Upon entering a position I want to set a stop loss for that trade based on a distance of 4 times the 10 day ATR from the price I entered at ; for example -" SetStopLoss(CalculationMode.Price, Position.AvgPrice - ATR(10)[0]*4); "
On each bar update I then want to reset the stop loss using the same method (i.e. at a distance of 4 times the ATR from the new price) IF the trade has moved in my favour. However, if the trade has gone against me I want the stop loss to remain unchanged.
I have placed the "StepStopLoss" method as described above in the OnBarUpdate () event in the same Condition Set where I enter the positions because the ATR is a dynamic value so I understand it has to be in OnBarUpdate and not in Initialize()????
I have attached a screenshot of this, however, it does not appear to be working correctly in that the stop losses do not appear to be executing correctly, can you assist?
In the screenshot you will notice that I have not yet inclued the logic to say only to update the stop loss if the position has moved in my favour; how do I do this? I was going to use something like on a long position - if (Close [1] < Close [0]) ....set the stop loss.........but this won't compile because it says I can't use "close" in this context when I use it in the OnBarUpdate ().
Thanks,
Ciaran

Comment