You can or cannot use ABS, it depends on your coding style. Look at this code, the most widely used for trailing stops https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/.
To check if the current price has reached your trailing stop treshold you can (but the above example is complete and perfectly working AS IS) write:
// for LONG trades
IF TRADEPRICE - close >= MyTreshold THEN
.
.
ENDIF
// for SHORT trades
IF close - TRADEPRICE >= MyTreshold THEN
.
.
ENDIF
Negative values do not work with a SET STOP.
SebParticipant
Average
Alright, so you can only trail to break-even with a SET STOP type stoploss. Than I will try to find out what’s causing the strange overnight behavior with the stops as described in my first post.
Also do not forget that if you send an order to the market that is too close to the price then the order will be rejected. You need to consider the minimum allowed stop distance for whatever instrument you are trading and include something in your code to ensure you never try to place an order that is under it.
SebParticipant
Average
I experienced that if it tries to put in a stoploss and the current price is beyond the stoploss level, the position closes at market (with IG CFD). Stops too close indeed got rejected. Will this shut the system down after too many rejections?
Will this shut the system down after too many rejections?
Yes, after 12 rejections, you are closed down on the 13th I think?
Not sure if there is a time limit on that, like > 12 rejections within 1 week etc??