What is your value of "TickSize"? If it's zero, ApplyStops seems to do
nothing and you don't get any sell signals. If it's a positive value,
then it is in dollars and the resulting value of stopLevelPoints may
be too large for the current share price.

If I try your formula with a tick size of 0.01 (ie. 1 cent), it works
as expected.

Regards,
GP


--- In [email protected], "gyowell2000" <[EMAIL PROTECTED]> wrote:
>
> 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