Is Code for Builtin Strategy 'Portfolio_SpreadingTradingSystem.Slave' Correct?

Questions about MultiCharts and user contributed studies.
Transatlantic
Posts: 3
Joined: 15 Feb 2021

Is Code for Builtin Strategy 'Portfolio_SpreadingTradingSystem.Slave' Correct?

Postby Transatlantic » 28 Feb 2021

Hi,

I am unable to confirm that the code for Portfolio_SpreadTradingSystem.Slave runs correctly. Can anyone confirm it does?

Specifically, I am not clear on Lines 25 and Line 30, which effectively seem to be the same as Line 12:

Line 12:

if sign(my_mp) <> sign(master_mp) then begin

Line 25:

if Sign(master_mp) <> Sign(my_mp) then // master in long, we are in short/flat

Line 30:

if Sign(master_mp) <> Sign(my_mp) then // master in short, we are in long/flat


Unless my eyes are deceiving me, all three statements are logically the same. I do not see how any of the 3 can evaluate differently than the other two as 'master_mp' and 'my_mp' are only assigned before these three statements.

Can anyone please help me understand what is going on?

Thanks.

-Transatlantic

Full code:

Code: Select all

var: master_mp(0), my_mp(0); value1 = pmms_from_portfolio_currency( pmm_get_my_named_num("MPMoney") ); // master's position cost. convert it to my contracts value33 = c; if marketposition <> 0 then value33 = entryprice; master_mp = IntPortion( value1 / ( value33 * bigpointvalue) ); my_mp = currentcontracts*marketposition; if sign(my_mp) <> sign(master_mp) then begin if 0 = value1 then begin // need close position if my_mp > 0 then sell all contracts this bar c else buytocover all contracts this bar c; #return; end; value2 = master_mp - my_mp; if 0 < value2 then begin // we must to buy if Sign(master_mp) <> Sign(my_mp) then // master in long, we are in short/flat buy absvalue(master_mp) contracts this bar c else buytocover value1 contracts this bar c; end else begin // we must sell if Sign(master_mp) <> Sign(my_mp) then // master in short, we are in long/flat sell short absvalue(master_mp) contracts this bar c else sell absvalue(value2) contracts this bar c; end; end;
Last edited by Transatlantic on 28 Feb 2021, edited 2 times in total.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Is Code for Builtin Strategy 'Portfolio_SpreadingTradingSystem.Slave' Correct?

Postby TJ » 28 Feb 2021

See post #1 & post #2
viewtopic.php?t=11713

Transatlantic
Posts: 3
Joined: 15 Feb 2021

Re: Is Code for Builtin Strategy 'Portfolio_SpreadingTradingSystem.Slave' Correct?

Postby Transatlantic » 28 Feb 2021

OP modified per post above. Added code in code box.


Return to “MultiCharts”