If you haven't read that post yet, you should do so before you jump into this one as this new adaptive system is based on that system so I am going to be skipping the explanation of its strategy for this post.
You can find the code for the new bollinger bands adaptive voting system here: http://www.wave59.com/library/scriptdetail.asp?id=175
I'll explain briefly how an adaptive system works but Earik does a much better job of it in his Mechanical Trading Systems book which I highly recommend you buy if you want to build your own systems as it helped me immensely.
Essentially, an adaptive system is running many miniature systems at once with different parameter sets. It keeps track of their profit and compares them over a specific look back period to determine which system is the most optimal at that point in time.
After I created the bollinger bands trading system, I noticed that there were points in the equity curve on a daily ES chart where the bollinger bands system did better in mode 2 and other times did better in mode 4 so I sought to create an adaptive system that would move between both systems as they became optimal.
After I created the first adaptive system and ran it through the optimizer to determine the best look back period, I realized I had run into the same problem again. Some look back periods did well at some points in the equity curve and others did better at other points. So then I took it one step further and implemented a voting system on top of the adaptive system. After experimenting, I determined the best system setup for a daily ES chart was having three adaptive systems with the look back periods of 5, 10 and 50 bars. So it is essentially determining which system performed the best over the last week, two weeks and 10 weeks and then returns a signal from each. This signal is counted as a vote on whether to go long or short and the system tallies the votes and trades accordingly.
As you will see later on, this resulted in the following improvements and did a great job of smoothing out the equity curve. Its not perfect but its as good as I think I can get it.
~16% ($30k) profit increase
~2% accuracy increase
~$42 avg trade increase
~3k max drawdown decrease
This system contains three files with different inputs which I will explain in turn.
Bollinger Bands EquityCurve
This function contains the same logic as the bollinger bands trading system and uses the same input as that system with the addition of the lookback and longshort variables. The lookback specifies the period for which to calculate the profit of the system and longshort is used to store whether the system is currently long, short or flat. The only difference between the logic in this function and that in the bollinger bands trading system is it was changed to return a signal rather than placing actual trades. So it is virtually keeping track of profit/loss it would have made had it actually been trading to be used for analysis.
Bollinger Adaptive EntryExit Signal
This function does the actual adaptation. You provide it with the parameters for up to two bollinger bands trading systems plus several variance parameters that determine the combination of systems to spawn. One thing I should point out is that the bollinger length and standard deviation variables are not being changed. Bollinger bands already do a decent job at adapting to volatility as their base calculation involves averages over x bars. I tried seeing if adapting these variables would lead to a better system and did not discover a single instance where this was the case. Instead what we are adapting is the profit exit and loss exit settings as these are the most vulnerable to degrade over time.
If you do not want to adapt two systems, you can set the mode setting of system 2 (s2_mode) to 0 and a second system will not be created.
INPUTS
lookback - applies to both systems and determines how many bars to look back when calculating profit and determining the best system.
There are two sets of the following variables, distinguished by the s1 or s2 in front of them for the two different systems.
bol_length - length of bollinger band
bol_sdev - standard deviation for bollinger band
bol_profit_exit_bars - if profitable, how many bars to hold before exit
bol_loss_exit_bars - if not profitable, how many bars to hold before exit
mode - see description in Bollinger_EquityCurve function
variance - how much variance you want in the profit and loss exit vars
variance_increment - how you want the profit and loss exit vars to
The two new variables are variance and variance_increment. The system takes the variance increment and begins applying that to both sides of the primary settings up to the variance total to create the number of profit exits and loss exits we wish to explore. Here are two examples of the variance settings being applied to the profit exit and loss exit settings.
profit_exit_bars: 5
loss_exit_bars: 9
variance: 2
variance_increment: 1
possible profit exits generated from input: 3, 4, 5, 6, 7
possible loss exits generated from input: 7, 8, 9, 10, 11
profit_exit_bars: 20
loss_exit_bars: 40
variance: 8
variance_increment: 2
possible profit exits: 12, 14, 16, 18, 20, 22, 24, 26, 28
possible loss exits: 32, 34, 36, 38, 40, 42, 44, 46, 48
Once the possible profit and loss exits have been generated, it spawns instances of the bollinger bands trading system for every combination of these parameters. For the first example above, it would look something like this.
3, 7
3, 8
3, 9
3, 10
3, 11
4, 7 and so on until every combination is being run on a system.
As it iterates through each system for each bar, it is determining the profit/loss for each system over the look back period and the one that has the most profit is selected and that signal is then returned.
System Bollinger Adaptive Merged Voting
This indicator then brings everything together and actually executes the trading. It deploys up to three separate adaptive systems with different look back periods and then tallies the votes from each of these adaptive systems and makes its trading decision based on the consensus.
INPUTS
contracts - number of contracts to trade (value is doubled if you enable modes #2 or #4 for any instance of the adaptive system)
lookback1, lookback2, lookback3 - how many bars to look back for each instance of the adaptive system when calculating profit
The second and third adaptive systems are optional. If you do not want to run multiple adaptive systems, you can set lookback2 and/or lookback3 to 0 and it will not create them. Lookback1 is required.
Same as before, there are two sets of system parameters you must pass in. If you do not want a second system, set s2_mode as 0 and it will not use a second system and will only adapt the first system.
bol_length - length of bollinger band
bol_sdev - standard deviation for bollinger band
bol_profit_exit_bars - if profitable, how many bars to hold before exit
bol_loss_exit_bars - if not profitable, how many bars to hold before exit
mode - see description in Bollinger_EquityCurve function
variance - how much variance you want in the profit and loss exit vars
variance_increment - how you want the profit and loss exit vars to increment up to the variance total
Default Parameters for daily ES
These are the final optimized parameters for a daily ES chart which are the default on the indicator.
lookback1: 5
lookback2: 10
lookback3: 50
s1_mode: 2
s1_bol_length: 12
s1_bol_sdev: 1.2
s1_profit_exit_bars: 4
s1_loss_exit_bars: 9
s1_exit_variance: 3
s1_exit_variance_increment: 1
s2_mode: 4
s2_bol_length: 12
s2_bol_sdev: 1.4
s2_profit_exit_bars: 3
s2_loss_exit_bars: 8
s2_exit_variance: 2
s2_exit_variance_increment: 1
Now before we get into showing how this improved the initial bollinger bands system at each step, I want to review how you could take this and set it up for a different time frame or market.
1. Run standalone bollinger bands trading system on time frame and then put into the optimizer to determine up to two workable systems. This took me a while to do as there are a lot of combinations between the length, sdev, profit exit, loss exit and mode settings so I did this in stages and only for modes 2 and 4 as I knew these were more profitable due to the contract size doubling logic if the special but rare criteria is met.
2. Once I had parameters I was happy with, I set those for s1 and s2 on the bollinger adaptive merged voting indicator. Then I ran this system through the optimizer using only the first lookback period (setting lookback2 and lookback3 to 0 to disable) and incrementally went through different values for lookback1, s1_variance, s1_variance_increment, s2_variance and s2_variance_increment.
3. Each time I found a set of parameters I liked, I wrote them down and then at the end, determined which standard variance and increment I wanted and put it through the optimizer one last time with ranges of look back periods to find the final combination.
This might seem like a lot but it really improved my standalone bollinger bands system and should allow you to go extended periods of time before you have to put it back through the optimizer if market conditions change. At least thats the idea. If someone could point out a flaw in my logic, it would be very much appreciated so I can make adjustments
![Smile :)](./images/smilies/icon_e_smile.gif)
Ok, so here are the results of the system that shows each stage and may help to visualize what is happening. I'm not sure how clear this image will be on other monitors so I'm also including the final results of the merged voting system as separate files so its easier to see. If you right click on the first image you can choose to view image which will open a new tab where you can zoom in to hopefully see things more clearly.
What I was hoping to get across with the combined image is to show how the equity curve continued to flatten after each step until we have a better equity curve in the merged system. There was an area in 2013 and 2014 where it struggled but it did eventually find its way and continue moving up. The improvements to profit, accuracy, average trade and the lower drawdown all confirm the final merged system is better and hopefully more reliable than any of its parts.
Please let me know if you have any questions and if you make improvements or optimize this for another time frame or market please share!
Thanks!