here is for SPY. Instead of contract I use percentOfEquity. Did a quick test, seems OK but no guarantees. So system21 buys 50% of equity, system22 30% and sysmtem23 20%.
If you want to see all details of the backtest you have to set the report settings to detailed log.
// BACKTESTER SETTINGS
SetTradeDelays( 0, 0, 0, 0 );
SetOption("InitialEquity",100000);
SetOption( "PriceBoundChecking", False );
SetOption( "CommissionMode", 3 );
SetOption( "CommissionAmount", 0.005 );
RoundLotSize = 1;
TickSize = 0.01;
MarginDeposit = 5000;
PointValue = 1;
BuyPrice = SellPrice = Close;
Buy = Sell = 0;
PercentOfEquity21 = 50;
PercentOfEquity22 = 30;
PercentOfEquity23 = 20;
Buy21 = Cross( MA( C, 50 ), MA( C, 200 ) );
Buy22 = Cross( MA( C, 20 ), MA( C, 50 ) );
Buy23 = Cross( MA( C, 10 ), MA( C, 20 ) );
Sell21 = Cross( MA( C, 200 ), MA( C, 50 ) );
Sell22 = Cross( MA( C, 50 ), MA( C, 20 ) );
Sell23 = Cross( MA( C, 20 ), MA( C, 10 ) );
// combining the systems
Buy21 = ExRem( Buy21, Sell21 );
Sell21 = ExRem( Sell21, Buy21 );
Buy22 = ExRem( Buy22, Sell22 );
Sell22 = ExRem( Sell22, Buy22 );
Buy23 = ExRem( Buy23, Sell23 );
Sell23 = ExRem( Sell23, Buy23 );
inBuy21 = Nz( Flip( Buy21, Sell21 ) );
inBuy22 = Nz( Flip( Buy22, Sell22 ) );
inBuy23 = Nz( Flip( Buy23, Sell23 ) );
totalPositions = IIf( inBuy21, 1, 0 ) * PercentOfEquity21 +
IIf( inBuy22, 1, 0 ) * PercentOfEquity22 +
IIf( inBuy23, 1, 0 ) * PercentOfEquity23;
actionAtBar = totalPositions - Ref( totalPositions, -1 );
Buy = IIf( actionAtBar >= 1 AND totalPositions >= 1 AND Ref( totalPositions, -1 ) == 0, 1, 0 );
Buy = IIf( actionAtBar >= 1 AND totalPositions >= 1 AND Ref( totalPositions, -1 ) >= 1, sigScaleIn, Buy );
Buy = IIf( actionAtBar <= -1 AND totalPositions >= 1, sigScaleOut, Buy );
Sell = IIf( actionAtBar <= -1 AND totalPositions == 0, 1, 0 );
// remove excess signals at start (this is just for display purposes)
Sell21 = IIf( Sell21 AND !( Buy OR Sell ), 0, Sell21 );
Sell22 = IIf( Sell22 AND !( Buy OR Sell ), 0, Sell22 );
Sell23 = IIf( Sell23 AND !( Buy OR Sell ), 0, Sell23 );
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );
Plot( MA( C, 10 ), "Ma10", colorYellow, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
Plot( MA( C, 20 ), "Ma20", colorViolet, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
Plot( MA( C, 50 ), "Ma50", colorPaleTurquoise, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
Plot( MA( C, 200 ), "Ma200", colorBlue, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
Plot( totalPositions, "total positions", colorGold, styleLine | styleOwnScale | styleStaircase, Null, Null, 0, 0, 1 );
Title =
"actionAtBar: " + actionAtBar +
EncodeColor( colorGold ) + "\n totalPositions (PercentOfEquity): " + totalPositions + EncodeColor( colorWhite ) +
"\n Ref( totalPositions, -1 ): " + Ref( totalPositions, -1 ) +
"\n Buy: " + Buy +
"\n Sell: " + Sell +
"\n Buy21: " + Buy21 +
"\n Buy22: " + Buy22 +
"\n Buy23: " + Buy23 +
"\n Sell21: " + Sell21 +
"\n Sell22: " + Sell22 +
"\n Sell23: " + Sell23;
PlotShapes( IIf( Buy == 1, shapeUpArrow, shapeNone ), colorDarkGreen, 0, L, -20 );
PlotShapes( IIf( Buy == 1, shapeSmallCircle, shapeNone ), colorWhite, 0, BuyPrice, 0 );
PlotShapes( IIf( Buy == sigScaleIn, shapeUpArrow, shapeNone ), colorBrightGreen, 0, L, -20 );
PlotShapes( IIf( Buy == sigScaleIn, shapeSmallCircle, shapeNone ), colorWhite, 0, BuyPrice, 0 );
PlotShapes( IIf( Buy == sigScaleOut, shapeDownArrow, shapeNone ), colorGold, 0, H, -20 );
PlotShapes( IIf( Buy == sigScaleOut, shapeSmallCircle, shapeNone ), colorWhite, 0, BuyPrice, 0 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, -20 );
PlotShapes( IIf( Sell, shapeSmallCircle, shapeNone ), colorWhite, 0, SellPrice, 0 );
PlotShapes( IIf( Buy21, shapeUpTriangle, shapeNone ), colorBrightGreen, 0, L, -40 );
PlotShapes( IIf( Sell21, shapeDownTriangle, shapeNone ), colorBrightGreen, 0, H, -40 );
PlotShapes( IIf( Buy22, shapeUpTriangle, shapeNone ), colorYellow, 0, L, -40 );
PlotShapes( IIf( Sell22, shapeDownTriangle, shapeNone ), colorYellow, 0, H, -40 );
PlotShapes( IIf( Buy23, shapeUpTriangle, shapeNone ), colorAqua, 0, L, -40 );
PlotShapes( IIf( Sell23, shapeDownTriangle, shapeNone ), colorAqua, 0, H, -40 );
SetPositionSize( abs( actionAtBar ), IIf( Buy OR Sell, spsPercentOfEquity, spsNoChange ) );