How do I open and close trades at levels relative to the signal bar?
Forums › ProRealTime English forum › ProOrder support › How do I open and close trades at levels relative to the signal bar?
- This topic has 5 replies, 2 voices, and was last updated 7 years ago by
Nicolas.
-
-
10/04/2017 at 3:04 PM #48201
As an example, when I get a Buy signal (say caused by 2 moving averages crossing), I would like to enter the trade if the next bar’s price goes above the high of the signal bar (and enter the trade at that price not the open of the following bar)
The profit target would be lets say 2 * ATR(14) above the high of the signal bar.
The exit would be if the price crosses below the high of the signal bar – the ATR(14) at the time of the signal bar.
Lastly, I have borrowed part of this code from MattyJ (thank you). Using the money management code here, how do I code this so the trade size (I am spread betting) is 5% of the account size at the time of the trade?
12345678910111213141516171819202122232425262728293031323334353637383940414243defparam cumulateorders=falsebarquantity=5 //how many bars to wait after a signal to open a new orderREM Money ManagementCapital = 1000 // initial capital at launch of the strategyRisk = 0.05 // risk in percentREM Calculate contractsequity = Capital + StrategyProfitmaxrisk = round(equity*(Risk/100))indicator1 = Average[25](close)indicator2 = Average[250](close)indicator3 = Average[15](close)c1 = (indicator1 CROSSES OVER indicator2)c2 = (indicator1 CROSSES UNDER indicator3)if c1 thenbuybar=barindexbuyprice=closeendifif c2 thensellbar=barindexsellprice=closeendifstillbullish = buybar>sellbarstillbearish = sellbar>buybarif stillbullish and barindex-buybar>=barquantity and gobuy<>buybar and close>buyprice thenbuy maxrisk -0.5 perpoint at marketgobuy=buybarendifif stillbearish and barindex-sellbar>=barquantity and gosell<>sellbar and close<sellprice thensellshort maxrisk-0.5 perpoint at marketgosell=sellbarendif10/04/2017 at 4:51 PM #48209I recognize the code we made recently in the Mattyj’s topic.
I understand your request about the changes to made to this code, but you did not mention if the elapsed bars after the MA cross conditions should be left or not?
5% of the account size at the time of the trade
It is already the case in the strategy, despite the fact that Mattyj reduced the calculated lots by 0.5 at lines 36 and 41 (don’t know why).
10/04/2017 at 6:15 PM #48214Thank you for the very quick reply Nicolas. I’m not sure what you mean about the elapsed bars being left or not. Sorry if I wasn’t very clear. What I meant was the bar at which time the MAs cross is what I call the signal bar. This should be the reference point for the entry . So in an up trade the high of the signal bar would be the entry level and the take profit would be 2 ATRs above the high and the stop loss would be 1 ATR below the high.
After each trade the account size would be adjusted and the amount per point on the next trade would change based on the risk percentage stated.
10/05/2017 at 12:11 PM #48259ok I understand your strategy, but the code provided embed a lot more than a simple MA cross: it has condition about bars to wait before opening a trade after a cross and it has also 3 MA, not only 2. I’d rather start from scratch 🙂
So, to be sure: only 2 moving average and no need to wait X bars before launching orders? (apart from the fact that it is necessary to wait for a break of the High of the signal bar).
10/05/2017 at 2:49 PM #4829910/05/2017 at 4:09 PM #48314Fine, let’s try with this code, do your own tests cause I didn’t.
12345678910111213141516171819202122232425262728293031323334353637383940defparam cumulateorders=falseREM Money ManagementCapital = 1000 // initial capital at launch of the strategyRisk = 5 // risk in percentREM Calculate contractsequity = Capital + StrategyProfitmaxrisk = round(equity*(Risk/100))MAfast = Average[7](close)MAslow = Average[21](close)atr = averagetruerange[14]c1 = (MAfast CROSSES OVER MAslow)c2 = (MAfast CROSSES UNDER MAslow)//The profit target would be lets say 2 * ATR(14) above the high of the signal bar.//The exit would be if the price crosses below the high of the signal bar – the ATR(14) at the time of the signal bar.if c1 thentrigger = hightp = atr*2sl = atrelsif c2 thentrigger = lowtp = atr*2sl = atrendifif MAfast>MAslow and trigger>0 and close<trigger thenBUY maxrisk CONTRACTS AT trigger stopendifif MAfast<MAslow and trigger>0 and close>trigger thenSELLSHORT maxrisk CONTRACTS AT trigger stopendifset target profit tpset stop loss sl -
AuthorPosts
Find exclusive trading pro-tools on