This is a simple Expert Advisor with an implemented trailing stop.
It has only two parameters:
Â
TrailingStop — the distance between the price and the Stop Loss level.
TrailingStep — protection against to frequent modification of position.Â
How TrailingStop works — the example of the Buy position:Â
Originally the StopLoss of a position is equal to zero, we wait for the following condition to be met
— i.e. when the Bid minus TrailingStop is greater than the position open price PriceOpen:
StopLoss is moved to the PriceOpen level (position open price):
now, when the position has StopLoss (i.e. when StopLoss is not equal to zero), wait for the following condition to be met:
— i.e. when the Bid minus TrailingStop minus TrailingStep is greater than the StopLoss price: So here we need to additionally check TrailingStep — this prevent position modification on every tick:
StopLoss is then moved to Bid minus TrailingStop:
Â
Here is why we need a protection in the form of TrailingStep:
Â