Please Help – Take only the first Cross
Forums › ProRealTime English forum › ProOrder support › Please Help – Take only the first Cross
- This topic has 4 replies, 2 voices, and was last updated 1 year ago by robertogozzi.
-
-
09/02/2023 at 12:56 PM #220212
Hello everyone,
I would like the following code to take only the first cross over or cross under, as the more we progress in the trend the more likely to have fake out.
Can you please indicate how can I modify the code to have only the first Cross Long or Short? and how to keep the trade all the way up or down?
Thank you.
Ma Cross1234567891011121314151617181920212223242526272829303132333435363738394041DEFPARAM CUMULATEORDERS = FALSEca=0cv=0ATR = AverageTrueRange[PATR](close)MAF = WeightedAverage[PF](WeightedClose)GRAPHONPRICE MAF coloured("cyan") as "MAF"ca = (close crosses over MAF )cv = (close crosses under MAF )if time>=080000 and time<=213000 thenIF NOT LongOnMarket AND ca THENBUY 1 CONTRACTS AT MARKETENDIF// Conditions to enter short positionsIF NOT ShortOnMarket AND cv THENSELLSHORT 1 CONTRACTS AT MARKETENDIFIF LONGONMARKET and cv THENSELL AT MARKETSELLSHORT 1 CONTRACTS AT MARKETENDIFIF SHORTONMARKET and ca THENEXITSHORT AT MARKETBUY 1 CONTRACTS AT MARKETENDIFENDIF// Stops and targets : Enter your protection stops and profit targets hereSET TARGET PPROFIT TPSET STOP PLOSS SLIF TIME>=214500 THENSELL AT MARKETEXITSHORT AT MARKETENDIF09/03/2023 at 9:41 AM #220234There you go (I couldn’t test it as some variables are missing):
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849DEFPARAM CUMULATEORDERS = FALSEONCE FirstCrossOver = 1ONCE FirstCrossUnder = 1IF IntraDayBarIndex = 0 THENFirstCrossOver = 1FirstCrossUnder = 1ENDIFca=0cv=0ATR = AverageTrueRange[PATR](close)MAF = WeightedAverage[PF](WeightedClose)GRAPHONPRICE MAF coloured("cyan") as "MAF"ca = (close crosses over MAF ) AND FirstCrossOvercv = (close crosses under MAF ) AND FirstCrossUnderif time>=080000 and time<=213000 thenIF NOT LongOnMarket AND ca THENBUY 1 CONTRACTS AT MARKETFirstCrossOver = 0ENDIF// Conditions to enter short positionsIF NOT ShortOnMarket AND cv THENSELLSHORT 1 CONTRACTS AT MARKETFirstCrossUnder = 0ENDIFIF LONGONMARKET and cv THENSELL AT MARKETSELLSHORT 1 CONTRACTS AT MARKETENDIFIF SHORTONMARKET and ca THENEXITSHORT AT MARKETBUY 1 CONTRACTS AT MARKETENDIFENDIF// Stops and targets : Enter your protection stops and profit targets hereSET TARGET PPROFIT TPSET STOP PLOSS SLIF TIME>=214500 THENSELL AT MARKETEXITSHORT AT MARKETENDIF1 user thanked author for this post.
09/03/2023 at 11:35 AM #22023909/03/2023 at 12:22 PM #220244Thank you Roberto. The code works fine for the first Signal of the day, then doesn’t take any of the other Signals in the same direction. What I would like to achieve is to take the first Signal Long until the First Signal Short happens, then take a Short until the next Signal Long happens and take Long, etc.
What I would like to avoid is taking two consecutive Long or two consecutive Short. If I exited the first Signal Long with TP or SL and then a second Signal Long appears, I d’ont want the system to take this second Signal in the same direction of the previous one.
I’ve added the variables optimized with backtest on 2k units on 5 min chart.
I hope my request is clearer now.
Ma Cross (test)1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253DEFPARAM CUMULATEORDERS = FALSEca=0cv=0PATR = 5PF = 12TP = 9SL = 20GRAPHONPRICE MAF coloured("cyan") as "MAF"ONCE FirstCrossOver = 1ONCE FirstCrossUnder = 1IF IntraDayBarIndex = 0 THENFirstCrossOver = 1FirstCrossUnder = 1ENDIFATR = AverageTrueRange[PATR](close)MAF = WeightedAverage[PF](WeightedClose)ca = (close crosses over MAF) AND FirstCrossOvercv = (close crosses under MAF) AND FirstCrossUnderif time>=080000 and time<=213000 thenIF NOT LongOnMarket AND ca THENBUY 1 CONTRACTS AT MARKETFirstCrossOver = 0ENDIF// Conditions to enter short positionsIF NOT ShortOnMarket AND cv THENSELLSHORT 1 CONTRACTS AT MARKETFirstCrossUnder = 0ENDIFIF LONGONMARKET and cv THENSELL AT MARKETSELLSHORT 1 CONTRACTS AT MARKETENDIFIF SHORTONMARKET and ca THENEXITSHORT AT MARKETBUY 1 CONTRACTS AT MARKETENDIFENDIF// Stops and targets : Enter your protection stops and profit targets hereSET TARGET PPROFIT TPSET STOP PLOSS SLIF TIME>=214500 THENSELL AT MARKETEXITSHORT AT MARKETENDIF09/04/2023 at 3:11 PM #220312There CANNOT be two consecutive CROSSOVERs in the same direction!
-
AuthorPosts