PMMS simple example  [SOLVED]

Questions about MultiCharts and user contributed studies.
Idangy
Posts: 9
Joined: 31 Oct 2022
Has thanked: 3 times
Been thanked: 2 times

PMMS simple example

Postby Idangy » 10 Dec 2022

Hey.
I'm having hard time finding someone who can walk me through the process of understanding PMMS,.

A simple code example would really help me here.

Strategy1
Strategy2

only enable startegy2 if there is an open position in strtegy1 else disable.

i will appreciate if someone please show me how to write that kind of money management signal?
:D :D

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: PMMS simple example

Postby rrams » 11 Dec 2022

Code: Select all

// Portfolio Money Management Signal to pause trading from // second strategy if no open position from first strategy. if pmms_strategies_count<2 then RaiseRunTimeError("Must have at least two strategies."); if pmms_strategy_marketposition(0)<>0 then begin if pmms_strategy_is_paused(1) then begin pmms_strategy_resume(1); print("Resuming second Strategy."); end; end else if pmms_strategy_is_paused(1)=False then begin pmms_strategy_pause(1); print("Pausing second Strategy."); end;

Idangy
Posts: 9
Joined: 31 Oct 2022
Has thanked: 3 times
Been thanked: 2 times

Re: PMMS simple example

Postby Idangy » 12 Dec 2022

Code: Select all

// Portfolio Money Management Signal to pause trading from // second strategy if no open position from first strategy. if pmms_strategies_count<2 then RaiseRunTimeError("Must have at least two strategies."); if pmms_strategy_marketposition(0)<>0 then begin if pmms_strategy_is_paused(1) then begin pmms_strategy_resume(1); print("Resuming second Strategy."); end; end else if pmms_strategy_is_paused(1)=False then begin pmms_strategy_pause(1); print("Pausing second Strategy."); end;

thank you so much!! I really appreciate it!

one questions.

when you refer to strategy 1 " if pmms_strategy_is_paused(1) "

1 is the number of the strategy in the tree?

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: PMMS simple example

Postby rrams » 12 Dec 2022

Idangy,
Yes the functions like pmms_strategy_is_paused(1) take a parameter that are the zero indexed numbered strategies in your portfolio from top to bottom. Zero is strategy one, one is strategy two.
Strategies in your portfolio tree can have multiple signals in each of them. The PMMS functions apply to all the signals in each strategy.

Idangy
Posts: 9
Joined: 31 Oct 2022
Has thanked: 3 times
Been thanked: 2 times

Re: PMMS simple example

Postby Idangy » 14 Dec 2022

Idangy,
Yes the functions like pmms_strategy_is_paused(1) take a parameter that are the zero indexed numbered strategies in your portfolio from top to bottom. Zero is strategy one, one is strategy two.
Strategies in your portfolio tree can have multiple signals in each of them. The PMMS functions apply to all the signals in each strategy.
So i played a bit with the logic as I understand it from the code you wrote :)

now I'm trying to check all strategies and allow only opposite directions entries.
i tested it with a simple signal

if close > open go long
if close < open go short

if applied this to 5 symbols- 1 min

it doesn't work properly /:

any suggestions?

Code: Select all

input: FIRST_INTEX(0), FINAL_INDEX(5); var: positionsLong(0), positionShort(0), bool allow_only_shorts_entries (false), bool allow_only_Long_entries (false), int Counter (0); array: strategyIndexes[](0); counter = 0; positionsLong = pmms_strategies_in_long_count(strategyIndexes); // num of pos in long positionShort= pmms_strategies_in_short_count(strategyIndexes); // num of pos in short /// reset bool vars and resume paused strategies if positionsLong = 0 then begin allow_only_Long_entries = false; pmms_strategies_resume_all; end; if positionShort = 0 then begin allow_only_shorts_entries = false; pmms_strategies_resume_all; end; /// Check for open pos for Counter = FIRST_INTEX to FINAL_INDEX begin if pmms_strategy_marketposition(Counter) > 0 then allow_only_shorts_entries = true; if pmms_strategy_marketposition(Counter) < 0 then allow_only_Long_entries = true; end; /// adjust other positions acording to first position for Counter = FIRST_INTEX to FINAL_INDEX begin if pmms_strategy_marketposition(counter) = 0 then begin if allow_only_shorts_entries and allow_only_Long_entries = false then // if only shorts alowed begin pmms_strategy_allow_short_entries(counter); pmms_strategy_deny_long_entries(counter); if pmms_strategy_is_paused(counter) then pmms_strategy_resume(counter); end else if allow_only_shorts_entries = false and allow_only_Long_entries then // if only longs allowed begin pmms_strategy_deny_short_entries(counter); pmms_strategy_allow_long_entries(counter); if pmms_strategy_is_paused(counter) then pmms_strategy_resume(counter); end; if allow_only_Long_entries and allow_only_shorts_entries then // if both allowed that means two positions open- pause all the rest begin pmms_strategy_deny_short_entries(counter); pmms_strategy_deny_long_entries(counter); pmms_strategy_pause(counter); end; end; end;

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: PMMS simple example

Postby rrams » 14 Dec 2022

Idangy,
Looks like you are making progress.
One thing I noticed; there needs to be separate dynamic arrays declared to hold the short and long positions.

Code: Select all

array: strats_with_longs[](0), strats_with_shorts[](0); positionsLong=pmms_strategies_in_long_count(strats_with_longs); // indexes of strategies with long positions positionShort=pmms_strategies_in_short_count(strats_with_shorts); // indexes of strategies with short positions
Unfortunately, I don't have time to debug all the code. If you have decided to write this yourself, my suggestion is to not try to complete the entire objective at once. Start with a small amount of code and use print statements to verify what is happening in the output window. Otherwise, you will keep getting stuck. You can print out the array contents similiar to this:

Code: Select all

for value1=0 to Array_GetMaxIndex(strategyIndexes) begin print("strat index: ", Array_GetIntegerValue(strategyIndexes, value1):0:0); end;
Be aware that it will slow down the run time, but you need to understand how it works before writing the whole thing.

Idangy
Posts: 9
Joined: 31 Oct 2022
Has thanked: 3 times
Been thanked: 2 times

Re: PMMS simple example  [SOLVED]

Postby Idangy » 15 Dec 2022

Idangy,
Looks like you are making progress.
One thing I noticed; there needs to be separate dynamic arrays declared to hold the short and long positions.

Code: Select all

array: strats_with_longs[](0), strats_with_shorts[](0); positionsLong=pmms_strategies_in_long_count(strats_with_longs); // indexes of strategies with long positions positionShort=pmms_strategies_in_short_count(strats_with_shorts); // indexes of strategies with short positions
Unfortunately, I don't have time to debug all the code. If you have decided to write this yourself, my suggestion is to not try to complete the entire objective at once. Start with a small amount of code and use print statements to verify what is happening in the output window. Otherwise, you will keep getting stuck. You can print out the array contents similiar to this:

Code: Select all

for value1=0 to Array_GetMaxIndex(strategyIndexes) begin print("strat index: ", Array_GetIntegerValue(strategyIndexes, value1):0:0); end;
Be aware that it will slow down the run time, but you need to understand how it works before writing the whole thing.

thank you so much for your help!


Return to “MultiCharts”