[Portfolio] Pmm Strategy Programing Problem  [SOLVED]

Questions about MultiCharts and user contributed studies.
pablo gonzalez vidal
Posts: 36
Joined: 25 Aug 2007
Has thanked: 6 times
Been thanked: 1 time

[Portfolio] Pmm Strategy Programing Problem  [SOLVED]

Postby pablo gonzalez vidal » 08 Feb 2018

Hello,


I am trying to program a PMM Strategy where the entry of orders by symbol is limited regardless of the number of strategies that there are on that symbol. For example, if there is already a long strategy in gold that another strategy on gold can not enter long.

This is the way that has occurred to me but something is wrong:

Captura.JPG
(13.97 KiB) Downloaded 511 times

variables: inLong(0), inShort(0);
arrays: strategiesLong[](-1), strategiesShort[](-1);
inLong = pmms_strategies_in_long_count(strategiesLong);
inShort = pmms_strategies_in_short_count(strategiesShort);



for idx = 0 to portfoliostrategies - 1
begin
simbolo1=pmms_strategy_symbol(idx);
simbolo[idx]=simbolo1;
end;



for idx = 0 to portfoliostrategies - 1
begin
value1=array_compare(simbolo,idx,simbolo,idx+1,portfoliostrategies);
if value1=0 then
begin
if inlong=0 then
begin
pmms_strategy_allow_long_entries(idx);
pmms_strategy_set_entry_contracts(idx,con[idx]);
end
else
pmms_strategy_deny_long_entries(idx);

end
else
pmms_strategy_allow_entries(idx);
end;




Can somebody tell me what fails?? Thanks!

Zheka
Posts: 223
Joined: 13 Jan 2016
Has thanked: 8 times
Been thanked: 53 times

Re: Pmm Strategy Programing Problem

Postby Zheka » 09 Feb 2018

value1=array_compare(simbolo,idx,simbolo,idx+1,portfoliostrategies);
You are trying to compare n=portfoliostrategies elements starting from an (increasing) element idx+1 - in an array that has a max number of portfoliostrategies elements.

Try value1=array_compare(simbolo,idx,simbolo,idx+1,portfoliostrategies-idx-1);

This should fix this programming error, but I am not sure your logic is right.

pablo gonzalez vidal
Posts: 36
Joined: 25 Aug 2007
Has thanked: 6 times
Been thanked: 1 time

Re: Pmm Strategy Programing Problem

Postby pablo gonzalez vidal » 09 Feb 2018

Thank you very much


Effectively, correct the error but as you say the logic is not right.


I miss a function that tells me the strategies position by symbol. That would make everything easier.

Regards

Zheka
Posts: 223
Joined: 13 Jan 2016
Has thanked: 8 times
Been thanked: 53 times

Re: Pmm Strategy Programing Problem

Postby Zheka » 09 Feb 2018

One way would be to split one portfolio strategy applied on N symbols into separate N strategies. You can easily do this by setting up one, and then "cloning" (right-click -menu).

But in general be aware that when you "deny entry" at the portfolio level then this entry is 'skipped' also in the strategy itself.
So if your strategy logic assumes reversals - you will have problems.

Another way is to communicate positions to the portfolio signal via pmm_set(get)_strategy_named_num/str..


Return to “MultiCharts”