New article How to create a custom indicator (Heiken Ashi) with MQL5:
Author: Mohamed Abdelmaaboud
Declaration- Definition
Hi,
I see that you use the members OnInit(),- OnDenit(),- OnTick() for object-oriented programming.
But doesn 'tthe declaration or initialisation of the variables, e.g. double heikenAshiOpen[]... belong once in the OnInit()- and consequently the evaluation of the variables (definition), as well as the object variables, fastEMA and slowEMA in the ticker?
In principle yes, but not here, as the variables would lose their values again when the function(s) is/are exited. Google for: site:mql5.com scope variable
and read: https://www.mql5.com/en/docs/basis/variables/variable_scope

- www.mql5.com
Deklaration- Definition
Hi,
I see that you use the members OnInit(),- OnDenit(),- OnTick() for object-oriented programming.
But doesn 'tthe declaration or initialisation of the variables, e.g. double heikenAshiOpen[]... belong once in the OnInit()- and consequently the evaluation of the variables (definition), as well as the object variables, fastEMA and slowEMA in the ticker?
I think the same as Carlo. Arrays in
OnInit()
are only loaded when the EA is uploaded and when the timeframe changes.
Because the value changes with every tick.
And with the indicator, the
OnCalculate
calculate.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article How to create a custom indicator (Heiken Ashi) using MQL5 has been published:
In this article, we will learn how to create a custom indicator using MQL5 based on our preferences, to be used in MetaTrader 5 to help us read charts or to be used in automated Expert Advisors.
The Heiken Ashi charts are similar to the normal candlestick technical charts but the calculation to plot these candles is different. Namely, there are two methods that differ. As we know, the normal candlesticks chart calculates prices based on actual open, high, low, and close prices in a specific period, but the Heiken Ashi takes into consideration the prices of the previous similar prices (open, high, low, and close) when calculating its candles.
Here is how the relevant values for Heiken Ashi are calculated:
Based on the calculation, the indicator constructs bull and bear candlesticks, and the colors of these candlesticks indicate the relevant direction of the market: if it is bullish or bearish. Below is an example that shows the traditional Japanese candlesticks and Heiken Ashi, so see the difference from a visual perspective.
Author: Mohamed Abdelmaaboud