double myMACD[],mySignal[]; ArraySetAsSeries(myMACD,true); ArraySetAsSeries(mySignal,true); int MACD = iMACD(_Symbol,_Period,12,26,9,PRICE_CLOSE); CopyBuffer(MACD,0,0,1,myMACD); // for Histogram CopyBuffer(MACD,1,0,1,mySignal); // for Signal
lolopodek :
No, you have shown an invalid code. Read the Help: in MQL5, the indicator handle is CREATED ONCE! DO IT IN OnInit () !!!
Pass the MACD handle to the MA indicator.
//--- input parameters input int FastEMA=12; input int SlowEMA=26; input int SignalMA=9; input ENUM_MA_METHOD SignalMethod=MODE_EMA; input int SignalShift=0; input ENUM_APPLIED_PRICE Price=PRICE_CLOSE; //--- indicator buffers double MACDBuffer[]; double SignBuffer[]; //--- int handleMACD=INVALID_HANDLE,handleSign=INVALID_HANDLE; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- if((handleMACD=iMACD(_Symbol,_Period,FastEMA,SlowEMA,SignalMA,Price))==INVALID_HANDLE || (handleSign=iMA(_Symbol,_Period,SignalMA,SignalShift,SignalMethod,handleMACD))==INVALID_HANDLE) return(INIT_PARAMETERS_INCORRECT); //--- ArraySetAsSeries(MACDBuffer,true); ArraySetAsSeries(SignBuffer,true); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- if(CopyBuffer(handleMACD,0,0,2,MACDBuffer)!=2 || CopyBuffer(handleSign,0,0,2,SignBuffer)!=2) return; //--- double curMACD=MACDBuffer[0]; double preMACD=MACDBuffer[1]; double curSign=SignBuffer[0]; double preSign=SignBuffer[1]; //--- if(curMACD>curSign && preMACD<preSign) { //--- } //--- } //+------------------------------------------------------------------+
returns is showing error.
and could you say us how to handle buy/sell signal. What's the conditional.
Thanks and take care.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi
I’m new to this platform and trading. So bear the newish question.
I noticed in MT5 the MACD signal line is based on SMA.
How do I go about calculating the MACD Signal line value based on EMA. I just am after the current value.
I’ve read other posts about this but I am still confused. Some people use limits of say 10. I don’t understand.
Any help would be great thanks .
I can calculate the macd using the values returned by ima but I don’t know how to use this macd and apply the 9 period Ema.