Keeping SetStopLoss Static.

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

Keeping SetStopLoss Static.

Postby Eric1704 » 05 Mar 2023

Hi. I use SetStopLoss to be able to set a stop right away on entry. I set it to like lowest or highest of last X bars. I have noticed it updates on each new bar to the highest or lowest new value.

Is there a way to keep it as originally placed right away upon entry and not update on each new bar?

Thanks.

User avatar
ABC
Posts: 721
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 409 times
Contact:

Re: Keeping SetStopLoss Static.

Postby ABC » 06 Mar 2023

Eric1704,

one way could be using a variable to store the amount you use for SetStopLoss and only allow updating this variable when you are not long.
Then you use this variable in SetStopLoss.

Regards,

ABC

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

Re: Keeping SetStopLoss Static.

Postby Eric1704 » 06 Mar 2023

Eric1704,

one way could be using a variable to store the amount you use for SetStopLoss and only allow updating this variable when you are not long.
Then you use this variable in SetStopLoss.

Regards,

ABC
Thanks. Will doing that in the same script be fine? I have seen it update on each bar that I did not want. Any examples?
Thanks.

User avatar
ABC
Posts: 721
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 409 times
Contact:

Re: Keeping SetStopLoss Static.

Postby ABC » 07 Mar 2023

Eric1704,

doing it in the same script should be fine, and the proper solution might depend a bit on your actual entry and exit code.

Regards,

ABC

Tibouss
Posts: 31
Joined: 26 May 2022
Has thanked: 7 times
Been thanked: 1 time

Re: Keeping SetStopLoss Static.

Postby Tibouss » 09 Mar 2023

If it could help.

Code: Select all

inputs: ATRLengthS (5), NumATRsS (5); variables: var1( 0 ); ATRStopLossValue( 0 ); condition3 = marketposition=0 and .... ; if condition3 then Buy ( "BBStochLE" ) next bar at market ; condition4 = marketposition=0 and ..... ; if condition4 then sellshort ( "BBStochDLX" ) next bar at market ; condition5 = marketposition=1 and ..... ; if condition5 then sell( "BBStochSE" ) next bar at market ; condition6 = marketposition=-1 and ..... ; if condition6 then buytocover ( "BBStochSX" ) next bar at market ; if condition3 or condition4 or condition5 or condition6 then ATRStopLossValue = AvgTrueRange( ATRLengthS ) * NumATRsS ; SetStopLoss( ATRStopLossValue ) ; //Or you could do condition3 = marketposition=0 and .... ; if condition3 then begin Buy ( "BBStochLE" ) next bar at market ; ATRStopLossValue = AvgTrueRange( ATRLengthS ) * NumATRsS ; end; condition4 = marketposition=0 and ..... ; if condition4 then begin sellshort ( "BBStochDLX" ) next bar at market ; ATRStopLossValue = AvgTrueRange( ATRLengthS ) * NumATRsS ; end; condition5 = marketposition=1 and ..... ; if condition5 then begin sell( "BBStochSE" ) next bar at market ; ATRStopLossValue = AvgTrueRange( ATRLengthS ) * NumATRsS ; end; condition6 = marketposition=-1 and ..... ; if condition6 then begin buytocover ( "BBStochSX" ) next bar at market ; ATRStopLossValue = AvgTrueRange( ATRLengthS ) * NumATRsS ; end; SetStopLoss( ATRStopLossValue ) ;

ScottishSpeculator
Posts: 47
Joined: 03 Jan 2023
Been thanked: 3 times

Re: Keeping SetStopLoss Static.

Postby ScottishSpeculator » 18 Mar 2023

Tobouss /Eric

I think setstoploss takes a dollar amount in () for total position as defaut.

I know ATR is like dollar value but I think you need to state

SetStopShare;
SetStopLoss( ATRStopLossValue ) ;

Also if your interested I am trying to set up a telegram group/ maybe discord in which people new to MC can share strategy code or come together to upvote ideas and get them build by professional for super cheap per person. See below seems you new and could be interested.

https://t.me/+h8iTLItDWGAxNGY0


Return to “MultiCharts”