Strategy is closing based on wrong timeframe
Forums › ProRealTime English forum › ProOrder support › Strategy is closing based on wrong timeframe
- This topic has 4 replies, 4 voices, and was last updated 1 year ago by Jaanboy321.
-
-
03/08/2023 at 1:21 AM #211065
Hi,
I’m trying to get the below strategy to work but its closing on the wrong timeframe.
Sorry, but I can’t see an ‘insert PRT code’ button on the toolbar on this browser.
For example the backtest shows trades opening when the 1minute MA50 is crossed when want I’m hoping for is for a trade to open within a minute or so of the 1hr MA50 being crossed. The same issue is happening on trade exits. I’m hoping someone can easily spot an obvious error I’ve made! Thanks
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated//limits strategy to 1 trade per dayOnce TradeON = 1If IntraDayBarIndex = 0 thenTradeON = 1EndifIf OnMarket or StrategyProfit <> StrategyProfit[1] ThenTradeON = 0Endif///indicatorsTIMEFRAME(1hours)SD1upper = Average[20](close)+1*std[20](close)SD2upper = Average[20](close)+2*std[20](close)SD3upper = Average[20](close)+3*std[20](close)SD1lower = Average[20](close)-1*std[20](close)SD2lower = Average[20](close)-2*std[20](close)SD3lower = Average[20](close)-3*std[20](close)Av20offset = Average[20](close)*0.9995//(offset so if price gets nearly there it will trigger)Av50offset = Average[50](close)*0.9995Av200offset = Average[200](close)*0.9995Av20 = Average[20](close) //(offset so if price gets nearly there it will trigger)Av50 = Average[50](close)Av200 = Average[200](close)/// UPDATE BELOW UPDATE BELOW UPDATE BELOW UPDATE BELOW UPDATE BELOW UPDATE BELOW UPDATE BELOW UPDATE BELOWSELLCONDITION=Av50offsetBUYCONDITION=SD3lower//risk reward ratioRRRatio=5/// UPDATE ABOVE UPDATE ABOVE UPDATE ABOVE UPDATE ABOVE UPDATE ABOVE UPDATE ABOVE UPDATE ABOVE UPDATE ABOVETIMEFRAME(default, updateonclose)// Conditions to enter long positionsIF high crosses over SELLCONDITION and Not OnMarket THEN //and TradeONSELLSHORT 0.52 PERPOINT AT MARKETENDIF// Conditions to exit long positionsIF low < BUYCONDITION THENEXITSHORT AT MARKETENDIFSET STOP PLOSS ((SELLCONDITION-BUYCONDITION)/RRRatio)03/08/2023 at 5:12 AM #211066Hi there,
123456789// Conditions to enter long positionsIF high crosses over SELLCONDITION and Not OnMarket THEN //and TradeONSELLSHORT 0.52 PERPOINT AT MARKETENDIF// Conditions to exit long positionsIF low < BUYCONDITION THENEXITSHORT AT MARKETENDIF- Buying Long goes by Buy … at Market – Selling long goes by Sell … at Market.
- Even if you’d have that right, the two commands as how you put them, may cancel out each other because both conditions may be true at the same time and there is no prevention against that; for that, the second condition can contain an And OnMarket.
1 user thanked author for this post.
03/08/2023 at 5:48 AM #211067Hi @Jaanboy321
I tried your code and the positions are opened and closed according to the correct time frame…
1 user thanked author for this post.
03/08/2023 at 10:38 PM #211154within a minute or so of the 1hr MA50 being crossed.
At Line 14, instead of …
1TIMEFRAME(1hours)Try
1TIMEFRAME(1hour, updateonclose)1 user thanked author for this post.
03/09/2023 at 10:32 AM #211184Buy version of the code currently utilised in USDJPY1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated//limits strategy to 1 trade per dayOnce TradeON = 1If IntraDayBarIndex = 0 thenTradeON = 1EndifIf OnMarket or StrategyProfit <> StrategyProfit[1] ThenTradeON = 0Endif///indicatorsTIMEFRAME(1hour) //TIMEFRAME(1hour, updateonclose)Donchmid = DonchianChannelCenter[50]SD1upper = Average[20](close)+1*std[20](close)SD2upper = Average[20](close)+2*std[20](close)SD3upper = Average[20](close)+3*std[20](close)SD4upper = Average[20](close)+4*std[20](close)SD1lower = Average[20](close)-1*std[20](close)SD2lower = Average[20](close)-2*std[20](close)SD3lower = Average[20](close)-3*std[20](close)SD4lower = Average[20](close)-4*std[20](close)Av20offset = Average[20](close)*1.00005 //(offset so if price gets nearly there it will trigger)Av50offset = Average[50](close)*1.00005Av200offset = Average[200](close)*1.00005Av20 = Average[20](close) //(offset so if price gets nearly there it will trigger)Av50 = Average[50](close)Av200 = Average[200](close)/// UPDATE BELOW UPDATE BELOW UPDATE BELOW UPDATE BELOW UPDATE BELOW UPDATE BELOW UPDATE BELOW UPDATE BELOWBUYCONDITION=SD3lowerSELLCONDITION=Av20TIMEFRAME(DEFAULT)//risk reward ratioRRRatio=5/// UPDATE ABOVE UPDATE ABOVE UPDATE ABOVE UPDATE ABOVE UPDATE ABOVE UPDATE ABOVE UPDATE ABOVE UPDATE ABOVE// Conditions to enter long positionsIF low crosses under BUYCONDITION and TradeON and Not OnMarket THEN ///and TradeONBUY 0.52 PERPOINT AT MARKETENDIF// Conditions to exit long positionsIF high crosses over SELLCONDITION THENSELL AT MARKETENDIFSET STOP PLOSS ((SELLCONDITION-BUYCONDITION)/RRRatio)Thanks everyone, much appreciated. Currently utilising this version to go long USDJPY (setting closing conditions according to the market) . Its not perfect but seems to do what I need and will experiment with your suggestions as required.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on