[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] How to plot a maximum loss stop line



PureBytes Links

Trading Reference Links

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




------------------------------------

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com
*********************

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html

*********************************
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/