Need help to create a double smoothed exponential MA indicator

 

Hi everyone!

Need some help to code a double smoothed EMA. The derfinition is:

Double Exponential Smoothing (DES) applies Single Exponential Smoothing twice.


My code has still a mistake, hope somebody can find it:


//+------------------------------------------------------------------+
//| double smoothed ema.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link "walb99@yahoo.com"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue


extern int MA_Period=14;
extern int MA_Shift=0;
extern int MA_Applied_Price=0;
extern int Count_Bars=1000;


double ExtMapBuffer1[];

double tempbuffer[];

int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);


return(0);
}



int deinit(){return(0);}


int start()
{
int limit=0;
if (Count_Bars>Bars) {limit=Bars-MA_Period-1;}else{limit=Count_Bars;}


//ArraySetAsSeries(ExtMapBuffer1,true);

(

for (int i=limit;i>=0;i--){
tempbuffer[i]=iMA(Symbol(),0,MA_Period,MA_Shift,MODE_EMA,MA_Applied_Price,i);
)


for (i=limit;i>=0;i--){
ExtMapBuffer1[i] = iMAOnArray(tempbuffer,0,MA_Period,0,MODE_EMA,i);
)
)
)
return(0);
}


-----------------------------------------------------------------------------


Thank you and best regards

walb99

 

What's with all the extraneous parenthesis and braces?

 

Can you corect the code? I m really lost with it.

 

If you use a { (brace) you have to have one and only on } to go with it.

If you use a ( (parenthesis) you have to have one and only one ) to go with it, also.

Same for [ and ].


{} encloses a block of code

() encloses a list of paramters, which may be empty

[] encloses the index for an array

 
phy:

If you use a { (brace) you have to have one and only on } to go with it.

If you use a ( (parenthesis) you have to have one and only one ) to go with it, also.

Same for [ and ].


{} encloses a block of code

() encloses a list of paramters, which may be empty

[] encloses the index for an array

in my editor the braces and the parenthesis look the same, how can I change this? I found the answer: I changed the fond to courier, befor it was courier new, which downot make a difference in the display of braces and parenthesisl.
 

The code looks like this now, but there is still one mistake in it, compiler says, unbalance parenthesis:

----------------------------------------------------------------------------------------------------------------------------


//+------------------------------------------------------------------+
//| EMA of EMA.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue


extern int MA_Period=14;
extern int MA_Shift=0;
extern int MA_Applied_Price=0;
extern int Count_Bars=1000;


double ExtMapBuffer1[];

double tempbuffer[];

int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);


return(0);
}

int deinit(){return(0);}


int start()
{
int limit=0;
if (Count_Bars>Bars) {limit=Bars-MA_Period-1;} else {limit=Count_Bars;}


ArraySetAsSeries(ExtMapBuffer1,true);

{

for (int i=limit;i>=0;i--){
tempbuffer[i]=iMA(Symbol(),0,MA_Period,MA_Shift,MODE_EMA,MA_Applied_Price,i);
}


for (i=limit;i>=0;i--){
ExtMapBuffer1[i] = iMAOnArray(tempbuffer,0,MA_Period,0,MODE_EMA,i);
}
}
}
return(0);
}

 

One { needs one }

You must master this.

 
phy:

One { needs one }

You must master this.


OK, I got it, thank you for your help!!!
 

The code looks like this now:

--------------------------------------------------------------------------------

//+------------------------------------------------------------------+
//| EMA of EMA.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue


extern int MA_Period=14;
extern int MA_Shift=0;
extern int MA_Applied_Price=0;
extern int Count_Bars=1000;


double ExtMapBuffer1[];

double tempbuffer[];

int init()
{
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexBuffer(0,ExtMapBuffer1);


return(0);
}

int deinit(){return(0);}


int start()
{
int limit=0;
if (Count_Bars>Bars) {limit=Bars-MA_Period-1;} else {limit=Count_Bars;}


ArraySetAsSeries(ExtMapBuffer1,true);

{

for (int i=limit;i>=0;i--){
tempbuffer[i]=iMA(Symbol(),0,MA_Period,MA_Shift,MODE_EMA,MA_Applied_Price,i);
}

for (i=limit;i>=0;i--){
ExtMapBuffer1[i] = iMAOnArray(tempbuffer,0,MA_Period,0,MODE_EMA,i);
}
}

return(0);
}


--------------------------------

The compiler does not report any errors, but the indicator displays nothing on the chart window. There must be still a bug in it.

 

You haven't declared the size of tempBuffer.

You must specify a size for your array tempbuffer, in this case, at least as big as the current number of Bars.

MT4 automatically handles this for indicator index buffers.


Also, ArraySetAsSeries is not to be used on the index array, but should be used to prepare tempbuffer array.

 

OK. This version is working now as it should do. Thank you for your help. This problem is solved now.

//+------------------------------------------------------------------+
//| EMA of EMA.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue


extern int MA_Period=14;
extern int MA_Shift=0;
extern int MA_Applied_Price=0;
extern int Count_Bars=1000;


double ExtMapBuffer1[];

double tempbuffer[500];

int init()
{
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexBuffer(0,ExtMapBuffer1);


return(0);
}

int deinit(){return(0);}


int start()
{
int limit=0;
if (Count_Bars>Bars) {limit=Bars-MA_Period-1;} else {limit=Count_Bars;}


ArraySetAsSeries(tempbuffer,true);


for (int i=limit;i>=0;i--){
tempbuffer[i]=iMA(Symbol(),0,MA_Period,MA_Shift,MODE_EMA,MA_Applied_Price,i);
}

for (i=limit;i>=0;i--){
ExtMapBuffer1[i] = iMAOnArray(tempbuffer,0,MA_Period,0,MODE_EMA,i);
}


return(0);
}

Reason: