In a previous article I demonstrated how to build a strategy that will trade the equity curve. That is, a strategy that will stop trading when the equity curve falls below a simple moving average. Lets look at a different technique that not many retails traders are aware of. In particular this technique is difficult to execute in EasyLanguage.
What do I want to do? I want to create a trading system that tracks multiple copies of a given system. Simply put, I want to build a single strategy (a master strategy) that virtually tracks the performance of multiple different strategies. This master strategy then uses this information from all the individual strategies to formulate buy and sell signals.
Lets look at a simple example to make this clear.
Lets first take a trading system to work with. Lets use the example strategy called Simple S&P. The rules are straightforward and listed below.
I coded the Simple S&P rules in EasyLanguage and tested it on the E-mini S&P futures market going back to 2000. Before going further with the demonstration let me say this: all the tests within this article are going to use the following assumptions:
This strategy produces a the following results.
Lets now duplicate our strategy and then change the inputs slightly. Instead of a our entry lookback being six, lets reduce it by one leaving us with 5. We have created a slightly different trading system which produces different results as seen below.
Lets duplicate the original strategy again and change the inputs. Instead of a our entry lookback being six, lets increase it by one. This gives us a value of seven. We have a new strategy which produces the following results.
So, we have three different trading strategies. Each uses a different lookback value to determine when to enter a trade. Thus, we have slightly different equity curves and performance reports for each of our three strategy variations.
In a traditional trading environment you might optimize a single strategy over your historical data and pick a reasonable set of input parameters. You would then trade that one system. Wouldn't t it be interesting if we could monitor the performance of each strategy variation and trade the best performing strategy in real time? In essence we want to the ability to watch a horse race and change our bet as the race race progresses. A very interesting idea! But when you start to code such a scheme, it becomes a very, very daunting process in EasyLanguage.
To pull this off we need the ability to track multiple trading systems within a given strategy. We then simply pick the best performing strategy to trade live. Simple in concept but difficult to do. Natively there is no method to accomplish this in EL. However that has changed. This tool, Equity Curve Feedback Toolkit, will allow us to do just that.
Lets create our first multi agent strategy which automatically trades the best performing strategy variation.
There are three key things we have to do to our strategy.
First is creating a virtual backtesters to track the performance of our three different different strategies. This is accomplished by using the ECF_VirtualBackTester function included with Equity Curve Feedback Toolkit. The three lines of code to accomplish this are below.
Result = ECF_VirtualBackTester(Orders1, Trades1, True);
Result = ECF_VirtualBackTester(Orders2, Trades2, True);
Result = ECF_VirtualBackTester(Orders3, Trades3, True);
Second we now get the trades and current equity from our backtesters. The function ECF_GetEquity is getting the equity information placing it within CurrentEquityX variables and EquityX arrays.
CurrentEquity1 = ECF_GetEquity(Orders1, Trades1, Equity1, cLongAndShort, UseOpenTrade);
CurrentEquity2 = ECF_GetEquity(Orders2, Trades2, Equity2, cLongAndShort, UseOpenTrade);
CurrentEquity2 = ECF_GetEquity(Orders3, Trades3, Equity3, cLongAndShort, UseOpenTrade);
Third, we now must determine if our strategy is trading above the equity curve. This is explained in a lot more detail within the previous article, Trading The Equity Curve & Beyond. The following lines will determine if our virtual strategies are trading above their respective equity curve.
TradeEnable1 = ECF_EquityMASignal(Orders1, Equity1, EquityMALength, cLongAndShort, UseOpenTrade);
TradeEnable2 = ECF_EquityMASignal(Orders2, Equity2, EquityMALength, cLongAndShort, UseOpenTrade);
TradeEnable3 = ECF_EquityMASignal(Orders3, Equity3, EquityMALength, cLongAndShort, UseOpenTrade);
Fourth, we must determine which of the three simulated strategies is performing the best. This is accomplished with these lines of code.
BestSys1 = false;
BestSys2 = false;
BestSys3 = false;
If ( CurrentEquity1 > CurrentEquity2 ) and ( CurrentEquity1 > CurrentEquity3 ) and ( CurrentEquity1 > 0 ) then BestSys1 = true
else If ( CurrentEquity2 > CurrentEquity1 ) and ( CurrentEquity2 > CurrentEquity3 ) and ( CurrentEquity2 > 0 ) then BestSys2 = true
else If ( CurrentEquity3 > CurrentEquity1 ) and ( CurrentEquity3 > CurrentEquity2 ) and ( CurrentEquity3 > 0 )then BestSys3 = true;
There we have it. A single strategy which tracks the performance of three virtual strategies and only trades the best performing strategy. This all happens in real time.
Below is a snapshot of the chart showing trades being taken by our multi-agent version of the Simple S&P strategy. You can see on the left-hand side it's trading Version 1 of our strategy. Then on the right-hand side of the chart it's switch to trading Version 3 of the strategy.
Below is the performance report of our multi agent strategy.
This is a very simple example of a multi-agent trading strategy. In our case, we have three similar strategies being simulated in the backtester. You can create many more virtual copies. As many as you want. You don't even have to use the same strategy. In our example we used the same strategy but changed one of the inputs. You could use different strategies to compete against each other. For example, a trend following model vs a mean reverting model.
In our example we made trading decisions based upon the equity of each system but, we could use other metrics like drawdown or average profit per trade. The options are really incredible and I hope this simple example is getting the wheels in your head turning!
What are he best practices for building such a trading model? Good question. This material is rather new to me and I would love to hear what you think. Like any tool, it can be abused. My opinion at this time is you should correctly build a single, traditional, strategy first. That is, follow all the known best practices of strategy development. Once you have a solid system only then attempt to add the tools available in Equity Curve Feedback Toolkit.
You might be wondering what inputs you should change in your strategy? Good question. I think the fewer the better. In this example I only changed one of the lookback values. I think it's probably imporant that you first estable what the stable range is for each parameter. Then use the values within that range. However like I said, this is a new area for me but it sure looks promising.
Build Dynamic Strategies in EasyLanguage!
Let me show you how to build better trading modules in EasyLanguage that adapt in real-time!
Jeff is the founder of EasyLanguage Mastery - a website and mission to empowering the EasyLanguage trader with the proper knowledge and tools to become a profitable trader. Join our EasyLanguage FaceBook group to interact with other EasyLanguage traders! Click the FaceBook icon to join.
Please log in again. The login page will open in a new tab. After logging in you can close it and return to this page.