Hello everybody,
I often have the problem that the explore mode provides different results than the backtest mode, here is an example:
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);
It is essentially a code sample for multiportfolios from the forum. The explore mode delivers a lot of buy signals for different stocks:
The backtest does not execute any orders. There is a message "not entered because of insufficient funds or wrong position size / value". According to explore mode, however, the capital employed is large enough (10% or 20% of 100,000).
Does anyone have an idea why the backtest does not do anything?
Thank you for every hint.
Frank