How to code trade only trade hours if trading hours cross midnight ?
Forums › ProRealTime English forum › ProOrder support › How to code trade only trade hours if trading hours cross midnight ?
- This topic has 3 replies, 3 voices, and was last updated 3 years ago by
robertogozzi.
-
-
10/05/2021 at 9:48 AM #179059
How to make the strategy trade throughout trade hours if the hours cross to the next day – when the exchanges trade hours cross over midnight ?
For example the DAX: Opens = 1800 AEDT, Closes =0930 AEDT (the following day).
How as such to code FLATBEFORE 1800, and FLATAFTER 09:30 (the next day) ? Without having issue of having to do 2 different strategies and the lose of money from the spread by having to sell/close at 235959 and then buy/open at 000001.
Or is there any way that strategies could be coded to avoid different times too, eg. for the USDJPY to be closed at end of USA trade (0630) until start of Japan trade (1130) to avoid whiplashes)
Thanks in advance 🙂
10/05/2021 at 3:19 PM #179091This will do:
1234567891011121314StartTime = 180000 //try also 110000EndTime = 093000 //try also 160000TradeON = 0IF OnMarket THENSELL AT MarketENDIFIF StartTime <= EndTime THENTradeON = (time >= StartTime) AND (Time <= EndTime)ELSETradeON = ((time >= StartTime) AND (Time < 240000)) OR ((Time >= 000000) AND (Time <= EndTime))ENDIFIF Not OnMarket AND Tradeon thenBUY AT MarketENDIFTradeON will be true whenever the candle is within the chosen time range.
1 user thanked author for this post.
10/06/2021 at 4:17 AM #179106123IF OnMarket THENSELL AT MarketENDIFRoberto, what do you intend with this ? It looks like you were in a hurry somewhat. 🙂
Or is there any way that strategies could be coded to avoid different times too, eg. for the USDJPY to be closed at end of USA trade (0630) until start of Japan trade (1130) to avoid whiplashes)
Assumed I understood correctly : I think I would dive into over-creativity and code something like
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071TradeOn = 0TradeBailOut = 0InstrIsEURUSD = 0InstrIsEURGBP = 0InstrIsUSDJPY = 0If Close > 1.14 and Close < 1.19 then // EUR/USD ?InstrIsEURUSD = 1TradeOn = 1EndifIf Close > 0.81 and Close < 0.91 then // EUR/GBP ?InstrIsEURGBP = 1TradeOn = 1EndifIf Close > 106 and Close < 117 then // USD/JPY ?InstrIsUSDJPY = 1TradeOn = 1EndifIf TradeEURUSD then// Here the code for the EUR/USD TradeOn times and other pair specialties :// If ... etc. then// TradeOn = 1// endif// Here the code for the EUR/USD Bail-out times :// If ... etc. then// TradeBailOut = 1// endifendifIf TradeEURGBP then// Here the code for the EUR/GBP TradeOn times and other pair specialties :// If ... etc. then// TradeOn = 1// endif// Here the code for the EUR/GBP Bail-out times :// If ... etc. then// TradeBailOut = 1// endifendifIf TradeUSDJPY then// Here the code for the USD/JPY TradeOn times and other pair specialties :// If ... etc. then// TradeOn = 1// endif// Here the code for the USD/JPY Bail-out times :// If ... etc. then// TradeBailOut = 1// endifendif// Bail out before Settlement (end of day etc.) :If OnMarket thenIf TradeBailOut// My Sell At Market code.endifTradeOn = 0endifIf TradeOn then// My General Fx Strategy code.endifIOW, welcome to my monster.
This would work as long as I regularly revisit the code and actualise the bands to recognise the pairs. Obviously there should not be any overlap between the pairs.
Please notice that in the end this will not be workable really, because of too many specifics for the pair. Thus, you won’t be able to capture all in the same strategy code. But this is up to you of course.
Good luck !
Peter1 user thanked author for this post.
10/06/2021 at 5:30 AM #179108My fault, lines 4-5-6 have no relation with the time question.
I still had it in my mind from what I had written a few minutes before!
They correct code is:
1234567891011StartTime = 180000 //try also 110000EndTime = 093000 //try also 160000TradeON = 0IF StartTime <= EndTime THENTradeON = (time >= StartTime) AND (Time <= EndTime)ELSETradeON = ((time >= StartTime) AND (Time < 240000)) OR ((Time >= 000000) AND (Time <= EndTime))ENDIFIF Not OnMarket AND Tradeon thenBUY AT MarketENDIF1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on