StopLevel =Param("Percentage Trail
Stop",0.05,
0.01,
0.6, 0.01 );
LK=50;
FF=10;
A1= IIf( L> Ref(HHV(
Close,LK),-5), 1, 0);
A2= Sum( A1, LK ) ;
A3= IIf(C>0, FF,
0);
Buy = Cross(A2,A3);
Sell = 0;
trailARRAY = Null;
trailstop = 0;
for( i = 1; i <
BarCount; i++ )
{
if( trailstop == 0 AND
Buy[ i ] )
{
trailstop = High[ i ] * (1-stoplevel);
}
else Buy[ i ] = 0; // remove excess buy signals
if( trailstop > 0 )
{
trailstop = Max( High[ i ] * (1-stoplevel),
trailstop );
trailARRAY[ i ] = trailstop;
}
if( trailstop > 0 AND
Low[ i ] < trailstop )
{
Sell[ i ] = 1;
SellPrice[ i ] = trailstop;
trailstop=0;
}
}
PlotShapes(Buy*shapeUpArrow,colorBlue,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
Plot(
Close,"Price",colorBlack,styleBar);
Plot(
trailARRAY,"trailing stop
level", colorRed
); |
_SECTION_BEGIN("Cr.HautP.");
TimeFrameSet( inDaily
); // switch now to Daily
HautP= Ref(H,-1) ;
BasP= Ref(L,-1)
;
TimeFrameRestore();
// restore time frame to original
StopLevel = BasP ;
Buy = Cross(C,HautP) ;
Sell = 0 ;
trailARRAY = Null;
trailstop = 0;
for( i = 1; i <
BarCount; i++ )
{
if( trailstop == 0 AND
Buy[ i ] )
{
trailstop = HautP ;
}
else Buy[ i ] = 0; // remove excess buy signals
if( trailstop > 0 )
{
trailstop = Max( HautP, trailstop );
trailARRAY[ i ] = trailstop;
}
if( trailstop > 0 AND
Low[ i ] < trailstop )
{
Sell[ i ] = 1;
SellPrice[ i ] = trailstop;
trailstop=0;
}
}
PlotShapes(Buy*shapeUpArrow,colorBlue,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
Plot(
Close,"Price",colorBlack,styleBar);
Plot(
trailARRAY,"trailing stop
level", colorRed
);
_SECTION_END(); |