Hello,
I'm also looking for a multiportfolio-system to backtest two completely different systems in one portfolio with one equity curve.
In the code below is a system from the forum, I think it could fit for my requirements. My problem is that there comes the error "insufficient funds...". I know this error, but I can't find out why in this code. The size is 10 % or 20 % and there is enough equity.
If I activate the code line "size = 10" or "buy = 1" after the multiplex the system buys and sells stocks but then the requirement two systems with different parameters is not considered (attachment)

Can someone give me a hint how to make work the code ?
Thanks for every help
function multiplex(Buy1, Sell1, BuyPrice1, SellPrice1,size1,PositionScore1,
Buy2, Sell2, BuyPrice2, SellPrice2, size2, PositionScore2)
{
global Buy, Sell, PositionScore, size;
Buy = Sell = False;
PositionScore = 0;
size = 0;
BuyPrice =SellPrice = Null;
sys = 0;
for(i = 0; i < BarCount; i++)
{
switch(sys)
{
case 0:
if(Buy1[i] && Buy2[i])
{
if(PositionScore1[i] >= PositionScore2[i])
{
sys = 1;
size[i] = size1[i];
BuyPrice[i] = BuyPrice1[i];
PositionScore[i] = PositionScore1[i];
Buy[i] = buy1[i];
}
else
{
sys = 2;
size[i] = size2[i];
BuyPrice[i] = BuyPrice2[i];
PositionScore[i] = PositionScore2[i];
Buy[i] = Buy2[i];
}
}
else if (Buy1[i])
{
sys = 1;
size[i] = size1[i];
BuyPrice[i] = BuyPrice1[i];
PositionScore[i] = PositionScore1[i];
Buy[i] = Buy1[i];
}
else if (Buy2[i])
{
sys = 2; //both used at the same time;
size[i] = size2[i];
BuyPrice[i] = BuyPrice2[i];
PositionScore[i] = PositionScore2[i];
Buy[i] = Buy2[i];
}
break;
case 1: //system 1 in use
if(Sell1[i])
{
sys = 0;
Sell[i] = Sell1[i];
SellPrice[i] = SellPrice1[i];
}
break;
case 2:
if(Sell2[i])
{
sys = 0;
Sell[i] = Sell2[i];
SellPrice[i] = SellPrice2[i];
}
}
}
return;
}
buy1 = Ref(C,-1) > Ref(MA(C, 30),-1);
Sell1 = Ref(C,-1) < Ref(MA(C, 30),-1);
size1 = 10;
PositionScore1 = 10;
BuyPrice1 = SellPrice1 = C;
r = RSI();
buy2 = Ref(C,-1) > Ref(MA(C, 50),-1);
Sell2 = Ref(C,-1) < Ref(MA(C, 50),-1);
size2 = 20;
BuyPrice2 = SellPrice2 = O;
PositionScore2 = 20;
multiplex(Buy1, Sell1, BuyPrice1, SellPrice1,size1,PositionScore1,
Buy2, Sell2, BuyPrice2, SellPrice2, size2, PositionScore2);
//buy = 1;
//size = 10;
Short = Cover = False;
SetPositionSize(size, spsPercentOfEquity);
SetOption("MaxOpenPositions", 10 ); // 10 and 100 as max pos makes 7 point
SetOption("InitialEquity", IE=100000);
SetOption("AllowPositionShrinking", 0);
SetOption("CommissionMode", 1);
SetOption("CommissionAmount", 0);
SetOption("AllowSameBarExit", False);
SetOption("PriceBoundChecking", True);
SetOption("ActivateStopsImmediately", False);
Filter = Buy OR Sell;
AddColumn(Buy, "Buy", 7.0);
AddColumn(Sell, "sell", 7.0);
AddColumn(size, "size", 7.0);
AddColumn(positionscore, "score", 7.0);