Adding money management to my script

Questions about MultiCharts and user contributed studies.
Giulia_1999
Posts: 1
Joined: 25 Jan 2024

Adding money management to my script

Postby Giulia_1999 » 25 Jan 2024

Hi all, I am trying to code a money management system into my script: I would like it to increase my cash position and my stoploss according to the % net profit I get.
e.g. starting capital goes +25%: cash position increases by 25% and stop loss too. starting capital resets to the new value, and so on as a loop.
I want to be able to optimize the % increase. I am no genius at coding, I can only code very basic stuff so I tried doing something but I think I am pretty far off, I send below my results.
In this example my starting capital is 25,000 usd. Thanks in advance

"inputs: price(close), slowsma(40), fastsma(20), sl(150);
VARS: AMOUNT(0); EQUITY; INCREASEEQUITY(0); INCREASESTOPLOSS(0), X(0,25)
EQUITY=INITIALCAPITAL+NETPROFIT;
AMOUNT= EQUITY/CLOSE
INCREASEEQUITY= EQUITY*X;
INCREASESTOPLOSS=SL*X;

condition5= price>XAverage(close,slowsma) and XAverage(close,fastsma)>XAverage(close,slowsma);
condition6= XAverage(close,fastsma)<XAverage(close,slowsma);


if condition5 And marketposition=0 then begin
buy AMOUNT SHARES next bar at market;
end;

if condition6 and marketposition>0 then begin
sell next bar at market;
end;

setstoploss(sl);

IF EQUITY>=EQUITY+INCREASEEQUITY THEN BEGIN
SL= SL+INCREASESTOPLOSS;
END;"

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

Re: Adding money management to my script

Postby TJ » 25 Jan 2024

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

BD.
Posts: 19
Joined: 02 Feb 2024
Has thanked: 2 times
Been thanked: 2 times

Re: Adding money management to my script

Postby BD. » 02 Feb 2024

if you know how to code basic stuff then all you need to do is open "Dictionary" in your PL editor, it's on the right side of a window (if you have nothing there then go to View -> Navigator Bar) you'll see you can switch between "Studies" and "Dictionary". in the dictionary you'll need "Accounts and Positions" but mostly "Strategy Performance". You can find what each of the keywords does right there at the bottom if you click on any of them.

You can pull all the information you need from there.


Return to “MultiCharts”