Code:long = 0; // long backtest true/false period = 20; // number of averaging periods m = MA( Close, period ); // simple moving average if ( long ) { Buy = Cross( Close, m ); // buy when close crosses ABOVE moving average Sell = Cross( m, Close ); // sell when closes crosses BELOW moving average SetFormulaName( Name() + "_Long Backtest" ); // displayed in the backtest result explorer. } else { Short = Sell; Cover = Buy; SetFormulaName( Name() + "_Short Backtest" ); // displayed in the backtest result explorer. }
or create one or two clones of a symbol (like ~AAPL_1 and ~AAPL_2 ) via addtocomposite
and then you could use individual backtester (not portfolio BT) to run over group 253:
Code:period = 20; // number of averaging periods m = MA( Close, period ); // simple moving average if ( StrFind( Name(), "_1" ) && groupID() == 253 ) { Buy = Cross( Close, m ); // buy when close crosses ABOVE moving average Sell = Cross( m, Close ); // sell when closes crosses BELOW moving average SetFormulaName( Name() + "_Long Backtest" ); // displayed in the backtest result explorer. } if( StrFind( Name(), "_2" ) && groupID() == 253 ) { Short = Sell; Cover = Buy; SetFormulaName( Name() + "_Short Backtest" ); // displayed in the backtest result explorer. }
Well Short cover rules in those examples should be
Code:
Short = Cross( m, Close );
Cover = Cross( Close, m );