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.
SetStopLoss [SOLVED]
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: SetStopLoss
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.
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);
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: SetStopLoss
You have to "freeze" the high and low values for your stop calculation.
eg:
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);
Re: SetStopLoss
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.
And no need to reset the var back to 0 as each new entry automatically updates it, correct?
Thanks.
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: SetStopLoss [SOLVED]
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.
Good trading to you.