I want to to create a trailing stoploss and draw a dot on the chart to track the changes.
The dot tracker works but it moves in both directions I only want it to move up with a buy position and down with a sell position.
Also the stoploss itself doesn't modify.
I'm sure there's a simple solution but for the life of me I can't see it!
Could someone show me where I should be looking please?
Any help would be greatly appreciated
Your function which calculates ATR returns its value in points.
To change the position SL you need to pass it a PRICE, so there is some calculation missing on your code.
You have to get que received ATR values, multiply it to the corresponding value on the Symbol Digits.
After that, you have to get the position OpenPrice, and add/subtract the corresponding value to it.
And then you can update the position SL.
Example: if ATR returns 230, convert to the corresponding digits:
atr = atr * _Point
Considering it is EURUSD, the value will be 0.00230, which means 230 points.
Than get the Opening Price, example: 1.18557 and subtract from it: (1.18557 - 0.00230) which will result in 1.18327
The value which you will pass to update de position SL will be 1.18327
By giving a quick look at your code, it looks like you are mixing/comparing price with points.
Check/print/debug the final SL value which you are passing to update, and verify if it is really a compatible PRICE, or if it is being passed as an out-of-range value (as I suppose is happening)
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want to to create a trailing stoploss and draw a dot on the chart to track the changes.
The dot tracker works but it moves in both directions I only want it to move up with a buy position and down with a sell position.
Also the stoploss itself doesn't modify.
I'm sure there's a simple solution but for the life of me I can't see it!
Could someone show me where I should be looking please?
Any help would be greatly appreciated