Folks,
I have copied this code from the source below;
Can some one tell me what changes need to be made so the stop is below the price action immediately after the buy ?
/// INCORRECTLY FORMATTED CODE FOLLOWS
//http://www.traderji.com/community/threads/trailing-stop-afl.101500///
StopATRFactor = Param("ATR multiple", 4.3, 0.5, 10, 0.1 );
StopATRPeriod = Param("ATR period", 14, 3, 50,1 );
sup = C - StopATRFactor * ATR( StopATRPeriod );
res = C + StopATRFactor * ATR( StopATRPeriod );
// calculate trailing stop line
trailARRAY = Null;
trailstop = 0;
for( i = 1; i < BarCount; i++ )
{
if( C[ i ] > trailstop AND C[ i - 1 ] > trailstop )
trailstop = max( trailstop, sup[ i ] );
else
if( C[ i ] < trailstop AND C[ i - 1 ] < trailstop )
trailstop = Min( trailstop, res[ i ] );
else
trailstop = IIf( C[ i ] > trailstop, sup[ i ], res[ i ] );
trailARRAY[ i ] = trailstop;
}
/// SNIP INCORRECTLY FORMATTED CODE