SetStopLoss  [SOLVED]

Questions about MultiCharts and user contributed studies.
Eric1704
Posts: 21
Joined: 29 Nov 2022
Has thanked: 9 times

SetStopLoss

Postby Eric1704 » 09 Dec 2023

I was trying SetStopLoss with a 2 bar low and saw it updated on every bar. Is there a way to keep SetStopLoss in same place after entry? I use it since it places the protective stop immediately after entry.
Thanks.

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

Re: SetStopLoss

Postby TJ » 10 Dec 2023

This is a coding question. You need to post your codes.

Eric1704
Posts: 21
Joined: 29 Nov 2022
Has thanked: 9 times

Re: SetStopLoss

Postby Eric1704 » 10 Dec 2023

Thanks TJ. I have enclosed the code below. I see on every bar update it recalculates the stop. I do not want that happening once we enter trade and place initial stop. Is there a way in Multi Charts to keep initial protective stop static? I use SetStop and SetTarget as they place stops and targets immediately after a position is opened.
Thanks.

Code: Select all

Inputs: NMM1 (3), PSParam (1.00), RoundPS (true), RoundTo (1), MinSize (1), SizeLimit (100); Var: EntCondL (false), EntCondS (false); Var: NShares (0); EntCondL = C > O; EntCondS = false; NShares = PSParam; If RoundPS and RoundTo > 0 then NShares = IntPortion(NShares/RoundTo) * RoundTo; NShares = MaxList(NShares, MinSize); NShares = MinList(NShares, SizeLimit); If MarketPosition = 0 and EntCondL then begin Buy("EnMark-L") NShares shares next bar at market; end; If MarketPosition = 0 and EntCondS and EntCondL = false then begin Sell short("EnMark-S") NShares shares next bar at market; end; SetStopShare; SetStopLoss((High - Lowest(L, NMM1)) * BigPointValue);

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

Re: SetStopLoss

Postby TJ » 10 Dec 2023

You have to "freeze" the high and low values for your stop calculation.

eg:

Code: Select all

var: mm.h(0) , mm.L(0); If MarketPosition = 0 and EntCondS and EntCondL = false then begin Sell short("EnMark-S") NShares shares next bar at market; mm.h = h; mm.L = Lowest(L, NMM1); end; SetStopShare; SetStopLoss(( mm.h - mm.L )) * BigPointValue);

Eric1704
Posts: 21
Joined: 29 Nov 2022
Has thanked: 9 times

Re: SetStopLoss

Postby Eric1704 » 11 Dec 2023

Thanks TJ. And I guess same would apply to a calculated profit target?
And no need to reset the var back to 0 as each new entry automatically updates it, correct?
Thanks.

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

Re: SetStopLoss  [SOLVED]

Postby TJ » 11 Dec 2023

What I have provided is an example . . . you can take it from there and add whatever is needed. It will take a few trial and error to iron out the bugs.

Good trading to you.


Return to “MultiCharts”