Your code doesn't compile.
Remember: the indicator handle must be received in OnInit, that is, this is done once, not at every tick.
Correct your mistake. After that I will show the following error.
I'm not sure if this is helpful but I have this error check.
I only use the last saved value in there e.g. MaBuffer[0]
double MA = iMA(_Symbol,_Period,12,4,MODE_SMA,PRICE_CLOSE);
if (CopyBuffer(MA,0,0,1,MABuffer) < 0){Print("CopyBuffer error =",GetLastError());}
ArraySetAsSeries(MABuffer, false);
Your code doesn't compile.
Remember: the indicator handle must be received in OnInit, that is, this is done once, not at every tick.
Correct your mistake. After that I will show the following error.
Sorry about that.
int macd; int OnInit() { int indicator = iMACD(_Symbol, PERIOD_CURRENT, 12, 26, 9, PRICE_CLOSE); return(INIT_SUCCEEDED); } void OnDeinit(const int reason){} void OnTick() { double array1[]; double array2[]; int MACD_bar_entry = 1; ArraySetAsSeries(array1, true); ArraySetAsSeries(array2, true); CopyBuffer(macd, 0, 0, MACD_bar_entry+2, array1); CopyBuffer(macd, 1, 0, MACD_bar_entry+2, array2); double mainLineValue = NormalizeDouble(array1[MACD_bar_entry], 2); double mainLineValueOld = NormalizeDouble(array1[MACD_bar_entry+1], 2); double signalLineValue = NormalizeDouble(array2[MACD_bar_entry], 2); double signalLineValueOld = NormalizeDouble(array2[MACD_bar_entry+1], 2); string str = "\nsignal 1" + DoubleToString(signalLineValue) + " " + "\nsignal 2 " + DoubleToString(signalLineValueOld) + " " + "\nmain line 1" + DoubleToString(mainLineValue) + " " + "\nmain line 2 " + DoubleToString(mainLineValueOld) + " " ; Print(str); }
It should be something like that?
I'm not sure if this is helpful but I have this error check.
I only use the last saved value in there e.g. MaBuffer[0]
double MA = iMA(_Symbol,_Period,12,4,MODE_SMA,PRICE_CLOSE);
if (CopyBuffer(MA,0,0,1,MABuffer) < 0){Print("CopyBuffer error =",GetLastError());}
ArraySetAsSeries(MABuffer, false);
You are confusing. You are on the MQL5 forum and write in the main section - MQL5 is discussed here. In MQL5, the principle of working with indicators is as follows:
Forum on trading, automated trading systems and testing trading strategies
Vladimir Karputov, 2020.11.13 06:01
Receiving data from an indicator in an MQL5.
Scheme:
An example for the iMA indicator:
Sorry about that.
It should be something like that?
Please insert the code correctly: FIRST press the button
Sorry about that.
It should be something like that?
An example of how to get indicator values: iMACD value on chart

- 2020.04.09
- www.mql5.com
You are confusing. You are on the MQL5 forum and write in the main section - MQL5 is discussed here. In MQL5, the principle of working with indicators is as follows:
Hello, that made me laugh. I read it in the voice of Richard Ayoade :D
I use that in my EA, I think it makes it run faster.
I am using MQL5 and it works perfectly for me. I also use it to work out the gradient between the last two values of the MABuffer.
Hello, that made me laugh. I read it in the voice of Richard Ayoade :D
I use that in my EA, I think it makes it run faster.
I am using MQL5 and it works perfectly for me. I also use it to work out the gradient between the last two values of the MABuffer.
Before you laugh, learn to read the help: iMA
The function returns the handle of the Moving Average indicator. It has only one buffer.
int iMA( string symbol, // symbol name ENUM_TIMEFRAMES period, // period int ma_period, // averaging period int ma_shift, // horizontal shift ENUM_MA_METHOD ma_method, // smoothing type ENUM_APPLIED_PRICE applied_price // type of price or handle );
Return Value
Returns the handle of a specified technical indicator, in case of failure returns INVALID_HANDLE. The computer memory can be freed from an indicator that is no more utilized, using the IndicatorRelease() function, to which the indicator handle is passed.

- www.mql5.com
Before you laugh, learn to read the help: iMA
The function returns the handle of the Moving Average indicator. It has only one buffer.
Return Value
Returns the handle of a specified technical indicator, in case of failure returns INVALID_HANDLE. The computer memory can be freed from an indicator that is no more utilized, using the IndicatorRelease() function, to which the indicator handle is passed.
I didn't mean that in a rude way! I thought it was funny. I like Richard Ayoade, he's in Gadget man and it's great.
I agree that it returns one buffer, I save multiple. I said the last two values (and that's my fault as I wasn't true), but I have a function at the bottom which passes in the different MA buffers.
They aren't specifically the last two values of the MABuffer, but they are the last two values of a moving average, saved in different buffers.
I have 3 as one has a different period shift.
double MABuffer[], currentMABuffer[], currentMABufferSlope[];
I am normally a programmer but have very, very slowly learnt how to use MQL5.
So it was frustrating considering it's based off of the old C++ language, and I can't use certain functions I'm used to.
I haven't ran the EA live yet but it'll be exciting when I do! Also terrifying.
But it works very well in demo, and have an included commission function so I can work out the balance in reality.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi!
For some reasons, iMACD is returning 0 on GBPUSD, it's working on other pairs. Any idea why?
double array1[];
double array2[];
int indicator = iMACD(_Symbol, MACD_timeframe, MACD_fast_ema_period, MACD_slow_ema_period, MACD_signal_period, MACD_applied_price);
ArraySetAsSeries(array1, true);
ArraySetAsSeries(array2, true);
CopyBuffer(indicator, 0, 0, MACD_bar_entry+2, array1);
CopyBuffer(indicator, 1, 0, MACD_bar_entry+2, array2);
double mainLineValue = NormalizeDouble(array1[MACD_bar_entry], 2);
double mainLineValueOld = NormalizeDouble(array1[MACD_bar_entry+1], 2);
double signalLineValue = NormalizeDouble(array2[MACD_bar_entry], 2);
double signalLineValueOld = NormalizeDouble(array2[MACD_bar_entry+1], 2);
string str = "\nsignal " + DoubleToString(signalLineValue, _Digits) + " " +
"\nsignalOld " + DoubleToString(signalLineValueOld, _Digits) + " " +
"\nMACD buy value" + DoubleToString(MACD_buy_value, _Digits) +
"\nMACD sell value" + DoubleToString(MACD_buy_value, _Digits);
Print(str);
Thanks,
Myx