Need help with custom exponential moving average on array - page 2

 
Great work @ami289  🥃 , and thanks (i just realized mt5 does not stop on division by zero
 
AMI289 #:


You did nothing wrong.

You just did something that is useless.


Usually when you create arrays it is because you want to make use of several values.

For example- when calculating MA of price you are not only looking at current price, but you are also looking at previous prices, depends on the period of the MA.

In your code you have created several arrays to hold all of the values you've calculated, but you only used them one time, and then didn't need them anymore.

For example-

You've calculated upper_wick,

And then you used the current calculation of upper_wick for calculating percent_upper_wick,

But then you are done with upper_wick, and don't care anymore about its value.

Then you use percent_upper_wick to calculate buying/selling volume,

But then you are done with percent_upper_wick, and don't care anymore about its value.

So there is no need to save those values forever in arrays.

I see, that was a good explanation. Thank you for that. I was mixing up buffers and arrays. It makes sense to only store it once, as we only need it once. This took away my confusion. 


AMI289 #:

Although Lorentzos Roussos did an awesome job providing his code modifications,

I don't think it will solve your problem.

I've noticed some cases where a candle's high and low were the same (perhaps because no ticks, or bad history data).

Anyway, I've re-written your code in a more clean and efficient way, and added some notes to explain some of the things I've did,

And I've also addressed the issue I've wrote above, that I believe that was the problem you were having.


Enjoy-

I didn't know that that was possible due to no ticks or bad history data. It did not give me any errors. That's definitely something I need to look out for in the future. 


Thanks @AMI289 and @Lorentzos Roussos, for your time, knowledge and patience. You both helped me a ton, and took away doubts. I wish you both a wonderful day. Thank you.