Modify an indicator in EA

 
Hi there,

I would like to transform an indicator using a buffer in EA.

I read the MQL4 documentation but i still can't do what i want

I would like to pratice by transforming the MACD indicator in Expert adviser

I don't need that the EA takes some order but just that it shows by the function Comment the value of macdbuffer[0], macdbuffer[1], SignalBuffer[0] and SignalBuffer[1] to know that it works

Does anyone can help me ? That will be very cool because it waste a lot of time on it !

If you have already done that for an other indicator using a buffer, i am also interesting in

Thanks in advance for your help

TAAD

[CODE]
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Silver
#property indicator_color2 Red
#property indicator_width1 2
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double MacdBuffer[];
double SignalBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(1,SignalSMA);
IndicatorDigits(Digits+1);
//---- indicator buffers mapping
SetIndexBuffer(0,MacdBuffer);
SetIndexBuffer(1,SignalBuffer);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//---- done
return(0);
}
//+------------------------------------------------------------------+[/CODE]
 
string comment="";
string NL="\n";
comment = comment+"MACD:"+NL;
comment = comment+"Current - Main: "+MacdBuffer[0]+" Signal:"+SignalBuffer[0]+NL;
comment = comment+"Old     - Main: "+MacdBuffer[1]+" Signal:"+SignalBuffer[1]+NL;
Comment(comment);

 
Hello zzuegg,

your solution add the comment but not transform the indocator in EA.

My problem is not adding the comment but to do an EA with buffer based on an indicator

thanks for your help
 
TAAD:

.... I don't need that the EA takes some order but just that it shows by the function Comment the value of macdbuffer[0], macdbuffer[1], SignalBuffer[0] and SignalBuffer[1] to know that it works ...

 
TAAD:

... My problem is not adding the comment but to do an EA with buffer based on an indicator ...

I don't get your question... EA can have regular array buffer but can't have IndicatorBuffer. You can call iCustom on that buffer if that's what you're after..

 
cameofx:

I don't get your question... EA can have regular array buffer but can't have IndicatorBuffer. You can call iCustom on that buffer if that's what you're after..


In other words, why this EA do not work ?

Files:
macdcea.mq4  3 kb