Backtest consists of trading one stock and one futures

Hi all, may I ask is there any documentation regarding how to backtest a portfolio consisting one stock and one futures? Thanks.

You may do so by code
So if the ticker is futures one then you enable futures mode else you disable it.

SetOption("InitialEquity", 1000000);
SetOption( "MaxOpenPositions", 2);

// if symbol is future one
if ( Name() == "YOUR_FUTURE_SYMBOL" ) {
	SetOption("FuturesMode", True);
	SetPositionSize( 1, spsShares);// e.g. one contract
	// OPTIONAL (as it can be set in Information window also):
	MarginDeposit = /* Set margin deposit */;
	PointValue = /* Set Contract's point vale*/;
	TickSize = /* Set Contract's tick size*/;
	RoundLotSize = 1;	

	Buy = /*your rules for futures contract */;
	Sell = /*your rules for futures contract */;
} else { // if it is Stock
	SetOption("FuturesMode", False);
	SetPositionSize( 1000, spsShares);// e.g. 1000 shares

	Buy = /*your rules for stock*/;
	Sell = /*your rules for stock*/;	

Buy  = Ref( Buy, -1 );
Sell = Ref( Sell, -1 );
BuyPrice = SellPrice = Open;

Thank you for the solution, I guess I am still one step from the correct output.

I tried to combine the futures symbol and the stock symbol into the watchlist (list0). So when I call the Name() function I put down the symbol name of the futures but it seems that the code could not read the symbol name because the output did not trigger the futures mode. Do you know where I did wrong if possible? Thanks.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.