Round a Array of indicator values in MQL5

To add comments, please log in or register
patagonia2015
158
patagonia2015  

Hey,


I want to Round the number of an Array of my indicator. I need to Round the numbers to the number of digits of the currency, for example the EURUSD in my broker has 5 digits, while USDJPY have 3 digits.

I cannot do it this way. And I want to change Round the numbers as soon as they are created, that way when I call them later they will be ready.

ArraySetAsSeries (SMAArray, true);
CopyBuffer (SMA_handle, 0, 0, TotalBars+1, SMAArray);
SMAArray[]=MathRound (SMAArray[], _Digits);

I doing this as in the reference manual, don't know why is not working.

https://www.mql5.com/en/docs/standardlibrary/mathematics/stat/mathsubfunctions/statmathround

Thank you!

Documentation on MQL5: Standard Library / Mathematics / Statistics / Subfunctions / MathRound
Documentation on MQL5: Standard Library / Mathematics / Statistics / Subfunctions / MathRound
  • www.mql5.com
Version for rounding an array of double-precision floating-point numbers to the specified number of decimal places. The results are output to a new array. Version for rounding an...
nicholi shen
2394
nicholi shen  
void roundArray(double &arr[], int digits)
{
   for (int i=ArraySize(arr)-1; i>=0; i--)
      arr[i] = NormalizeDouble(arr[i], digits);
}
lippmaje
594
lippmaje  

Does this even compile?

SMAArray[]=MathRound (SMAArray[], _Digits);
patagonia2015
158
patagonia2015  
nicholi shen:

Thank you.

I was thinking if there was another option without using a for.

Maybe is the only option, I will use that way for now.

To add comments, please log in or register