- Function call
- Limitations of functions in the tester
- Parameters and arguments
I suggest you first research how Indicators work and how they are programmed, because Indicators are not "created" inside functions. Indicators are separate "programs", that need to be instantiated to obtain a handle, and then their data accessed later.
Instantiating an indicator to obtain a handle, is done in OnInit() or a class constructor or initialiser. After that, you then access their data in OnTick() or OnTimer().
I suggest you first research how Indicators work and how they are programmed, because Indicators are not "created" inside functions. Indicators are separate "programs", that need to be instantiated to obtain a handle, and then their data accessed later.
Instantiating an indicator to obtain a handle, is done in OnInit() or a class constructor or initialiser. After that, you then access their data in OnTick() or OnTimer().
Thank you for the response
so do i need to call each handle in the onInit function for example CCIHandle = iCCI(_Symbol,PERIOD_CURRENT,14,PRICE_TYPICAL); or can i just call the function inside the onInit where i have used this code?
Thank you for the response
so do i need to call each handle in the onInit function for example CCIHandle = iCCI(_Symbol,PERIOD_CURRENT,14,PRICE_TYPICAL); or can i just call the function inside the onInit where i have used this code?
I just went and test it and it is working. if i call the fanction inside the onInit and you test it, it shows the indicators on the chart.
You should not access market data inside OnInit(). There is no guarantee that it will be available at that time. You should only access market data after the first tick has arrived.
Forum on trading, automated trading systems and testing trading strategies
Issue: AccountInfoDouble(ACCOUNT_BALANCE) returns 0 all the time.
William Roeder, 2025.08.18 12:42
void OnInit() { Print("OnInit: ", AccountInfoDouble(ACCOUNT_BALANCE));don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
Do you realise that your code is leaking handles, and that you are creating indicator handles on every call and never releasing them?
Luckily, I suspect, that the compiler or the terminal is probably optimising the code or detecting the situation, and internally releasing or reusing Indicator handles to prevent an overflow. However, your code design is very problematic and a bad practice model.
Indicator handles should preferably be instantiated only once during the life-time of the EA's existence. The handles can then be references as many times as needed thereafter, until released explicitly or implicitly at the end when the EA's execution is terminated.
Please study the example code in the documentation ...
- www.mql5.com
When showing code, please don't use screenshots. Use the CODE button (Alt-S) when inserting code.
When showing code, please don't use screenshots. Use the CODE button (Alt-S) when inserting code.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use