What is the difference between the two EMA funtions

 

funtion 1:

for (int i = 0; i < bars-1; i++) {

ind[i] = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, i);

}

funtions 2:

ind = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, i);

 
rajandran:

funtion 1:

for (int i = 0; i < bars-1; i++) {

ind[i] = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, i);

}

funtions 2:

ind = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, i);


Funtion 1

Is calculating for every bar there is the moving average beginning with 0 ending with last bar (total bars = bars-1 because the first bar we count = 0)

Function 2

Only calculating for bar number i the moving average one calculation i= the number of the bar you want to know ....

A nice practise for you would be if you trie to put it in a program and see the difference then take not bars-1 but for example 5

place a moving average with same setting on the chart and you will see the difference I'm curious if you can do it

 
//+------------------------------------------------------------------+
//|                                                     Comments.mq4 |
//|                                Copyright © 2012, Tjipke de Vries |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, Tjipke de Vries"
#property link      ""

#property indicator_chart_window
//---- input parameters
extern int limit = 6;
extern int BARNR = 3;


double ind[100];
double BARNRvalue;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   subPrintDetails();
//----
   return(0); 

  }
//+------------------------------------------------------------------+
//----------------------- PRINT COMMENT FUNCTION
void subPrintDetails()
{
   string sComment   = "";
   string sp         = "----------------------------------------\n";
   string NL         = "\n";
   
      
   sComment = "Comments EA              Copyright © 2012, Tjipke" + NL;
   sComment = sComment + NL;
   sComment = sComment + "formule 1 " + NL;
   for (int i = 0; i < limit; i++)
    {
     ind[i] = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, i);
     sComment = sComment + DoubleToStr(i,0) + "   " + DoubleToStr(ind[i],Digits) + NL;
    }
   sComment = sComment + NL;
   sComment = sComment + NL;
   sComment = sComment + "formule 2 " + NL; 
   BARNRvalue = iMA(NULL, 0, 13, 0, MODE_EMA, PRICE_CLOSE, BARNR);
   sComment = sComment + DoubleToStr(BARNR,0) + "   " + DoubleToStr(BARNRvalue,Digits) + NL;
  


   Comment(sComment);
}
//+------------------------------------------------------------------+

This might help place it as indicator on the chart

with also a Moving Average ---- Period 13 ----MA shift 0 ----- EMA----Price_Close

 
Thanks deVries for the clarification :)
Reason: