Hi there, I have recently found this Trail stop Code but can't get my handle to understand it so any help is appreciated. Thanks in advance...
Buy=Buy1; // Buy1 is the buy condition that trigger the buy action
Short=Sell1; // Same usage as Buy1
Sell=0;
Cover=0;
SL=Param("trailing stop %", 0.4, 0.1, 10, 0.1);
StopLevel1 = 1 - SL/100;
StopLevel2 = 1 + SL/100;
trailARRAY =trailARRAYs= Null; // why need trail array here where it can't just use the trailstop array?
trailstop =tstop= 0; // why 2 different trailstop array for the same function
for( i = 1; i < BarCount; i++ )
{
if( trailstop == 0 AND Buy[ i ] )
{
trailstop = High[ i ] * stoplevel1;
}
else Buy[ i ] = 0; // remove excess buy signals // how this remove excess signal?
if( trailstop > 0 AND (Low[ i ] < trailstop OR Sell1[i]) ) // what does this line mean?
{
Sell[ i ] = 1;
SellPrice[ i ] = trailstop;
trailstop = 0;
}
if( trailstop > 0 )
{
trailstop = Max( High[ i ] * stoplevel1, trailstop );
trailARRAY[ i ] = trailstop;
}
if( tstop == 0 AND Short[ i ]) // Is this triggering of 2nd level of Trail stop?
{
tstop = Low[ i ]*stoplevel2;
}
else Short[ i ] = 0; // remove excess buy signals // how this remove excess signal?
if( tstop > 0 AND (High[i]>tstop OR Buy1[i]) )
{
Cover[ i ] = 1;
CoverPrice[ i ] = tstop;
tstop= 0;
}
if( tstop> 0 )
{
tstop= Min( Low[ i ]*stoplevel2, tstop);
trailARRAYs[ i ] = tstop;
}
}type or paste code here
Again, thanks in advance for all the help