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;
Portfolio Trader Question
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Portfolio Trader Question
Hello quantarb,
pmms_strategy_currentcontracts - Returns a numerical value representing number of contracts of the position opened by strategy with StrategyIndex number.
pmms_strategy_currentcontracts - Returns a numerical value representing number of contracts of the position opened by strategy with StrategyIndex number.
Re: Portfolio Trader Question
Thanks for your suggestion, Henry. However, I don't see one for pmms_strategy_currententries.Hello quantarb,
pmms_strategy_currentcontracts - Returns a numerical value representing number of contracts of the position opened by strategy with StrategyIndex number.
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);
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Portfolio Trader Question
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);