-
for (int i = begin; i < rates_total ; i++) { // initialize buffers avg1_buffer[i] = EMPTY_VALUE; avg2_buffer[i] = EMPTY_VALUE; if (i < rates_total - 1) { avg1_buffer[i] = (high[i] + low[i]) / 2; if (SymbolInfoInteger(SYMBOL, SYMBOL_EXIST) && SYMBOL != "" && Symbol() != SYMBOL) { int idx = iBarShift(SYMBOL, Period(), time[i], true); if (idx > 0) { indicator_handle = iCustom(SYMBOL, Period(), "Me\\indicator", SYMBOL);
Perhaps you should read the manual, especially the examples.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
How to call indicators in MQL5 - MQL5 Articles (2010) -
You are recursively calling the indicator.
The following is a minimal example. Indicator.mq5 #property indicator_chart_window indicator_handle = iCustom(SYMBOL, Period(), "Me\\indicator", SYMBOL);
- They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
If the Indicator calls iCustom() in OnInit(), then, the Expert Advisor gets the error: stack overflow
2. You are recursively calling the indicator.
Alternatives?
True. The static flag should be declared on the global scope and reset it in OnDenit(reason) depending on the value of the reason parameter. After iCustom(), could be useful to refresh the chart with ChartSetSymbolPeriod().
It's not clear why one shouldn't create an instance of oneself. From my point of view, there is no downside, unless one doesn't enter an infinite loop or overflow the memory or, in general, uses a method in a way that is not recommended by the documentation.
- 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,
I have an Expert Advisor which retrieves, with iCustom() , values from two buffers calculated by an Indicator: one buffer is associated with data get from the current Symbol() , while the other one uses iCustom() to get data from a different SYMBOL.
The indicator prints correctly the two buffers.
The problem is that the Expert Advisor takes several minutes to synchronize all the data so any optimization test is impossible.
Things of which I'm aware:
* in the Expert Advisor, iCustom() , must be called in OnInit() ;
* in the Indicator, iCustom() , must be called in OnCalculate() .
Why the Expert Advisor takes so long to load all the bars? Am I doing something wrong?
The following is a minimal example.
Indicator.mq5
Expert.mq5