Portfolio Trader Question

Questions about MultiCharts and user contributed studies.
quantarb
Posts: 51
Joined: 14 Apr 2012
Has thanked: 9 times
Been thanked: 33 times

Portfolio Trader Question

Postby quantarb » 09 Oct 2014

I'm trying to create a modified version of portfolio_currententries.


Ex. I want to calculate the number of instruments that have at least two open positions.
SPY has 3 open positions, XRT has two open positions, GDX has two open positions, XME has one position, and QQQ has one position.

The function should return a value of 3.

Is there a way for me to do something along the lines

foreach(instrument in portfolio)

if currententries >= 3 then
begin
portfolio_currententries3 ++;
end;

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Portfolio Trader Question

Postby Henry MultiСharts » 09 Oct 2014

Hello quantarb,

pmms_strategy_currentcontracts - Returns a numerical value representing number of contracts of the position opened by strategy with StrategyIndex number.

quantarb
Posts: 51
Joined: 14 Apr 2012
Has thanked: 9 times
Been thanked: 33 times

Re: Portfolio Trader Question

Postby quantarb » 09 Oct 2014

Hello quantarb,

pmms_strategy_currentcontracts - Returns a numerical value representing number of contracts of the position opened by strategy with StrategyIndex number.
Thanks for your suggestion, Henry. However, I don't see one for pmms_strategy_currententries.

I follow the code example on the wiki help, and was able to get the code to successfully complied. Unfortunately, portfolio trader crashes when I try to run the code. The error is "Array bounds. Wong index: 1".

Code: Select all

variables: idx(0), strategyIdx(0), strategyValue(0), formulaValue(0);
Array: allStrategies[](0);

if CurrentEntries >= 3 then
begin
formulaValue = 1;
end else
begin
formulaValue = 0;
end;

pmm_set_my_named_num ("CurrentEntries", formulaValue);

for strategyIdx = 0 to pmms_strategies_count - 1
begin
strategyValue = pmms_get_strategy_named_num(strategyIdx, "CurrentEntries");
allStrategies[strategyIdx] = strategyValue;
end;

value1 = Array_Sum(allStrategies,0,pmms_strategies_count - 1);



User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Portfolio Trader Question

Postby Henry MultiСharts » 10 Oct 2014

This alert appeared because the size for the dynamical array (allStrategies) was not set. Please find the proper code below:

Code: Select all

Array: allStrategies[](0);

if CurrentEntries >= 3 then
begin
formulaValue = 1;
end else
begin
formulaValue = 0;
end;

pmm_set_my_named_num ("CurrentEntries", formulaValue);

//Sets array size:
array_setmaxindex(allStrategies, pmms_strategies_count);

for strategyIdx = 0 to pmms_strategies_count - 1
begin
strategyValue = pmms_get_strategy_named_num(strategyIdx, "CurrentEntries");
allStrategies[strategyIdx] = strategyValue;
end;

value1 = Array_Sum(allStrategies,0,pmms_strategies_count - 1);


Return to “MultiCharts”