whroeder1:
Why would you want variable length ATR, and length being a function of the hour it opened. A zero length ATR (bogus) if the order was opened at midnight, or a 12 bar ATR if it was opened at noon.
If the order was opened at midnight (00:00) then Why would you want variable length ATR, and length being a function of the hour it opened. A zero length ATR (bogus) if the order was opened at midnight, or a 12 bar ATR if it was opened at noon.
if(difference == 0) realcandle = 8; //if the time of now is 00:00 then atr is 8. else realcandle is diff
the reason I want a dynamic atr is that I had already been asked to code this for mql4 and I am trying to slowly port many of my codes to mql5
still even when realcandle is 8 the atr will return 0
That isn't the code you posted.
whroeder1:
That isn't the code you posted.
I think i am lost in this . I did post two pieces of code first one from mql4 that work perfectly and the other one (larger) from mql5 which works until the point were the returned value is always 0. Therefore priceopen + 0 = Invalid stop
That isn't the code you posted.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello everyone and thanks in advance.
My problem is the following, in MQL4 I can use the following code:
Once I have the atr value i then (if buying substract it to the open price to determine my stop or if selling sum it) and everything works well.
But in MQL5 I can't seem to get the same result. I have tried using the same approach shown in https://www.mql5.com/en/articles/4318 and the 'original' indicator handling mode of the language but everytime i get that atr is 0 and therefore get invalid stoploss error. The only thing that I managed to do was to create the 24 atrs handlers in the OnInit() function but I know this is not only memory consuming but when I backtest my idea I have 24 indicators + other one I use to determine entries drown in my chart.
I would really be thankful if anyone could point me in the right direction as I have the intention and the conviction that I can learn how to solve this problem.
Here is the attempt I did with the article style: