Specifiche
I have attached a strategy below which I require you to add a trailing stop loss, there is an explanation below on how the trailing stop loss works, it is from the meta stock system tester in case you are wondering or have used it before.
All I require is the following stop loss to be added
Also, regarding the buy and sell condition it is available on the sheet
How does the Trailing Stop work?
The following is an example of a 2 point trailing stop, with and without a 3 bar delay:
A trade is triggered on a security. The entry price is 50. Over the next several bars, the price rises to 55. On the next bar, the price drops to 54. The following bar sees a drop to 52.5. Then the price rises to 53.5. From there, it continues to climb till it reaches 65. At this point, the price starts to fall rapidly. The next several bars have prices of 63, 61, 59, and 57 respectively.
A two point trailing stop, with no delay:
The trade is entered at 55. The stop moves up with the prices. When the price reaches 55, the stop is at 53. Two bars later, the stop is triggered and the trade is closed.
A two point trailing stop, with a 3 bar delay:
The trade is entered at 55. The stop moves up with the prices, but using the closing price from 3 bars prior to the current to calculate the stop level. Therefore, when the price begins to fall from the 55 bar high, the stop is being calculated from the price 3 bars earlier. It will not use the value of 55 till the prices have already moved back above 53 and the trade will remain open. When the prices reach 65 and begin to fall, the stop is still being used on the price 3 bars earlier. This means the prices will fall past 63, probably to 61 before being stopped out.
{Long trailing stop}
x:=1 { enter the trailing stop percent } ;
trade:= 1 { enter buy condition };
tep:=C; { trade entry price }
start:=ValueWhen(1,trade,tep);
r:=C-start;
lvl:= C-(r*(x/100));
stop:=If(trade,H-((H-tep)*(x/100)),
If(ROC(C,1,%)>0,Max(lvl,PREV),PREV));
Cross(stop,L)
{Short trailing stop}
x:=1 { enter the trailing stop percent } ;
trade:= 1 { enter sell short condition };
tep:=C; { trade entry price }
start:=ValueWhen(1,trade,tep);
r:=start-C;
lvl:= C+(r*(x/100));
stop:=If(trade,L+((tep-L)*(x/100)),
If(ROC(C,1,%)<0,Min(lvl,PREV),PREV));
Cross(H,stop)