trailing stop

It would be easier to help if you said what you are coding with.
 
You need to grab one of the online tutorials for easy language. Trailing stops must be one of the standard things that are used as examples in these tutorials.

You just need to decide how much you want your buffer zone to be between the market and the stop.

When you put on a long trade, set a variable to keep track of the high. Every iteration, check to see if it has made a higher high and if so, save the new high.

Set the exit for that price minus your buffer as a stop.
 
Top