I while back I started a thread asking if anyone ran multiple variations of the same strategy on the same instrument but with different variable settings so as to cover a broad range of settings that have worked in the past. The idea being not to put all your eggs on one setting.
Running multiple variations of the same strategy
I just wrote a strategy with just one variable and it worked quite well in backtest with a period setting anywhere from 2 to 10. So I decided that rather than pick one setting for that variable I would check in the code all of them and if any of them met the buy or sell requirements it would place a trade. I then added a switch so that you can increase the positions size dependent on how many of the variable settings meet the entry criteria or just have level staking. I thought I’d share the code here (not the whole strategy just the multiple entry criteria being met bit of it) just in case anyone else was interested in the idea for their own strategies.
Maybe another one for your snippet library GraHal?
a = (start of range to check)
b = (end of range to check)
PosSizeIncrease = 0// Set to 1 to turn on increased position sizing
PositionSize = 1
Flag = 0
For Period = a to b
Indicator1 = (indicator)[Period]
Indicator2 = (indicator)[Period]
IF (long entry conditions) THEN
Flag = Flag + 1
ENDIF
IF (short entry conditions) THEN
Flag = Flag - 1
ENDIF
NEXT
IF PosSizeIncrease = 1 THEN
PositionSize = ABS(Flag)
ENDIF
IF Flag > 0 THEN
BUY PositionSize Contracts at Market
ENDIF
IF Flag < 0 THEN
SELLSHORT PositionSize Contracts at Market
ENDIF
IF LongOnMarket and (long exit conditions) THEN
SELL at market
ENDIF
IF ShortOnMarket and (short exit conditions) THEN
EXITSHORT at market
ENDIF
if anyone ran multiple variations of the same strategy on the same instrument but with different variable settings
Yes I do often, but then I move on and don’t follow through to refine down the best System.
I have a System running currently on Demo with 6 variations (some with added variables, e.g. volume) the v6.0 gave biggest gain by far in backtest, but up to now the v1.0 (least complex) is in the lead! I guess my System with different variables does not fit in with your criteria for different variable settings, but thought I’d mention it! 🙂
I will add your snippet Vonasi. Keep em coming and I’ll be up to 21 in no time at all! 🙂 There are 3 users in the database (link below) right now so it is increasing in popularity!
@robertogozzi your link comes up as 404 Not Found.
https://docs.google.com/spreadsheets/d/1rgboqj7sVwsP9ZRhOduOefye48QMWC07jWVXCl-KJPU/edit?usp=sharing
Thanks for that robertogozzi. For some reason the link does not work for me but I found it here thanks to Google:
multiple strategies within one trading system
It is always good to link similar ideas in the same place for others to find.
Your idea is to have different strategies that an overall strategy that opens one or multiple positions depending on what set of entry criteria are hit and your code stops any more positions being traded at the same time until there are no positions – then it starts hunting for a position to open again. It would open several positions with buy or sell orders and then leave only the last strategy that opened a position to control the closing of them? As it will prioritise the last strategy over all the others you would have to put your worst strategy first and your best last in the list.
My idea was more about selecting an exact entry variable. If a period of anywhere between 2 and 10 has produced profitable results for twenty years but some years 1 is better than 10 and other 5 is the best setting for that variable then why not use them all and play the averages. Some would say that you should re-optimize every so often and use the last number that worked but I do not like this idea because just because it just worked does not mean that it will tomorrow. What if you just happen to re-optimize on the day of a market shift and 5 used to work but from today onwards 8 is the number to set your average period to?
I don’t know why the link doesn’t work!
GraHal you are doing what I have suggested as a good way to play the averages. If you have six systems that are basically the same but use six different sets of variables and all have passed backtesting with varying levels of profit then use them all – as long as they are all in a working range (i.e 2,3,4,5,6,7,8, and not 2,5,10,40). Some may win, some may lose but that is better than if you had picked just one and it turned out that it was the biggest loser going forward. The biggest limit to testing this theory out is the 25 demo strategy limit in PRT and in real life your bank account. If all six strategies are running independently it could be expensive which is why I developed my idea. All six can decide to open a position but you only open one position if PosSizeIncrease is set to zero.
It would not be too difficult to develop it further to use multiple ranges of different variables for different indicators although the more variables and the more indicators the more curve fitted so at the moment I am sticking to one.
Here is the the equity curve for my test strategy (weekly time frame) with an average period of an indicator set to open positions anywhere from 2 to 9. Unfortunately the number of trades is quite low and the drawdown more than I can stomach but it is a nice final result.
[attachment file=68942]
I don’t know why the link doesn’t work!
It is not just you mine doesn’t either……. Nicolas!
Hi Vonassi,
Thanks for your share.
Below a piece of code which allows to use parameters which are non consecutive
For Case = 1 to X
if Case = 1 then
Period1 = 10
Period2 = 20
elsif Case = 2 then
Period1 = 21
Period2 = 45
.
.
elsif Case = X then
Period1 = 5
Period2 = 8
endif
.
.
.
Next
I’ve added above to Snippet Library @ Row 32
Snippet Link Library
Thanks GraHal !
One more point: I’ve observed that sometimes (quite often), when 2 different (but close variable Cases) are triggered an order at the same time or nearly (up to 2 bars), results are improved. Most probably because the current trend seems cleaner…
So have you an idea to imagine what piece of code will ONLY place an order when AT LEAST 2 cases are filled (without using a duplication of the all long conditions since only a few parameters are changing) ?
Thanks a lot in advance
You could use a SUMMATION:
IF Summation[2](condition1 or condition2) = 2 THEN
I am trying to implement this but struggling to figure out how to do it.
If one wanted to try different box sizes, let’s say with the ‘pure Renko’ strategy, how would you add this code to use several different box sizes in one strategy?
Thanks in advance.
Defparam cumulateorders = false
boxSize = 40
once renkoMax = ROUND(close / boxSize) * boxSize
once renkoMin = renkoMax - boxSize
IF high > renkoMax + boxSize THEN
WHILE high > renkoMax + boxSize
renkoMax = renkoMax + boxSize
renkoMin = renkoMin + boxSize
WEND
ELSIF low < renkoMin - boxSize THEN
WHILE low < renkoMin - boxSize
renkoMax = renkoMax - boxSize
renkoMin = renkoMin - boxSize
WEND
ENDIF
buy at renkoMax + boxSize stop
sellshort at renkoMin - boxSize stop
How about duplicate the strategy several times and have a different > box size for each strategy??
I have tried a different method in one code, but it’s not beautiful – a lot of copy and paste and I’m not sure it’s the best way. I was curious about the method Vonasi mentioned here. It would be easier to analyse the results if it was all in one strategy also.
easier to analyse the results i
You could have different position size (0.2, 0.3, 0.4 etc) that relate to the different box size.
Then factor them up /down to position size = 1 for a direct comparison / analysis in Excel?
Just thoughts off top of my head 🙂