Question how to move stoploss to neut?
Forums › ProRealTime English forum › ProOrder support › Question how to move stoploss to neut?
- This topic has 5 replies, 3 voices, and was last updated 5 years ago by
robertogozzi.
-
-
12/18/2020 at 12:42 PM #154267
Hell0,
I am working on my backtest code for EUR/USD. To makes things easy I only talk about LONG positions!
My buy is when the average[20] crosses over average[50]. I work with a fixed target of 10 pips and original stoploss at the lowest of the last 5 bars. BUT after a high has reached the 4 pips, I want to move the stoploss to neutral, which means the buy price. That last thing doesn’t work.How do need to describe this?
Thanks a lot, Marc
stoploss to neutral after reached a certain level1234567891011121314151617181920defparam cumulateorders = false//conditions for longmashort = average[20] (close)malong = average[30] (close)c1= (mashort crosses over malong)if c1 thenBUY 1 contract at marketstoploss = lowest[5] (low)endif// Conditions to put the stoploss to neutral after the high has been above the buy plus 4 pipsif LongOnMarket and high => positionprice + 4 thenstoploss = positionpriceendif// Stops and TargetsSET TARGET pPROFIT 10SET STOP ploss stoploss12/18/2020 at 1:02 PM #15427312/18/2020 at 1:16 PM #154276You are mixing prices with pips.
StopLoss is a price, while SET STOP PLOSS requires pips, with Dax your SL would become 13700 pips, with Eur/Usd just a little more than 1 pip.
Try replacing line 15 with:
1stoploss = abs(positionprice - high) / PipSizeBut I think the new stoploss would be set from PositionPrice, not high, so it wouldn’t be a breakeven.
Using a pending Stop order might be a better solution.
Let me know if the above doesn’t work.
12/18/2020 at 2:03 PM #154285Thanks Xorandnot,
It looks logical, though, when I backtest, it doesn’t do what I expect it will do. I changed the original SL to a fixed numberof 4 pips, because I see that it didn’t take the stoploss at the lowest low from the last 5 candles as descibed befor. But even then, it doesn’t move the SL to neutral after the price has reached 4 pips.
See the image.
I know it has to do with the order in my programming.1234567891011121314151617181920212223242526272829// defenition of code parametersdefparam cumulateorders = false//conditions for longmashort = average[20] (close)malong = average[30] (close)c1= (mashort crosses over malong)if c1 thenBUY 1 contract at marketendif// Conditions to put the stoploss to neutral after the high has been above the positionprice of 4 pipsnb = barindex - tradeindexhighesthigh = highest[nb+1](high)If longonmarket and (not c1) and highesthigh >= positionprice + 4 thensell at positionprice stopendif// Stops and TargetsSET TARGET pPROFIT 10SET STOP ploss 412/18/2020 at 2:24 PM #154291Thanks Roberto,
Yes of course, I mix pips and price. Not good 🙂 I use EUR/USD, 600 ticks
But still… 2 things don’t work in my coding.
1. When BUY then I want the stoploss below the lowest low form the previous 5 candles. The code like down here doesn’t work like that.
if c1 then
BUY 1 contract at market
stoploss = lowest[5] (low)
endif2. When after BUY the price has reached 4 pips above the BUY, then I want the SL moved to neutral.
I have changed my line 15 the way you suggested, but that doesn’t seem to work.1234567891011121314151617181920defparam cumulateorders = false//conditions for longmashort = average[20] (close)malong = average[30] (close)c1= (mashort crosses over malong)if c1 thenBUY 1 contract at marketstoploss = lowest[5] (low)endif// Conditions to put the stoploss to neutral after the high has been above the buy plus 4 pipsif LongOnMarket and high => positionprice + 0.0004 thenstoploss = abs(positionprice - high) / PipSizeendif// Stops and TargetsSET TARGET pPROFIT 10SET STOP ploss stoploss12/18/2020 at 2:48 PM #1542944 pips might be too few, check with IG what’s the minimum required.
At line 9 you should add AND Not OnMarket to your conditions, so that your calculation is not made after entering a trade since this makes your SL to move each candle.
A pending stop order, similar to the one suggested by XorAndNot might be useful.
-
AuthorPosts
Find exclusive trading pro-tools on