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 CrossMAClose20), MAClose50) );
Sell CrossMAClose50), MAClose20) );

// 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 CrossMAClose50), MAClose100) );
 
Sell CrossMAClose100), MAClose50) );
}

// system for IBM
if( Name() == "IBM" )
{
 
Buy CrossMACD(), Signal() );
 
Sell CrossSignal(), MACD() );
}

// system for NVDA
if( Name() == "NVDA" )
{
 
Buy CrossRSI(), 30);
 
Sell 0;
 
ApplyStopstopTypeNBarstopModeBars10);

Note that different per-symbol stops (ApplyStop) are possible only in regular (non-rotational) backtest.

No comments yet. Be the first.

Leave a reply