finding the lowest value of EMA over previous period

 
       double Lowest = 500000;
       
       double MovingAverage = iMA(Symbol(), 0, 10, 0, MODE_EMA, PRICE_CLOSE, 10);
       
       
   
       for (int i = 0; i < 10; i++)
        {
        if(Lowest < MovingAverage)
         {
          MovingAverage = Lowest;     
         }
        }

Hi all,

Been trying to find the lowest value of an EMA but this code doesnt seem to work.

Thx for the help.

 
Amirio:

Hi all,

Been trying to find the lowest value of an EMA but this code doesnt seem to work.

Thx for the help.

Almost there , you need to calculate the moving average you are comparing against the lowest . The iMA calculates one value not an entire plot like Trading View

so your code becomes :

       
       
       
       
       //get the first value of MA in the lowest
       double Lowest = iMA(Symbol(), 0, 10, 0, MODE_EMA, PRICE_CLOSE,0);
       //loop inside the rest (from 1 instead of from 0)
       for (int i = 1; i < 10; i++)
        {
        //get the moving average at this location 
        double MovingAverage = iMA(Symbol(), 0, 10, 0, MODE_EMA, PRICE_CLOSE,i);
       //if the moving average here is lower than the lowest value , we change ...
        if(MovingAverage < Lowest)
         {
         //...the lowest value
          Lowest=MovingAverage;     
         }
        }
 

Hey Lorentzos,

Wow, thanks a lot.

Works perfectly.

Cheers,

Amir

 
Amirio #:

Hey Lorentzos,

Wow, thanks a lot.

Works perfectly.

Cheers,

Amir

anytime