help coding breakout strategy
Forums › ProRealTime English forum › ProOrder support › help coding breakout strategy
- This topic has 19 replies, 3 voices, and was last updated 2 years ago by robertogozzi.
-
-
04/07/2021 at 8:37 AM #166368
hi
I need help coding a strategy ive been backtesting manually and forwardtested for a while now. Results look promising.
rules:
- from todays open (midnight) to US open, (15:30 my time gmt +2) creates a rangebox
- if ADR is below 50%, put sell/buy stop orders 10 pips below/above rangebox
- target 50 pips, SL 100 pips, breakeven SL after 25 pips
- if ADR is above 50% no trades
1 user thanked author for this post.
04/07/2021 at 10:44 AM #166391What ADR is the one you are referencing?:
- Advance/Decline Ratio
- Average Daily Range calculated on Highs & Lows
- Average Daily Range calculated on Range (pips)
Do you have any link to that indicator? PRT have ADX, ADXR, but no ADR.
04/07/2021 at 11:39 PM #16644904/08/2021 at 12:42 PM #166523Try this:
123456789101112131415161718192021222324252627282930313233343536373839404142DEFPARAM CumulateOrders = FALSEIF Not OnMarket THENMyExit = 0ELSEc1 = 0ENDIF// ADR Average Daily RangeMyADR = average[300,0](range)//IF Time = 000000 THENMyHI = highMyLO = lowc1 = 0ENDIFIF Time <= 153000 THENMyHI = max(MyHI,high)MyLO = min(MyLO,low)MyRange = MyHI - MyLOc1 = ((MyRange / MyADR) * 100) < 50ENDIFIF Time >= 153000 AND c1 THENBUY 1 Contract AT MyHI + 10 * pipsize STOPSELLSHORT 1 Contract AT MyLO - 10 * pipsize STOPSET TARGET pPROFIT 50SET STOP pLOSS 100ENDIFIF MyExit = 0 THENIF (LongOnMarket AND (close - TradePrice) >= 25 * pipsize) OR (ShortOnMarket AND (TradePrice - close) >= 25 * pipsize) THENMyExit = TradePriceENDIFENDIFIF MyExit > 0 THENSELL AT MyExit STOPEXITSHORT AT MyExit STOPENDIF//GraphOnPrice TradePrice coloured(0,0,255,255)//GraphOnPrice MyHI coloured(0,128,0,200)//GraphOnPrice MyLO coloured(255,0,0,255)//Graph close - TradePrice//Graph c1//Graph MyADR//Graph MyRange1 user thanked author for this post.
04/08/2021 at 1:17 PM #16653004/08/2021 at 1:59 PM #166546No, those two values must be updated earlier or on that time.
After that time the range is defined and trades can be entered.
1 user thanked author for this post.
04/12/2021 at 10:32 AM #16683604/12/2021 at 11:08 AM #166845Try this one. I changed the average with yesterday’s range:
123456789101112131415161718192021222324252627282930313233343536373839404142DEFPARAM CumulateOrders = FALSEIF Not OnMarket THENMyExit = 0ELSEc1 = 0ENDIF// ADR Average Daily RangeMyADR = average[20,0](Dhigh(1) - Dlow(1))//IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THENMyHI = highMyLO = lowc1 = 0ENDIFIF Time <= 153000 THENMyHI = max(MyHI,high)MyLO = min(MyLO,low)MyRange = MyHI - MyLOc1 = ((MyRange / MyADR) * 100) < 50ENDIFIF Time >= 153000 AND c1 THENBUY 1 Contract AT MyHI + 10 * pipsize STOPSELLSHORT 1 Contract AT MyLO - 10 * pipsize STOPSET TARGET pPROFIT 50SET STOP pLOSS 100ENDIFIF MyExit = 0 THENIF (LongOnMarket AND (close - TradePrice) >= 25 * pipsize) OR (ShortOnMarket AND (TradePrice - close) >= 25 * pipsize) THENMyExit = TradePriceENDIFENDIFIF MyExit > 0 THENSELL AT MyExit STOPEXITSHORT AT MyExit STOPENDIF//GraphOnPrice TradePrice coloured(0,0,255,255)//GraphOnPrice MyHI coloured(0,128,0,200)//GraphOnPrice MyLO coloured(255,0,0,255)//Graph close - TradePrice//Graph c1//Graph MyADR//Graph MyRange1 user thanked author for this post.
04/13/2021 at 9:17 AM #166914perfect! thanks alot roberto!! 😀
1 user thanked author for this post.
04/11/2022 at 9:48 PM #19159904/12/2022 at 8:23 AM #191623There you go:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455DEFPARAM CumulateOrders = FALSEIF Not OnMarket THENMyExit = 0ELSEc1 = 0ENDIF// ADR Average Daily RangeMyADR = average[20,0](Dhigh(1) - Dlow(1))//IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THENMyHI = highMyLO = lowc1 = 0ENDIFIF Time <= 153000 THENMyHI = max(MyHI,high)MyLO = min(MyLO,low)MyRange = MyHI - MyLOc1 = ((MyRange / MyADR) * 100) < 50ENDIFIF LongOnMarket THENSET TARGET pPROFIT 50 //you can change this value for LONG tradesSET STOP pLOSS 100 //you can change this value for LONG tradesELSIF ShortOnMarket THENSET TARGET pPROFIT 50 //you can change this value for SHORT tradesSET STOP pLOSS 100 //you can change this value for SHORT tradesENDIFIF Time >= 153000 AND c1 AND Not OnMarket THENBUY 1 Contract AT MyHI + 10 * pipsize STOPSELLSHORT 1 Contract AT MyLO - 10 * pipsize STOPSET TARGET pPROFIT 50 //initial values cannot be different with pending ordersSET STOP pLOSS 100ENDIFIF MyExit = 0 THENIF LongOnMarket AND (close - TradePrice) >= 25 * pipsize THEN //you can change this value for LONG tradesMyExit = TradePriceENDIFIF ShortOnMarket AND (TradePrice - close) >= 25 * pipsize THEN //you can change this value for SHORT tradesMyExit = TradePriceENDIFENDIFIF MyExit > 0 THENIF LongOnMarket THENSELL AT MyExit STOPELSIF ShortOnMarket THENEXITSHORT AT MyExit STOPENDIFENDIF//GraphOnPrice TradePrice coloured(0,0,255,255)//GraphOnPrice MyHI coloured(0,128,0,200)//GraphOnPrice MyLO coloured(255,0,0,255)//Graph close - TradePrice//Graph c1//Graph MyADR//Graph MyRange1 user thanked author for this post.
04/12/2022 at 1:13 PM #19163104/12/2022 at 2:40 PM #191639There you go:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566DEFPARAM CumulateOrders = FALSEONCE MaxTrades = 2 //no more than 2 trades a dayONCE Tally = 0IF IntraDayBarIndex = 0 THENTally = 0ENDIFIF Not OnMarket THENMyExit = 0ELSEc1 = 0ENDIF////////////////////////////////////////////////////////////////////////////////////////////////////////////NewTrade = (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) OR ((Not OnMarket AND Not OnMarket[1]) AND (StrategyProfit <> StrategyProfit[1]))IF NewTrade THENTally = Tally + 1ENDIF////////////////////////////////////////////////////////////////////////////////////////////////////////////// ADR Average Daily RangeMyADR = average[20,0](Dhigh(1) - Dlow(1))//IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THENMyHI = highMyLO = lowc1 = 0ENDIFIF Time <= 153000 THENMyHI = max(MyHI,high)MyLO = min(MyLO,low)MyRange = MyHI - MyLOc1 = ((MyRange / MyADR) * 100) < 50ENDIFIF LongOnMarket THENSET TARGET pPROFIT 50 //you can change this value for LONG tradesSET STOP pLOSS 100 //you can change this value for LONG tradesELSIF ShortOnMarket THENSET TARGET pPROFIT 50 //you can change this value for SHORT tradesSET STOP pLOSS 100 //you can change this value for SHORT tradesENDIFIF Time >= 153000 AND Time <= 180000 AND c1 AND Tally < MaxTrades AND Not OnMarket THEN //trade only between 15:30 and 18:00BUY 1 Contract AT MyHI + 10 * pipsize STOPSELLSHORT 1 Contract AT MyLO - 10 * pipsize STOPSET TARGET pPROFIT 50 //initial values cannot be different with pending ordersSET STOP pLOSS 100ENDIFIF MyExit = 0 THENIF LongOnMarket AND (close - TradePrice) >= 25 * pipsize THEN //you can change this value for LONG tradesMyExit = TradePriceENDIFIF ShortOnMarket AND (TradePrice - close) >= 25 * pipsize THEN //you can change this value for SHORT tradesMyExit = TradePriceENDIFENDIFIF MyExit > 0 THENIF LongOnMarket THENSELL AT MyExit STOPELSIF ShortOnMarket THENEXITSHORT AT MyExit STOPENDIFENDIF//GraphOnPrice TradePrice coloured(0,0,255,255)//GraphOnPrice MyHI coloured(0,128,0,200)//GraphOnPrice MyLO coloured(255,0,0,255)//Graph close - TradePrice//Graph c1//Graph MyADR//Graph MyRange04/15/2022 at 7:38 PM #19181005/23/2022 at 10:08 PM #193737Roberto, i ended up using this version. But system is not taking any positions last 18 days. But it should, could you take a look at what might be wrong?
us3012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455//-------------------------------------------------------------------------// Main code : ryd range box 1-2 min US30 DOW//-------------------------------------------------------------------------DEFPARAM CumulateOrders = FALSEONCE PL = 130.0ONCE SL = 60.0ONCE t = 50.0ONCE tS = 50.0ONCE x = 40.0ONCE y = 1.0IF Not OnMarket THENMyExit = 0ELSEc1 = 0ENDIF// ADR Average Daily RangeMyADR = average[20,0](Dhigh(1) - Dlow(1))//IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THENMyHI = highMyLO = lowc1 = 0ENDIFIF Time <= 142900 THENMyHI = max(MyHI,high)MyLO = min(MyLO,low)MyRange = MyHI - MyLOc1 = ((MyRange / MyADR) * 100) < x //75ENDIFIF Time >= 142900 AND c1 THENBUY 0.2 Contract AT MyHI + y * pipsize STOPSELLSHORT 0.2 Contract AT MyLO - y * pipsize STOPSET TARGET pPROFIT PL //40SET STOP pLOSS SL //80ENDIFIF MyExit = 0 THENIF (LongOnMarket AND (close - TradePrice) >= t * pipsize) OR (ShortOnMarket AND (TradePrice - close) >= tS * pipsize) THEN //27.5 37.5MyExit = TradePriceENDIFENDIFIF MyExit > 0 THENSELL AT MyExit STOPEXITSHORT AT MyExit STOPENDIF//GraphOnPrice TradePrice coloured(0,0,255,255)//GraphOnPrice MyHI coloured(0,128,0,200)//GraphOnPrice MyLO coloured(255,0,0,255)//Graph close - TradePrice//Graph c1//Graph MyADR//Graph MyRange -
AuthorPosts
Find exclusive trading pro-tools on