FX/Dax Trading Strategy
Forums › ProRealTime English forum › ProOrder support › FX/Dax Trading Strategy
- This topic has 3 replies, 2 voices, and was last updated 5 years ago by
robertogozzi.
-
-
01/30/2020 at 1:13 PM #118272FX Trading Strategy Code1234567891011121314151617181920212223242526272829303132333435363738394041424344// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated//Condition To Ensure That Only One Transaction Can Happen Per Bar – for example on any 30 min bar this condition is meant to stop the exit of a Long AND an initiation of a Short during the same 30 min period. Not fully convinced if this is coded correctly for this purpose.ONCE BarCount = 0ONCE TradeON = 1 //1=trading allowed 0=trading disbaledIF LongOnMarket OR ShortOnMarket AND Not LongOnMarket[1] AND Not ShortOnMarket[1] THENTradeON = 0 //disable tradingBarCount = 0 //reset counterENDIFIF Not LongOnMarket And Not ShortOnMarket THEN //Increase counter when not on marketBarCount = BarCount + 1ENDIFIF BarCount > 1 THENTradeON = 1ENDIF// Conditions to enter long positionsc1 = (close < open)IF c1 AND TradeON THENBUY 1 SHARES AT MARKETENDIF// Conditions to exit long positionsc2 = (close > open)IF c2 THENSELL AT MARKETENDIF// Conditions to enter short positionsc3 = (close > open)IF c3 AND TradeOn THENSELLSHORT 1 SHARES AT MARKETENDIF// Conditions to exit short positionsc4 = (close < open)IF c4 THENEXITSHORT AT MARKETENDIF
I’ve used this strategy on Bloomberg over 30 years of FX data (30 min bars) and it works very well and would now like to add it to PRT but am unsure of if I have coded it correctly and would very much appreciate your feedback.
To confirm, this is what the strategy is meant to do on FX pairs with 30 min bars:
- Enter Long at the Next Open when the 30 min bar Closes < its Open
- Exit Long at the Next Open when the 30 min bar Closes > its Open
- Enter Short at the Next Open when the 30 min bar Closes > its Open
- Exit Short at the Next Open when the 30 min bar Closes < its Open
A few questions:
Is the code specified correctly for this Entry and Exit rules listed above ?
Is the code correct for FX trades ? Also, how could it be modified if it was to be used on stock indices (esp. DAX)?
Critically of all, is the “timer” condition I have specified at the top of the code correct (I doubt it). Effectively, the strategy I wish to add to PRT should only allow one transaction per 30 min bar (so for example, if a bar closes>open, on the next bar, the strategy should EITHER Exit a Long (if one exists) OR Enter a Short (but not both exit a long and enter a short at the same time).
Thank you very much in advance for your help.
01/30/2020 at 2:32 PM #118275Replace lines 19-44 with:
12345678910111213141516c1 = (close < open)c2 = (close > open)IF c1 AND TradeON THENIf ShortOnMarket ThenEXITSHORT AT MARKETElsif not LongOnMarket ThenBUY 1 SHARES AT MARKETENDIFENDIFIF c2 AND TradeON THENIf LongOnMarket ThenSELL AT MARKETElsif not ShortOnMarket ThenSELLSHORT 1 SHARES AT MARKETENDIFENDIFThe use of BarCount is useful if you use multiple and lower TFs. On a 30-minute TF no more than 1 trade can occur on the same bar.
1 user thanked author for this post.
01/30/2020 at 4:17 PM #11828301/30/2020 at 5:13 PM #118286Actually my code is logically incorrect, since it does not allow closing open trades when TredeON=0. While this condition should not allow to OPEN new positions, it shouldn’t forbid open positions from being CLOSEd:
12345678910111213141516c1 = (close < open)c2 = (close > open)IF c1 THENIf ShortOnMarket ThenEXITSHORT AT MARKETElsif not LongOnMarket AND TradeON ThenBUY 1 SHARES AT MARKETENDIFENDIFIF c2 THENIf LongOnMarket ThenSELL AT MARKETElsif not ShortOnMarket AND TradeON ThenSELLSHORT 1 SHARES AT MARKETENDIFENDIF -
AuthorPosts
Find exclusive trading pro-tools on