MQL4 - automated forex trading   /  

Forum

Need help to create a double smoothed exponential MA indicator

Back to topics list  | 1 2 To post a new topic, please log in or register

avatar
12
walb99 2008.01.22 19:29 

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

article

Testing of Expert Advisors in the MetaTrader 4 Client Terminal: An Outward Glance

What happens after you have clicked on the "Start" button? The article answers this and many other questions.


avatar
2462
phy 2008.01.22 19:57 

What's with all the extraneous parenthesis and braces?


avatar
12
walb99 2008.01.22 20:01 

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


avatar
2462
phy 2008.01.22 21:27 

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


avatar
12
walb99 2008.01.22 21:50 
phy wrote:

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.

avatar
12
walb99 2008.01.22 22:17 

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);
}


avatar
2462
phy 2008.01.23 02:29 

One { needs one }

You must master this.


avatar
12
walb99 2008.01.23 08:43 
phy wrote:

One { needs one }

You must master this.


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

avatar
12
walb99 2008.01.23 08:57 

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.



avatar
2462
phy 2008.01.23 09:36 

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.




avatar
12
walb99 2008.01.23 09:53 

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);
}

Back to topics list   | 1 2  

To add comments, please log in or register