Stop ATR
-
Hello fxDreema. How do I implement the Stop ATR in my EA? I believe that the mathematical formula is simple, like this:
Market price - ATR * "x"
Example.
EURUSD this now quoted at 1.11650
14 period ATR is currently 0.0015
x is the multiplier want it to be 2.1.11650 - (0.0015 * 2) =
SL is 1.11350.I believe it's correct the formula. So how to implement a project?
Could you do me a sample project? -
Maybe something like this - http://prntscr.com/aj119m
http://i.imgur.com/52Mrpgr.pngCandle Close is Bid, but when working with indicators I prefer to use Candle Close.
-
Interesting fxDreema. He worked for me here. Thank you.
Now I wonder how can I leave the Stop ATR as a Donchian channel, for example?
See the picture:
https://c.mql5.com/18/21/nrtr_atr_stop_1.gif -
Now you want to make indicators
Unfortunately fxDreema works only for EAs and Scripts. -
No no ... I do not want to indicator. Only the ATR Stop function this way. The Stop ATR fixed line, such as a Donchian channel, for example. This indicator is above a Stop ATR, but do not want to display. It would be something to "Adjusting the result?"
I tried to "Market Properties" using the Highest point (candle period) in block 20 Formula, and was almost what I need. But the values were higher than necessary. I tried vise-versa for block 25.
https://fxdreema.com/shared/5FgqrGOue -
Of course you can do calculations, as many as you want. The problem is that if you use "Formula", this means 1 block for 1 calculation, which is kinda stupid. But there are other ways to calculate things as well. In these examples you can see them - https://fxdreema.com/examples/#Constants-and-Variables Also, there is a block "Custom MQL4 code".
When you use "Formula" blocks, make sure that each calculation follows the previous one. I don't know why people prefer to connect many "Formula" blocks in parallel. It looks beautiful, but it's much better to connect multiple "Formula" blocks one after another, because calculations must be done in order. Don't rely on block numbers very much. Look at your block numbers - 25, 26, 16 - which one of these block will run first? Do you know and do you care? 16 runs first and you should care. Trace runs before Formula blocks.
If you have issues with values... well, you should know them before going to work with them. ATR gives you values like 0.00010. Ask/Bid are values like 1.23456. Sometimes values must be converted.
So, this is what I see - http://prntscr.com/akf0a0
If ATR is let's say 0.0007, this is 7 pips. In Formula blocks you double that value and put it in both sides of the current price. Something like +/- 0.0014 (or 14 pips). This is pretty much what I see - http://prntscr.com/akf1kb (127 = 12.7 pips). -
It is .. maybe there is no need to use the formula block.
Actually, the blocks 15 and 16 are only for visualization not important.
Interesting pips of viewing the image above.
I think it would be interesting in the Trace block put beyond color lines, but types of lines, thickness, etc., as we do in external imput of any indicator, for example.
In the case of this project, as you can see, the StopATRU and StopATRL lines are oscillating.
How do I let them straighter, as a Donchian channel for example? That's what I need.
-
Again, the Trace block is only for testing purposes, it's not designed to be used to indicate something. Trace is NOT an indicator. Trace shows you the history of a value, including values such as EMPTY_VALUE or -EMPTY_VALUE.
These lines are oscillating because the values you prot are oscillating. These lines are Ask and Bid prices shifted above and below. These are not Highest or Lowest prices of something, which is the case in Donchain Channel.
-
Yes I know. You can hide the ATR indicator Tester Visualization?

-
So ... I found the formula Stop ATR I believe it will work:
StopLoss = Low[0] - 2 * ATR(5, Close[1]-2ATR(5), and High[0] - 3ATR(5)
https://www.instaforex.com/pt/forex_ind ... r_stop.php -
Hello fxDreema. Well ... if you can not hide the indicator, I have to do with the blocks, and to think better.
But first my idea is to calculate the ATR in a block formula, for example, without using the ATR indicator.Recalling that: If you can hide the window, we do not do all this work.
The true range is the largest of the:
Most recent period's high minus the most recent period's low
Absolute value of the most recent period's high minus the previous close
Absolute value of the most recent period's low minus the previous closeFormula: TR:
https://upload.wikimedia.org/math/1/6/1/161bbb13f7109a0ae8f4618a8708a474.pngThe ATR at the moment of time t is calculated using the following formula: (This is one form of an exponential moving average):
https://upload.wikimedia.org/math/8/b/8/8b849a07cc6fa12d28d73a1d0db00548.pngMore information about the formula, can be found here: https://en.wikipedia.org/wiki/Average_true_range
-
There is no function ATR in MQL4. There is iATR(), but it has some more inputs - https://docs.mql4.com/indicators/iatr
I never tested that, but I think this is the answer - https://docs.mql4.com/customind/hidetestindicators
-
Interesting fxDreema! How to put HideTestIndicator in a block? If I get it, forget the previous post and we will hide the indicator!
-
__There is no function ATR in MQL4. There is iATR(), but it has some more inputs - https://docs.mql4.com/indicators/iatr
I never tested that, but I think this is the answer - https://docs.mql4.com/customind/hidetestindicators[/quote:3atq74ol]
Well ... I tried and it seems that it worked in MT4.
https://fxdreema.com/shared/h31iU00gdNow I can not hide in MT5.
https://fxdreema.com/shared/sd1jjRFQI researched this function in MT5, and unfortunately has not. So ... in this case ... how to hide in the MT5 platform?
https://www.mql5.com/pt/articles/81Robots sold in MQL5 do not show their indicators
-
Hello fxDreema. I tried 3 ways, but without success.
https://fxdreema.com/shared/6iglX9bbbSee the link for possible solutions here:
https://www.mql5.com/en/docs/runtime/te ... torreleasehttps://www.mql5.com/en/forum/11193
https://www.mql5.com/en/forum/9184 -
Just do that http://prntscr.com/ancxsk
http://i.imgur.com/TkQW68r.png -
Yes ... I did that and it worked in MT4, but I need also to MT5 , as mentioned in the post above .
-
It looks that there is no such function in MQL5. There is one IndicatorRelease(), but it does something else and is called at the end. What people suggest (https://www.mql5.com/en/forum/9184) is to detect Visual Mode and prevent the EA from working in this case. I think that indicators appear only in Visual Mode.
-
So ... that way it worked! Thanks!
But look at it this way: https://www.mql5.com/en/docs/runtime/te ... torrelease
Hide the indicator?To prohibit the showing of the indicator on the chart after testing, call the IndicatorRelease() with the handle of the indicator in the handler OnDeinit(). The OnDeinit() function is always called after the completion and before the showing of the testing chart.
//+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- bool hidden=IndicatorRelease(handle_ind); if(hidden) Print("IndicatorRelease() successfully completed"); else Print("IndicatorRelease() returned false. Error code ",GetLastError()); }In order to prohibit the showing of the indicator on the chart, after the completion of a single test, use the function IndicatorRelease() in the handler OnDeinit().
IndicatorRelease() https://www.mql5.com/en/docs/series/indicatorrelease
OnDeinit() https://www.mql5.com/en/docs/runtime/event_fire#deinit