Strategy Break MM7
Forums › ProRealTime English forum › ProOrder support › Strategy Break MM7
- This topic has 13 replies, 5 voices, and was last updated 3 years ago by Léo.
-
-
07/06/2020 at 2:15 PM #138552
Dear All,
I hope I am posting this subject in the correct section of the website.
I have no experience in programming and I think that the best way for me to understand the codes posted on this website is to try to work on my own projects.
Therefore I tried to write the code below, the idea is to take position when prices crosses MM7 and x prior closes are above or under MM7. A lot of it is based on the SL strategies that I found in a thread created by Gianluca and originaly developped by Nicolas and Ale.
I assume there is a lot of mistakes in this code, but I hardly see my mistake myself.
Can you please comment on this ?
Thank you all for your contribution to this website, very much appreciated.
Best regards.
Alex.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182//-------------------------------------------------------------------------// Code principal : Break MM7 H4 Dax// Stop strategy adapted from Gianluca/Nicolas/Ale https://www.prorealcode.com/topic/trailing-stop-and-breakeven-codes///-------------------------------------------------------------------------// Dax - IG MARKETS// TIME FRAME H4//idea1 : Buy when Close crosses over MM7 and Close for the X previous periods were below MM7 (X=5 in this first code)//idea2 : Set initial SL on the lowest of the X previous periods (X=5 in this first code)//idea3 : Move SL to entry point when profit > 300 pts//idea4 : Move SL to highest Close when Close crosses under MM7//idea5 : If SL > 300 pts no tradeDEFPARAM CumulateOrders = falseMM7= Average[7]C1= Close crosses over MM7 and Close[1]<MM7[1] and Close[2]<MM7[2] and Close[3]<MM7[3] and Close[4]<MM7[4] and Close[5]<MM7[5]C2= Close crosses under MM7 and close[1]>MM7[1] and Close[2]>MM7[2] and Close[3]>MM7[3] and Close[4]>MM7[4] and Close[5]>MM7[5]LongSLvalue= high-lowest[5](low)ShortSLvalue= highest[5](high)-lowif not onmarket thenif C1 and longSLvalue < 300 thenbuy 1 contract at (high+1) stopendifif C2 and shortSLvalue < 300 thensell 1 contract at (low-1) stopendifendif// Stop strategy adapted from Gianluca/Nicolas/Ale https://www.prorealcode.com/topic/trailing-stop-and-breakeven-codes///1/TRAILING STOP//////////////////////////////////////////////////////once trailinstop= 1 //1 on - 0 offtrailingstart = 300 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//1 trailing stop functionif trailinstop>0 then//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN// set initial SLif newSL=0 thennewSL=longSLvalueendif//first move (breakeven)IF newSL>0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close crosses under MM7 THENnewSL = low-1ENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//Set initial SLif newSL=0 thennewSL=shortSLvalueendif//first move (breakeven)IF newSL>0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close crosses over MM7 THENnewSL = high+1ENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFendif///////////////////////////08/14/2020 at 1:11 PM #141636Dear All,
still trying to work on this strategy.
I tried the code below which works well on long position but does not take any short position.
I think I must be missing something very obvious.
Could someone help please ?
Best regards.
Alex.
12345678910111213141516171819202122232425DEFPARAM CumulateOrders = falseTaillePosition=5SMA= Average[PeriodeMM]C1= Close crosses over SMA and Summation[X](Close<SMA)=(X-1)C2= Close crosses under SMA and Summation[X](Close>SMA)=(X-1)LongSLvalue= high-lowest[5](low)ShortSLvalue= highest[5](high)-lowif not longonmarket thenif C1 and longSLvalue < 300 thenbuy TaillePosition contract at (high+1) stopset stop ploss LongSLvalueendifendifif not shortonmarket thenif C2 and shortSLvalue < 300 thensell TaillePosition contract at (low-1) stopset stop ploss ShortSLvalueendifendif08/14/2020 at 9:24 PM #14166508/15/2020 at 9:36 AM #14167608/15/2020 at 9:40 AM #14167708/17/2020 at 10:03 AM #141830Dear Grahal, Vonasi and Roberto,
Thank you for your help – much appreciated.
I updated the code accordingly and backtested on Dow Jones in 1H. Results are not great Especially prior to 2015 but not so bad since.
I will try to optimize X and SMA and repost it here if I find good parameters.
Thank you again for your help.
123456789101112131415161718192021222324252627282930313233DEFPARAM CumulateOrders = falseTaillePosition=1SMA= Average[PeriodeMM](close)C1= Close crosses over SMA and Summation[X](Close<SMA)=(X-1)C2= Close crosses under SMA and Summation[X](Close>SMA)=(X-1)LongSLvalue= high-lowest[5](low)ShortSLvalue= highest[5](high)-lowif not onmarket thenif C1 and longSLvalue < 300 thenbuy TaillePosition contract at (high+1) stopset stop ploss LongSLvalueendifelseif C2 and shortSLvalue < 300 thensellshort TaillePosition contract at (low-1) stopset stop ploss ShortSLvalueendifendifIf onmarket thenif C1 and longSLvalue < 300 thenexitshort TaillePosition contract at (high+1) stopendifelseif C2 and shortSLvalue < 300 thensell TaillePosition contract at (low-1) stopendifendif08/18/2020 at 10:59 AM #141907Hi All,
I simplified the code as below and tested different combinations for PMM and X.
Best results for Dow H1 are with PMM=154 and X=77. (2020 show particularly good results as it was able to capture most of the Feb/March adjustment).
Results are even better with larger SL but I found 300 good for now.
As mentionned this is experimental, but I am happy to hear your comments.
Thanks.
Alex.
1234567891011121314151617181920212223242526272829DEFPARAM CumulateOrders = falseTaillePosition=2PeriodeMM = PMM //154X = XX //77SLValue = SLV //300SMA= Average[PeriodeMM](close)C1= Close crosses over SMA and Summation[X](Close<SMA)=(X-1)C2= Close crosses under SMA and Summation[X](Close>SMA)=(X-1)if not longonmarket and C1 thenbuy TaillePosition contract at (high+1) stopset stop ploss SLValueendifif not shortonmarket and C2 thensellshort TaillePosition contract at (low-1) stopset stop ploss SLValueendifif C1 and shortonmarket thenset stop ploss SLValueendifif C2 and longonmarket thenset stop ploss SLValueendif08/18/2020 at 1:12 PM #141915Beware of over fitting. Divide your optimizing period into at least 1 IS+ 1 OOS periods.
Optimize on 70% of history (In-Sample period) and test the robustness (validation of optimized variables) with the 30% of history (the Out Of Sample period). You can automate this process with the walk forward tool: https://www.prorealcode.com/blog/learning/prorealtime-walk-analysis-tool/
(french videos: Analyse Walk Forward avec ProRealTime et Récapitulatif sur l’utilisation du module Walk Forward sous ProRealTime)
1 user thanked author for this post.
08/18/2020 at 3:17 PM #14193308/19/2020 at 11:27 AM #142022Dear Nicolas,
I worked on parameters using one IS / OOS (70/30) period as suggested (Dow 1h, 200’000 bars, Tick by tick mode).
WFE is 53,8 % using 150 for PMM and 112 for XX – which I understand is not so bad. I understand it would make sense to have more than one IS/OOS but it is running super slowly.
Alex.
08/19/2020 at 12:09 PM #14204208/20/2020 at 8:33 AM #14208708/20/2020 at 9:55 AM #14209509/02/2020 at 11:55 AM #143201Dear Nicolas,
Maybe you can help to understand the issue I have.
I am testing the code below with variables to optimize PMM, XX, SLa and TPa.
The walk forward analysis below (TEST MM7 Break(7)) shows that the best variables would be PMM = 6 or 7, XX = 5 and SLa and TPa = 5 (200 K bares, Tick by tick, spread = 1 )
When I replace the variables in the code for PMM=6, XX=5 SLa=5 and TPa=5 (Test MM7 Break(9)) or PMM=7, XX=5 SLa=5 and TPa=5 (Test MM7 Break(10)) the stratgey fails after few months (200 K bares, Tick by tick, spread = 1 ).
I would have expected a gain curve more or less in line with the results of the walkforward analysis.
I definetly miss something – Can you please help ?
Thank you !
Alex.
12345678910111213141516171819202122232425262728DEFPARAM CumulateOrders = falseTaillePosition=1PeriodeMM = PMMX = XXSL = SLaTP = TPaSMA= Average[PeriodeMM](close)ATR = abs(close - open) > ATR * 2C1= Close crosses over SMAC1= C1 and Summation[X](Close<SMA)=(X-1)C1= C1 and ATRC2= Close crosses under SMAC2= C2 and Summation[X](Close>SMA)=(X-1)C2 = C2 and ATRif not longonmarket and C1 thenbuy TaillePosition contract at (high+1) stopendifif not shortonmarket and C2 thensellshort TaillePosition contract at (low-1) stopendifset stop ploss SLSet target pprofit TP -
AuthorPosts
Find exclusive trading pro-tools on