MA of the MACD Signal

 

I need in my EA an Moving average of the Signal line of the MACD.

Can I use IMAOnArray ?.

Please giv me advice, thanks

Dropje

 

Yes,

// fill your regular macd array

MaCD[i] = iMACD(......i);

// and then use iMAOnArray on that buffer

Ma_On_MACD[i] = iMAOnArray(MaCD,....i)

 

Thank you cameofx,

This is a part of the EA, it give me not the right signal. What is wrong with the code?

int fnMACD_Signal()

{

double iMACD_Signal;

double dMACD = iMACD(NULL,0,10,20,0,PRICE_CLOSE,MODE_SIGNAL,0);

double macd[];

double dIMACD[];

for(int i=0 ; i<=160 ; i++)

{

macd[i] = iMACD(NULL,0,10,20,1,PRICE_CLOSE,MODE_SIGNAL,i);

dIMACD[i] = iMAOnArray( macd,0,7,0,MODE_EMA,i);

}

if(dMACD > dIMACD[i])

{

iMACD_Signal =1;

}

if(dMACD < dIMACD[i])

{

iMACD_Signal =2;

}

return(iMACD_Signal);

}

 

Try the following code:

int fnMACD_Signal()
{
   int iMACD_Signal = 0;
   double dMACD = iMACD(NULL,0,10,20,0,PRICE_CLOSE,MODE_SIGNAL,0);
   double macd[];
   double dIMACD[];
   
   for(int i=0 ; i<=160 ; i++)
   {
      macd[i] = iMACD(NULL,0,10,20,1,PRICE_CLOSE,MODE_SIGNAL,i);
      dIMACD[i] = iMAOnArray(macd,0,7,0,MODE_EMA,i);
   }
   if(dMACD > dIMACD[0])
   {
      iMACD_Signal = 1;
   }
   if(dMACD < dIMACD[0])
   {
      iMACD_Signal = 2;
   }
   return(iMACD_Signal);
}
 
Dropje:

Thank you cameofx,

This is a part of the EA, it give me not the right signal. What is wrong with the code?

to declare a function like you did would never work... I've indented your code otherwise as is. please use the SRC button next time.
      int fnMACD_Signal()
      {
       double iMACD_Signal;
       double dMACD = iMACD(NULL,0,10,20,0,PRICE_CLOSE,MODE_SIGNAL,0);
       double macd[];
       double dIMACD[];

         for(int i=0 ; i<=160 ; i++)
            {
            macd[i] = iMACD(NULL,0,10,20,1,PRICE_CLOSE,MODE_SIGNAL,i);
            dIMACD[i] = iMAOnArray( macd,0,7,0,MODE_EMA,i);
            }

         if(dMACD > dIMACD[i])
            {
            iMACD_Signal =1;
            }

         if(dMACD < dIMACD[i])
            {
            iMACD_Signal =2;
            }

       return(iMACD_Signal);
      }
I recommend learning the process step by step Dropje, less frustration more result... I explain some more in next post
 
robofx.org:

Try the following code:

robofx, you beat me to it... some question though :

- the function has no parameter;

- dMACD is calling last bar only while macd & dIMACD calculates 160 + 1 bars, what's the point of this?

- declaring iMACD_Signal with double instead of int is also a waste of memory on iteration, though not noticable, it's simply pointless in this case to flag with double.

 
cameofx:

robofx, you beat me to it... some question though :

- the function has no parameter;

- dMACD is calling last bar only while macd & dIMACD calculates 160 + 1 bars, what's the point of this?

- declaring iMACD_Signal with double instead of int is also a waste of memory on iteration, though not noticable, it's simply pointless in this case to flag with double.

cameofx,

You're right, I'm not sure what's the point in calculating 161 bars.. just fixed some minor mistakes.

 
robofx.org:

cameofx,

You're right, I'm not sure what's the point in calculating 161 bars.. just fixed some minor mistakes.

The 160 bars is just a figure, I thought I needed a number of bars to do the calculation.

The only signal I need is when the MA of the MACD crosses the MACD.

So I only need the last bar?

 

@ robofx.org. & Dropje

I rarely got it on first attempt either, no worries. Here's my try on the snippet assuming you only need to call last bar value on each iteration/call. fwiw.

int fnMACD_Signal()
{
   int iMACD_Signal; 
   double macd[], maOnMacd[];

      double dMACD = iMACD(NULL,0,10,20,0,PRICE_CLOSE,MODE_SIGNAL,0);

      for(int i=0; i<= 20+7+1+1; i++)
      {
       macd[i] = iMACD(NULL,0,10,20,1,PRICE_CLOSE,MODE_SIGNAL,i);
       maOnMacd[i] = iMAOnArray( macd,0,7,0,MODE_EMA,i);
      }
   
      if(dMACD > maOnMacd[0]) iMACD_Signal = 1;
      else if(dMACD < maOnMacd[0]) iMACD_Signal = 2;
      else Print(" dMACD & maOnMacd is dead equal.)";
      return(iMACD_Signal);
}
 
Dropje:

The 160 bars is just a figure, I thought I needed a number of bars to do the calculation.

The only signal I need is when the MA of the MACD crosses the MACD.

So I only need the last bar?

Yes, you can call only the last bar... but that would mean at every tick when the bar has not closed you will have iMACD_Signal changing its value. Not very useful.

you need to configure your algorithm/logic beforehand. Calling on last bar closed is the more accepted 'consensus' with signal trigger. Knowing where/what 'i' stand on calculation is also important.

I use "20+7+1+1" to illustrate : with the hard-coded parameters - 20 & 7 being the max period of each array and adding one to each just in case - it is sufficient to produce last bar calc value.

hth

 
cameofx:

Yes, you can call only the last bar... but that would mean at every tick when the bar has not closed you will have iMACD_Signal changing its value. Not very useful.

you need to configure your algorithm/logic beforehand. Calling on last bar closed is the more accepted 'consensus' with signal trigger. Knowing where/what 'i' stand on calculation is also important.

I use "20+7+1+1" to illustrate : with the hard-coded parameters - 20 & 7 being the max period of each array and adding one to each just in case - it is sufficient to produce last bar calc value.

hth


Thanks,

It is working!

Regards, FH

Reason: