Request : CCI+EMA20

 

Helo,

I need a piece of code to define a variable as a moving average of CCI. I use the MA applied to the CCI (using previous indicator's data) and I want to use that into an EA. How should I do it? iMA(....); ?

Thank you."

 
BrunoFX:
Helo,

I need a piece of code to define a variable as a moving average of CCI. I use the MA applied to the CCI (using previous indicator's data) and I want to use that into an EA. How should I do it? iMA(....); ?

Thank you."

BrunoFX,

If I understand you well, this is the code:

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

//| Demo.mq4 |

//| Mohammed |

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

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Red

extern int CCI_PERIOD=14;

extern int EMA_PERIOD=20;

//---- buffers

double Buf[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,Buf);

//----

return(0);

}

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

//| Custor indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

int start()

{

int i,limit;

double marray[];

int counted_bars=IndicatorCounted();

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

ArrayResize( marray, limit);

ArraySetAsSeries(marray,true);

for(i=0; i<limit; i++)

{

marray = iCCI(NULL,0,CCI_PERIOD,PRICE_CLOSE,i);

Print("marray = ",marray);

}

for(i=0; i<limit; i++)

{

Buf = iMAOnArray(marray,limit,EMA_PERIOD,0,MODE_EMA,i);

}

return(0);

}

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

 

Hi Mohammed

I have compiled the code you've posted and I think that there is something wrong with it. Please have a look at the chart attached. In subchart 1, is CCI

with Moving Average applied to Previous indicator's data. I think that's what BrunoFX wants (and me too). In subchart 2 is your indicator along with the CCI. The settings are the same (CCI period14, EMA period 50) but the Moving averages are different. Why?

Can you please fix your indicator?

Thank you.

Files:
cci_ma.gif  9 kb
 
cucurucu:
I have compiled the code you've posted and I think that there is something wrong with it. Please have a look at the chart attached. In subchart 1, is CCI

with Moving Average applied to Previous indicator's data. I think that's what BrunoFX wants (and me too). In subchart 2 is your indicator along with the CCI. The settings are the same (CCI period14, EMA period 50) but the Moving averages are different. Why?

Can you please fix your indicator?

Thank you.

cucurucu,

I'm so sorry to hear that it didn't work.

Well, I don't understand this sentence "Moving Average applied to Previous indicator's data"

 

It's easy

Hi Mohammed

Well, I don't understand this sentence "Moving Average applied to Previous indicator's data"

Please click & drag the Moving Average over the CCI subchart and, in the MA properties window choose Apply to: Previous Indicator's Data (instead of Close price which is default). Using the previous indicator's data, the Moving Average will be the MA of CCI, not the MA of price.

It's important to use the Moving Average standard indicator (not custom) and to modify the Apply to:, in the moment you drop it on the CCI subchart. If you don't , the MA will appear on the price chart, using the closing price.

I hope you understand. I was kind of difficult to me too, the first time. BrunoFX explained this to me, few days ago.

Please think of something to correct the indicator.

Thank you.

 
cucurucu:
Hi Mohammed

Please click & drag the Moving Average over the CCI subchart and, in the MA properties window choose Apply to: Previous Indicator's Data (instead of Close price which is default). Using the previous indicator's data, the Moving Average will be the MA of CCI, not the MA of price.

It's important to use the Moving Average standard indicator (not custom) and to modify the Apply to:, in the moment you drop it on the CCI subchart. If you don't , the MA will appear on the price chart, using the closing price.

I hope you understand. I was kind of difficult to me too, the first time. BrunoFX explained this to me, few days ago.

Please think of something to correct the indicator.

Thank you.

Guys !

U have to use Buffers instead of normal arrays. If U do so, it will work fine !

 
cucurucu:
Hi Mohammed

Please click & drag the Moving Average over the CCI subchart and, in the MA properties window choose Apply to: Previous Indicator's Data (instead of Close price which is default). Using the previous indicator's data, the Moving Average will be the MA of CCI, not the MA of price.

It's important to use the Moving Average standard indicator (not custom) and to modify the Apply to:, in the moment you drop it on the CCI subchart. If you don't , the MA will appear on the price chart, using the closing price.

I hope you understand. I was kind of difficult to me too, the first time. BrunoFX explained this to me, few days ago.

Please think of something to correct the indicator.

Thank you.

Well Well Well, I've found the problem.

The indicator is working well (The values are right, just watch the data window)

But it draws itself wrong (because it didn't use the same indicator_minimum and indicator_maximum settings of the CCI). This is the first well

The second well:

To make the indicator draws itself right you have to do the following:

1- Download the attached indicator.

2- Drop it to the chart.

3- Drop a CCI.

4- Open the properties window of the CCI to copy the fixed maximum and minimum values (see attached image).

5- Open the MA_CCI indicator and paste the values.

6- It will work.

The third well:

Should I have work to skip these boring steps to make the indicator draws itself right? Or you need only to know the values (which working well although the drawing in not)?

Files:
cci_parms.jpg  52 kb
ma_cci.mq4  2 kb
 

Thank you both

Thank you Mohammed!

You are right, the value it's ok.

There is no need to modify the indicator (for me) because I need to use it in an EA.

I don't know about BrunoFX ... but he also wants to use it for an EA, so I think this indicator would be fine for him too. Thank you.

Kalenzo, thanks for your advice. However, in the data window, I can see that the value is correct. It's all I need.

Best Regards.

 
cucurucu:
Thank you Mohammed!

You are right, the value it's ok.

There is no need to modify the indicator (for me) because I need to use it in an EA.

I don't know about BrunoFX ... but he also wants to use it for an EA, so I think this indicator would be fine for him too. Thank you.

Kalenzo, thanks for your advice. However, in the data window, I can see that the value is correct. It's all I need.

Best Regards.

I'm happy it worked !

 

Thank you with all the present: Mohammed, cucurucu, and Kalenzo for your assistance.