Backtesting limit maximum number of open positions in different strategy (Portfolio trader).
I found this code in the forum and have seen that works well when run on one strategy that has many symbol.
SIGNAL:
Code: Select all
inputs:ptf(true);
IF (marketposition = 0 and dayofweek(date)=1) then BEGIN
if (ptf = true) then pmm_set_my_named_num("Entry",1);
Buy next bar at open ;
END;
IF (Marketposition<>0 and dayofweek(date)=5) then begin
if (ptf = true) then pmm_set_my_named_num("Exit",1);
Sell ("EOW-L") next bar at open;
end;
Code: Select all
var:idx(0),count(0),maxopenposition(10),countin(0),countout(0),countMP(0),SLOT(0);
array:strategyIndexes[](0);
pmms_strategies_deny_entries_all;
countin = 0;
countout = 0;
COUNTMP = 0;
slot=0;
for idx = 0 to pmms_strategies_count -1 begin
countin = countin + pmms_get_strategy_named_num(idx,"Entry");
countout = countout + pmms_get_strategy_named_num(idx,"Exit");
IF pmms_strategy_marketposition(idx) <> 0 THEN begin
countMP = countMP+1;
end;
end;
SLOT = COUNTMP - countout;
for idx = 0 to pmms_strategies_count -1 begin
if ( pmms_get_strategy_named_num(idx,"Entry") = 1 and SLOT < maxopenposition) then begin
SLOT =SLOT +1;
pmms_strategy_allow_entries(idx);
end;
end;
for idx = 0 to pmms_strategies_count -1 begin
pmms_set_strategy_named_num(idx,"Entry",0);
pmms_set_strategy_named_num(idx,"Exit",0);
END;
if pmms_strategies_in_positions_count(strategyIndexes)> maxopenposition then
print("error ",pmms_strategies_in_positions_count(strategyIndexes));
I have added
Code: Select all
if (ptf = true) then pmm_set_my_named_num("Entry",1);
Code: Select all
if (ptf = true) then pmm_set_my_named_num("Exit",1);
I would like to make a backtesting of 20 trading system but allow the opening maximum of 10 entry simultaneously.
The code should MM blocking entry if there are already 10 operations open.
Can you help me?