Limit max number of open positions in different strategy.

Questions about MultiCharts and user contributed studies.
stefano84
Posts: 6
Joined: 31 Aug 2015
Has thanked: 2 times

Limit max number of open positions in different strategy.

Postby stefano84 » 29 Nov 2015

TOPIC
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;
MONEY MANAGEMENT SIGNAL:

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 wish I could use even more of one strategy in portfolio trader but I have seen that is not working.

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);
in other signals but skip operations, the performance report is wrong.

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?

Return to “MultiCharts”