TradeWithMe |
20. Trading Systems : Advance Techniques for Simple and Effective Trading
20.1 Introduction:
Think of a well planned city. There will be a good command and control management center which will orchestrate actions of doing various activities such as Project Planning, Execution/Implementation, Maintenance, Billing and Customer support. What this illustrates that each function is handled by an individual department or section and everything then works in unison following a set of rules and discipline.
Normally when we write AFL's and use them, each of them have has a buy and sell signal generation logic and the a risk management system that plots and keeps track of your exit logic to optimize profits. We keep repeating this in each new script that we write. This is quiet inefficient. How would it be, if we could keep the signal generation logic separate from the risk management system. So that each new script that we write focuses on exactly the system logic we are testing. That is possible, and this section demonstrates how it can be done.
We will develop a signal logic and we will use the trade simulator as the risk management system from the earlier sections to show how one AFL can communicate with another. This approach can be used for building and testing new systems for trading where buy and sell triggers could be generated by multiple systems and handled by one risk management system!
For example, how about generating basic buy and sell signals using a moving average crossover system. And then filter those signals that dont satisfy an RSI logic. Extend this to multiple other conditions that you may want to test. If you use a well defined protocol, you can have multiple AFL's communicating with each other. Each AFL could represent a clean constant script which is never touched or modified. You dont like the MA logic. Throw that out and replace that with something else..Just replace the AFL that has the Buy Sell signals generation logic in it. Everything else remains the same.
Its like each AFL becomes a service provider which is replaceable.
Minor understanding of writing AFL's needed to apply this section for your work. Cut and Paste experts, enjoy!
Significant message : This is completely original work, taking advantage of static variables, usually used for dynamic information sharing in an AFL.
Think of a well planned city. There will be a good command and control management center which will orchestrate actions of doing various activities such as Project Planning, Execution/Implementation, Maintenance, Billing and Customer support. What this illustrates that each function is handled by an individual department or section and everything then works in unison following a set of rules and discipline.
Normally when we write AFL's and use them, each of them have has a buy and sell signal generation logic and the a risk management system that plots and keeps track of your exit logic to optimize profits. We keep repeating this in each new script that we write. This is quiet inefficient. How would it be, if we could keep the signal generation logic separate from the risk management system. So that each new script that we write focuses on exactly the system logic we are testing. That is possible, and this section demonstrates how it can be done.
We will develop a signal logic and we will use the trade simulator as the risk management system from the earlier sections to show how one AFL can communicate with another. This approach can be used for building and testing new systems for trading where buy and sell triggers could be generated by multiple systems and handled by one risk management system!
For example, how about generating basic buy and sell signals using a moving average crossover system. And then filter those signals that dont satisfy an RSI logic. Extend this to multiple other conditions that you may want to test. If you use a well defined protocol, you can have multiple AFL's communicating with each other. Each AFL could represent a clean constant script which is never touched or modified. You dont like the MA logic. Throw that out and replace that with something else..Just replace the AFL that has the Buy Sell signals generation logic in it. Everything else remains the same.
Its like each AFL becomes a service provider which is replaceable.
Minor understanding of writing AFL's needed to apply this section for your work. Cut and Paste experts, enjoy!
Significant message : This is completely original work, taking advantage of static variables, usually used for dynamic information sharing in an AFL.
20.2 Implementation example 1
We take the trade simulator provided in section 7 and 8 and modify it to accept signals from any signal generation script. The trade simulator will only plot buy and short signals and exit trades based on the ATR based stop loss. It does not have any feature for re-entry, but you can add a manual buy or short or cover signal any time as part of the standard feature set of the simulator. It additionally, now has intelligence to accept signals from any other script which sets static variables with a buy or short level.
Static variables in Amibroker are variables that exist for that session of the Amibroker progeam being active. You exit Amibroker, they disappear. You restart, Amibroker, they get created by signal generation scripts. This is a powerful feature, which will allow you to separate your Buy/Sell plotting and stop loss logic, which can be standardized acrross all possible signal generation logic.
To make static variables unique we have used the Year, Datenum and Timenum functions of Amibroker to create the static variables. In the example script, you just need to replace the buy/short signal generation logic with your own custom formula and voila, you have a whole new trading system.
y = Year();
m = Month();
d = Day();
r = Hour();
e = Minute();
dnum=(m+10)*100+d;
tnum=TimeNum()+100000;
if ((Buy[i] OR Short[i])
{
Varname=Name()+"X"+y[i]+dnum[i]+tnum[i];//ensures that the static variable has a unique name for each signal generated
if (Buy[i])StaticVarSet(Varname,1);
if (Short[i])StaticVarSet(Varname,-2); //you can use any convention you like
}
See the AFL for the EMA based buy/short signal generation and you can see where you need to replace your buy sell logic.
Now our signal plotter program just reads the static variable and plots the buys/short signals with ATR based stops. It also allows the flexibility of adding your own Buy/Short/Sell/Cover signals too!This is an amazingly powerful concept, which I have not seen used elsewhere. I use this a lot in my own trading systems.
Static variables in Amibroker are variables that exist for that session of the Amibroker progeam being active. You exit Amibroker, they disappear. You restart, Amibroker, they get created by signal generation scripts. This is a powerful feature, which will allow you to separate your Buy/Sell plotting and stop loss logic, which can be standardized acrross all possible signal generation logic.
To make static variables unique we have used the Year, Datenum and Timenum functions of Amibroker to create the static variables. In the example script, you just need to replace the buy/short signal generation logic with your own custom formula and voila, you have a whole new trading system.
y = Year();
m = Month();
d = Day();
r = Hour();
e = Minute();
dnum=(m+10)*100+d;
tnum=TimeNum()+100000;
if ((Buy[i] OR Short[i])
{
Varname=Name()+"X"+y[i]+dnum[i]+tnum[i];//ensures that the static variable has a unique name for each signal generated
if (Buy[i])StaticVarSet(Varname,1);
if (Short[i])StaticVarSet(Varname,-2); //you can use any convention you like
}
See the AFL for the EMA based buy/short signal generation and you can see where you need to replace your buy sell logic.
Now our signal plotter program just reads the static variable and plots the buys/short signals with ATR based stops. It also allows the flexibility of adding your own Buy/Short/Sell/Cover signals too!This is an amazingly powerful concept, which I have not seen used elsewhere. I use this a lot in my own trading systems.

buy_sell_display_engine_with_atr_stop.afl | |
File Size: | 9 kb |
File Type: | afl |

buysell_signal_generation_module.afl | |
File Size: | 1 kb |
File Type: | afl |
20.3 Example 2 : Multiple Signal generators and displaying results from any one
You could set up multiple signal generating AFL's and if they are run in your current session, choose from amongst them for a trading logic that best suits your trade setup for the moment. We will set up two signal generation systems and use the ATR based stop loss trade simulator to show the resulting trades.
We have the original EMA signal generator and have created a second signal generator using a digital signal filter. One is called system X and the other is
called system Y. Each system identifies itself uniquely by creating static variable with its name inserted in it:
Varname=Name()+"Y"+y[i]+dnum[i]+tnum[i]; // This is for the EMA system
Varname=Name()+"X"+y[i]+dnum[i]+tnum[i];// This is for the Digital Filter system.
This is the only minor change done to the programs in the previous example. To make life simpler, we have moved the date period selection logic to the trade simulator.
See the immediate advantage; there was no need to develop and implement a separate signal display and stop loss logic for each system. They share the same output display module AFL as needed!
See the results below:
We have the original EMA signal generator and have created a second signal generator using a digital signal filter. One is called system X and the other is
called system Y. Each system identifies itself uniquely by creating static variable with its name inserted in it:
Varname=Name()+"Y"+y[i]+dnum[i]+tnum[i]; // This is for the EMA system
Varname=Name()+"X"+y[i]+dnum[i]+tnum[i];// This is for the Digital Filter system.
This is the only minor change done to the programs in the previous example. To make life simpler, we have moved the date period selection logic to the trade simulator.
See the immediate advantage; there was no need to develop and implement a separate signal display and stop loss logic for each system. They share the same output display module AFL as needed!
See the results below:
The respective AFL's are inserted here : all three of them needed for this environment. You can extend the logic to generate re-entries, if you like as well.

buy_sell_display_engine_with_atr_stop.afl | |
File Size: | 10 kb |
File Type: | afl |

buysell_signal_generation_module.afl | |
File Size: | 1 kb |
File Type: | afl |

buysell_signal_generation_module_2.afl | |
File Size: | 2 kb |
File Type: | afl |
20.4 Composite indices and their advantages
You can create compute composite indices using the AddtoComposite feature, which requires a Scan to be run to create a composite index. Check the example provided here in one of our services. Click here.
20.5 Advanced Trend Lines
Check out the trendlines shown in the point and figure section (13). These are original definitions. (click here)
Want more information ? Get in touch with us through the contact form : (click here)
|
|