How does this work ?

 
   double EMA        =weight*Open[0]   + (1.0-weight)*lastEMA,
   EMA_of_EMA  =weight*EMA      + (1.0-weight)*lastEMA_of_EMA;
   Buffer[0]=2.0*EMA - EMA_of_EMA;
//----

That block of code is from a DEMA indicator the first line ends in a comma so I assume that means that line is continued onto the next line.

I dont really understand what the comma does in this case, and if it does continue onto the next line it means there is this section of code:

   double EMA        =weight*Open[0]   + (1.0-weight)*lastEMA,EMA_of_EMA  =weight*EMA

the thing about it that puzzles me is there is no variable defined as EMA_of_EMA, there is one called lastEMA and one called lastEMA_of_EMA so how does this compile with: "lastEMA,EMA_of_EMA" ? and

Buffer[0]=2.0*EMA - EMA_of_EMA;

The indicator does compile and does appear to work but I would like to understand what that line does and how it can be written that way if anyone knows I would appreciate any reply as I want to incorporate this indicator into an EA later on. I was wondering if the code should have been like this:

   double EMA        =weight*Close[0]   + (1.0-weight)*lastEMA;
   lastEMA_of_EMA  =weight*EMA      + (1.0-weight)*lastEMA_of_EMA;
   Buffer[0]=2.0*EMA - lastEMA_of_EMA;

This is the complete code of the indicator

//+------------------------------------------------------------------+
//|                                                         DEMA.mq4 |
//| DEMA = 2 * EMA - EMA of EMA                                                                                                 |
//+------------------------------------------------------------------+
#property link "http://www.forexfactory.com/showthread.php?t=29419"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1  Red
#property indicator_width1  1
//---- input parameters
extern int PERIOD  =12;
//---- indicator buffer
double Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorShortName("DEMA("+PERIOD+")");
   SetIndexBuffer(0,Buffer);
   SetIndexStyle(0,DRAW_LINE);
  }
//+------------------------------------------------------------------+
int start()
  {
   int limit=Bars-1-IndicatorCounted();
//----
   static double lastEMA, lastEMA_of_EMA;
   double weight=2.0/(1.0+PERIOD);
   if(IndicatorCounted()==0)
     {
      Buffer[limit]  =Close[limit];
      lastEMA        =Close[limit];
      lastEMA_of_EMA  =Close[limit];
      limit--;
     }
//----
   //   Calculate old bars (not the latest), if necessary
   for(int i=limit; i > 0; i--)
     {
      lastEMA        =weight*Close[i]   + (1.0-weight)*lastEMA;
      lastEMA_of_EMA  =weight*lastEMA   + (1.0-weight)*lastEMA_of_EMA;
      Buffer[i]=2.0*lastEMA - lastEMA_of_EMA;
     }
//----
   //   (Re)calculate current bar
   double EMA        =weight*Close[0]   + (1.0-weight)*lastEMA,
   EMA_of_EMA  =weight*EMA      + (1.0-weight)*lastEMA_of_EMA;
   Buffer[0]=2.0*EMA - EMA_of_EMA;
//----
   return(0);
  }

//+------------------------------------------------------------------+
 

EMA_of_EMA is a double variable.

Just like...

double var1, var2;

... creates 2 double variables your code does the same because of the comma.

Compiler is expecting either a)semicolon or b)comma to either a)end variable definition or b)define the next double variable.

/ McKeen

 

Ohh ok i see now !! Thanks McKeen, I was looking at it all the wrong way