Johannesburg + South Africa
Posts: 4 since Jul 2014
Thanks Given: 0
Thanks Received: 0
|
Hi Folks,
Amibroker trailing stop:
StopLevel = 1 - Param("trailing stop %", 3, 0.1, 10, 0.1)/100;
Buy = Cross( MACD(), Signal() );
Sell = 0;
trailARRAY = Null;
trailstop = 0;
for( i = 1; i < BarCount; i++ )
{
if( trailstop == 0 AND Buy[ i ] )
{
trailstop = High[ i ] * stoplevel;
}
else Buy[ i ] = 0; // remove excess buy signals
if( trailstop > 0 AND Low[ i ] < trailstop )
{
Sell[ i ] = 1;
SellPrice[ i ] = trailstop;
trailstop = 0;
}
if( trailstop > 0 )
{
trailstop = Max( High[ i ] * stoplevel, trailstop );
trailARRAY[ i ] = trailstop;
}
}
PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
Plot( Close,"Price",colorBlack,styleBar);
Plot( trailARRAY,"trailing stop level", colorRed );
Is there a way to change the code to become more conservative when a filter is added? E.g. filter:
X=Foreign("^GSPC", "C", True);
IMA=WMA(X,75);
When X<IMA the filter is triggered.
How can the above coding be changed so that the stop becomes tighter. So if the initial stop is 20% from position entry, the new coding provides for a move to 15% when the filter is triggered and when filter is relaxed stop moves back to 20% ?
Thanks
rshor
|