Hello All,
I'm tryin to code a trailing stop loss but am having a number of
problems with writing the code.
What I'm trying to achieve is:
1. Once a Buy signal appears from my system, the value of the current
AccDist() Line should be recorded.
2. As long as the AccDist() moves upwards the trade should remain
open.
3. However, once the AccDist() line falls by a certain percentage
(say 10% for this example) from its Highest value since the trade was
opened, the trade should be stopped out.
I have some code for a simple trailing stop based on the Low of the
price (see below) but I'm not sure how to modify it to accomplish the
above.
Any ideas would be most welcome...
Initial = LLV(Low,5);
stop[0] = Close[0];
for( i = 1 ; i < BarCount; i++)
{
if( Close[i] > stop[i-1])
{
stop[i] = Max( initial[i], stop[i-1] );
}
else { stop[i] = initial[i]; }
}
Plot( stop, " Stop Loss", ParamColor("Color", colorCycle ), ParamStyle
("Style", styleDots | styleNoLine, maskDefault | styleDots |
styleNoLine ) );
Many Thanks in advance,
Chorlton