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

[amibroker] Chandelier-stop code won't run


  • Date: Wed, 02 Dec 2009 12:01:21 -0000
  • From: "pbracs" <jppbracs1@xxxxxxxxxxx>
  • Subject: [amibroker] Chandelier-stop code won't run

PureBytes Links

Trading Reference Links

I'm a newbie so the solution to my problem is probably obvious to everyone (except me).  I've tried to run a single-stock backtest with code by TJ, published in the May 09 issue of Stocks & Commodities (please see below).  It should generate a graph of a trailing stop loss line, by either fixed-% or ATR-chandelier methods, by looping rather than the ApplyStop command. 

When I try to run the code my chart shows "Empty" for the trailing stop loss line.  Likewise, in an exploration AddColumn produces values for sup and res for each i, but trailARRAY is empty. (The graphics for the exploration do generate a line in the chart for the  trailstop line!?)

Any suggestions on how I can get this code to output a backtest?
   ============================   

// "Using Initial and Trailing Stops" (part 1), by Sylvain Vervoort, 
// p36, Stocks & Commodities, May 09, programmed by T. Janeczko

Version(5.20);
SetBarsRequired(sbrAll);

// get start date
Start = Cross( DateNum(), ParamDate("Start date", "2008-12-04") );
Started = Flip( Start, 0);

StopMode = ParamToggle( "Stop Mode", "Fixed | Chandelier" );
StopLevel = Param( "Fixed perc %", 14, 0.1, 50, 0.1)/100;
StopATRFactor = Param( "Chandelier ATR Multiple", 4, 0.5, 10, 0.1 );
StopATRPeriod = Param( "Chandelier ATR period", 14, 3, 50 );

// calculate support and resistance levels
if( StopMode == 0 ) // fixed percentage trailing stop
{
sup = C * (1 - stoplevel);
res = C * (1 + stoplevel);
}
else  // Chandelier ATR-based stop
{
sup = C - StopATRFactor * ATR( StopATRPeriod );
res = C + StopATRFactor * ATR( StopATRPeriod );
}

// calculate trailing stop line
trailARRAY = Null;
trailstop = 0;
for( i=1; i<BarCount; i++)
{
if( Started[i] ==0 ) continue;

if( C[i] > trailstop AND C[i-1] > trailstop )
   trailstop = Max( trailstop, sup[i] );
else
if( C[i] < trailstop AND C[i-1] < trailstop )
   trailstop = Min( trailstop, res[i] );

else
   trailstop = IIf( C[i] > trailstop, sup[i], res[i] );

trailARRAY[i] = trailstop;
}

//  generate buy/sell signals based on crossover with trail stop line 
Buy = Start OR Cross( C, trailArray );
Sell =  Cross( trailArray, C);

PlotShapes( Buy*shapeUpArrow, colorGreen, 0, trailarray);
PlotShapes( Sell*shapeDownArrow, colorRed, 0, trailarray);

Plot( Close, "Price", colorBlack, styleBar);
Plot( trailARRAY, "trailing stop level", colorRed);



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

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

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

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

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

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:
    amibroker-digest@xxxxxxxxxxxxxxx 
    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/