Optimization moving average crossing strategy
Forums › ProRealTime English forum › ProOrder support › Optimization moving average crossing strategy
- This topic has 185 replies, 11 voices, and was last updated 2 years ago by slevinkelevra.
-
-
03/22/2020 at 8:18 AM #122887
@dnystrom I dont think you would want an actual crossover in both time frames as that would be a fairly rare occurrence and, as you say, result in v few trades. Better would be to use some kind of trend indicator in the daily TF, then insert the part of the code i posted above (MACross finder) in the shorter TF and let it find the best crossover to work in conjunction with your daily filter.
It’s possible of course to load it in both TFs and optimize them separately, but I wouldn’t expect it to work very well. (or maybe it would – try it and let us know!)
Thank you, yes i will try it later today.
I just need help it two things. How do i use Jans code with just the two averages that i want and its not do all the crossings each backtest? So I easily can change the averages on each timeframe, default and upper time frame?
And how can I code the two averages on the upper time frame so when that condition fills in, then look for the trade in the default time frame?03/22/2020 at 11:15 AM #122892After you’ve run the program, add
ONCE MAType = x
ONCE MATypeV2 = yand enter the results. Then you can add another TF and do it all again.
03/22/2020 at 1:22 PM #122900Hi dnystrom,
Very interesting idea to try this crossing strategy in Multiple Time Frames.
I am not sure if it much limits the trades using an optimum in both a long and short time frame, because there are many short time frames available for crossing when the long time frame crosses.
(Theoretically) it would be possible to do so, but it can not be tested at once (70 x 70 x 70 x 70 = 24.010.000 variations, way too much), and you would have then 4 x 70 averages, which is a long code.
Image you do this for proper testing on more then 100.000 bars (of the short time frame), I hope we do not get the RED FLAG from ProRealTime for overusing the server !
The trading concept would be: (if I understand the idea of dnystrom correctly)
if AvType1 (long time frame) crosses above AvType2 (long time frame) and AvType3 (short time frame) crosses above AvType4 (short time frame), go long
Vice versa if AvType1 (long time frame) crosses under AvType2 (long time frame) and AvType3 (short time frame) crosses under AvType4 (short time frame), go short
I will work out a strategy like this and test it with a small range of variables and let you know. (Testing until the RED Flag will be given . . ), I can share the code.
You may develop it yourself, copy first range of averages (0-69) to Notepath, find/replace MATpe to MAType3 /4, find/replace Series to Series3 /4, find/replace Period to Period3 /4, find/replace AFR to AFR3 /4, and add back the new averages, started those with the smaller time frame, start the original 2 ranges with the higher timeframe, and extend the smoothed averages and the crossings in the bottom lines of the code, and see and test what it delivers), Do not forget to add also AFR3 and AFR4 to the variables to be tested above the code.
03/22/2020 at 2:17 PM #122909I haven’t tested this but my instinct is that for 2 TFs, it might be better to use
1IF wAFR > wAFRv2 thenin the longer TF, so that it’s more of a trend indicator than a crossover.
Then have
1IF wAFR > wAFRv2 and wAFR[1] < wAFRv2[1] thenin the shorter TF.
What do you think?
03/22/2020 at 2:41 PM #122915Thanks for the input.
Exactly the way I was intended to test Jan. But i was thinking of first do a test on lets say a 2 or 4H chart then a separately test on the 15 min chart, and then run a test with thoose 4 avg that gives the best output. But your way seems so much better =)I will make some test later today with different kind of indicators for bull/bear on the upper TF then the optimisation on the lower.
I let you know how it goes.1 user thanked author for this post.
03/22/2020 at 2:53 PM #122917Nasty complicating factor is that ProRealTime requires unique variables per time frame.
That’s no issue if you have 100 lines, but become pretty annoying when you have 1.700 lines with variables like a = …. , then the Replace does not easily work and you have to check the proposed replacement one by one . . . . see how far I come.
03/22/2020 at 2:56 PM #122920Testing until the RED Flag will be given
I know it was humour! 🙂
PRT will have their own way of throttling / limiting our backtesting … you can tell, it’s like we get a second or so every minute sometimes?
When I’ve been backtesting max combo’s 10,000 over 100k bars it can seem like it has stopped and then every minute or so 10 or so more results pop into the table … even at the start when the table is empty then 10 to 20 results appear after a minute or so?
Anybody else seen / had this?
03/22/2020 at 3:00 PM #12292103/22/2020 at 3:50 PM #12292303/22/2020 at 3:55 PM #12292503/23/2020 at 5:51 PM #123028@Jan, in the coding of the entry conditions
123456789101112131415if time >= StartE And time <= StartL and OTD then //and not onmarket thenIF wAFR > wAFRv2 and wAFR[1] < wAFRv2[1] thenbuy N shares AT MARKETSET STOP PLOSS TSL//SET STOP PTRAILING TSL//SET TARGET PPROFIT TSLelseif wAFR < wAFRv2 and wAFR[1] > wAFRv2[1] thensellshort N shares at marketSET STOP PLOSS TSL//SET STOP PTRAILING TSL//SET TARGET PPROFIT TSLendifendifendifdoes a reversal also constitute an exit?
I tried adding
123456if longonmarket and wAFR < wAFRv2 and wAFR[1] > wAFRv2[1] thensell at marketENDIFif shortonmarket and wAFR > wAFRv2 and wAFR[1] < wAFRv2[1] thenexitshort at marketENDIFbut it made things worse.
03/23/2020 at 11:30 PM #123065does a reversal also constitute an exit?
Not necessarily, unless the set crossings is very volatile (eg when it generates a long crossing and after 3 bars a short, when is possible on short time frames) (Maybe a combi of long and short term is not that bad.)
03/23/2020 at 11:57 PM #123075So (just to be clear) if longonmarket, the sellshort conditions do not close the existing long — it that right? (where OTD is active and no new position is to be opened)
03/24/2020 at 3:25 PM #123147So (just to be clear) if longonmarket, the sellshort conditions do not close the existing long — it that right? (where OTD is active and no new position is to be opened) , YES when you add OTD to the exit code, but NO if leave OTD out of your code as your example below. then it could be triggered already in the next bar (at a volatile crossing) .
But if you add OTD to your code below, and it is initialized to tradeindex(1), it will not work untill the next trading day, which is also not what you want, presumably. Alternatively you could try adding “and barindex – tradedindex > 4”, so that the trade stays at least 4 bars .
Exit code without OTD123456if longonmarket and wAFR < wAFRv2 and wAFR[1] > wAFRv2[1] thensell at marketENDIFif shortonmarket and wAFR > wAFRv2 and wAFR[1] < wAFRv2[1] thenexitshort at marketENDIF03/24/2020 at 3:28 PM #123148I haven’t tested this but my instinct is that for 2 TFs, it might be better to use
1IF wAFR > wAFRv2 thenin the longer TF, so that it’s more of a trend indicator than a crossover.
I agree with you, I have tested it and with a double change crossing (longer and shorter timeframes) very few trades are generated, so better use higher timeframes as a trend.
-
AuthorPosts
Find exclusive trading pro-tools on