Return 4806 when create a iMACD handle in OnTick and useiGetArray to get buffer data, what`s the problem?
The following is my test code
and the log
You are making a gross mistake! In MQL5, the indicator handle SHOULD be received ONLY ONCE! This is done in OnInit ().
- Example from help: iMACD
- An example of how to create an indicator handle and get indicator values from an expert: iMACD value on chart
You are making a gross mistake! In MQL5, the indicator handle SHOULD be received ONLY ONCE! This is done in OnInit ().
- Example from help: iMACD
- An example of how to create an indicator handle and get indicator values from an expert: iMACD value on chart
Thanks again for your answers.There is a requirement that create a new macd handle as a quotation changed.
Thanks again for your answers. There is a requirement that create a new macd handle as a quotation changed.
I did not understand the highlighted phrase . Can you ask your question differently?
I did not understand the highlighted phrase . Can you ask your question differe
Dynamically created new macd handle(change signal_period paramter) as the market quotaion changed. Like the following code , I use iRSI change signal_period paramter with iMacd .
void OnTick() { //--- tick_cnt++; if(tick_cnt % 100 == 0) { double rsi_buffer[]; ArraySetAsSeries(rsi_buffer,true); if(!iGetArray(handle_ris,0,0,1,rsi_buffer)) { PrintFormat("INFO! EA: %s, FUNCTION: %s, macd_type:%s, iGetArray 0 failed! curr_time:%s", __FILE__,__FUNCTION__, EnumToString(macd_type), TimeToString(time_current)); return(false); } double rsi_value = rsi_buffer[0]; int signal_period = int((rsi_value - 20) * rsi_macd_coeff + 2); int handle =iMACD(Symbol(),PERIOD_CURRENT,120,260,signal_period, PRICE_CLOSE);
Dynamically created new macd handle(change signal_period paramter) as the market quotaion changed. Like the following code , I use iRSI change signal_period paramter with iMacd .
One option might be the usage of IndicatorCreate() together with IndicatorParameters and IndicatorRelease.
But the better way would be to calculate the MACD yourself and just change the coefficients of the used ema for the fast and slow MA

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The following is my test code
and the log