September 29, 2006
How to set individual trading rules for symbols in the same backtest
The following code shows how to use separate trading rules for several symbols included in the same backtest.
// default trading rules if the symbol is not specified below:
Buy = Cross( MA( Close, 20), MA( Close, 50) );
Sell = Cross( MA( Close, 50), MA( Close, 20) );
// individual trading rules for selected symbols
// that will overwrite the above default rules
// if particular symbol is detected
// system for MSFT
if( Name() == "MSFT" )
{
Buy = Cross( MA( Close, 50), MA( Close, 100) );
Sell = Cross( MA( Close, 100), MA( Close, 50) );
}
// system for IBM
if( Name() == "IBM" )
{
Buy = Cross( MACD(), Signal() );
Sell = Cross( Signal(), MACD() );
}
// system for NVDA
if( Name() == "NVDA" )
{
Buy = Cross( RSI(), 30);
Sell = 0;
ApplyStop( stopTypeNBar, stopModeBars, 10);
Note that different per-symbol stops (ApplyStop) are possible only in regular (non-rotational) backtest.
Filed by AmiBroker Support at 6:55 am under Backtest
Comments Off on How to set individual trading rules for symbols in the same backtest