I would find useful to have a trailing stop that will stay below the SAR indicator when buying and vice versa when selling. The same coding I guess would apply if using a Moving average or other indicator.
I used the below code that gives excellent result in back-testing but it appears is a sort of curve fitting as it does not work in real market.
Hello Bob, pTRAILING is a pip/point distance between the STOP and the current price. So you have to find this distance by substracting the SAR value and the price one.
The example i shown to you is a dynamic trailing stop. It’s actually the same to have a fixed price or a price difference between 2 points.
Just to be clear :
1
2
3
4
5
6
7
SAR1=SAR[0.02,0.02,0.2][1]
// Stops and targets
mytrailing=ABS(Open-SAR1)
SET STOPpTRAILINGmytrailing
or you can also change dynamically your stoploss at each new bar :
1
2
3
4
5
6
7
SAR1=SAR[0.02,0.02,0.2][1]
// Stops and targets
mystop=ABS(Open-SAR1)
SET STOPpLOSSmystop
Of course I made no conditional request to the server to test if the SAR is above or below your price, it will handle by itself if it can place the stoploss for a buy or a sell order.
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue