Finding Digital Root Source Numbers with MathMod

 

Hi All,

I couldn't find a more appropriate forum category to post this to so please forgive me if I'm not posting this in the right place.

Anyway, I'm using MathMod to find the digital roots between numbers 1-9 of prices and that works perfectly with this code:


DigitalRoot = MathRound(1+MathMod((Price/points*10)-1,9));
For simplicity in the test code below I just used an integer number instead of a price, incremented the original number by 9 and printed that list of 10 numbers along with their digital roots. Since digital roots don't change by adding 9, all the digital roots of the 10 numbers are 4. However, the last 2-digit source numbers for each of those 10 numbers are sometimes different. For a digital root of 4 the last source two-digit numbers can be either 13, 22 or 40, so my question is, can the MathMod function be used in any way to find those final previous source two-digit numbers instead of the single digit final dgital root? If MathMod can be used in this way then can someone please help and explain how this can be done? Thank you very much.


      double Number=1570;
      double DigitalRoot=0;

      string List="";
      for(int k=0; k<11; k++)
      {
         DigitalRoot = MathRound(1+MathMod((Number+(9*k))-1,9));
         List=StringConcatenate(List, k," Number: ", Number+(9*k)," DigitalRoot : ", DigitalRoot,"\n");
      }

      Comment(List);
Documentation on MQL5: Math Functions / MathMod
Documentation on MQL5: Math Functions / MathMod
  • www.mql5.com
MathMod - Math Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5