I have been attempting to plot a maximum loss stop line following the 
code for plotting a trailing stop provided by TJ in the Knowledge 
base:

http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-
the-price-chart/

My code follows, unfortunately it doesn't work!  I have used ticks 
for max loss allowed instead of percentages.  I also wanted a system 
that would accomodate either long or short sales. 

////////////////////////Code begins/////////////////////////////
StopLevelticks = Param("stoplevel ticks", 3, 0, 20, 1 );
stoplevelpoints = stoplevelticks*TickSize;
SetTradeDelays(0,0,0,0);

Buy = Cross( MACD(), Signal() );
Short = Cross(Signal(), MACD() );
Sell = 0;
Cover = 0;
ApplyStop( stopTypeLoss, stopModePoint, StopLevelpoints, True );
 
Equity( 1, 0 ); // evaluate stops, all quotes

InTradelong = Flip( Buy, Sell );
InTradeshort = Flip( Short, Cover );

SetOption("EveryBarNullCheck", True );
stoplinelong = IIf( InTradelong, ValueWhen( Buy, BuyPrice) - 
stoplevelpoints , Null );
stoplineshort = IIf( InTradeshort, ValueWhen( Short, ShortPrice) + 
stoplevelpoints , Null );

PlotShapes(Buy*shapeUpArrow,colorBrightGreen,0,Low);
PlotShapes(Short*shapeDownArrow,colorRed,0,High);
PlotShapes(Cover*shapeHollowUpArrow,colorBrightGreen,0,Low);
PlotShapes(Sell*shapeHollowDownArrow,colorRed,0,High);

SetBarFillColor( IIf( C > O, colorBrightGreen, colorRed ) );

Plot( Close,"Price",colorWhite,styleCandle);
Plot( stoplinelong, "maxloss line long", colorBrightGreen );
Plot( stoplineshort, "maxloss line short", colorRed );
//////////////////////////Code Ends/////////////////////////////////

 Converting TJ's code from a trailing stop to a maximum loss stop and 
getting the functionality to handle shorts  proved to be be more 
difficult than I had anticipated.

I would appreciate any help in clearing up the problems in the code 
above.

Thanks in advance,

Grover Yowell



Reply via email to