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.
Keeping SetStopLoss Static.
- ABC
- Posts: 723
- Joined: 16 Dec 2006
- Location: www.abctradinggroup.com
- Has thanked: 125 times
- Been thanked: 410 times
- Contact:
Re: Keeping SetStopLoss Static.
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
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
Re: Keeping SetStopLoss Static.
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?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.
- ABC
- Posts: 723
- Joined: 16 Dec 2006
- Location: www.abctradinggroup.com
- Has thanked: 125 times
- Been thanked: 410 times
- Contact:
Re: Keeping SetStopLoss Static.
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
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
Re: Keeping SetStopLoss Static.
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 ) ;
-
- Posts: 47
- Joined: 03 Jan 2023
- Been thanked: 3 times
Re: Keeping SetStopLoss Static.
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
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