Discussion of article "How to create a custom indicator (Heiken Ashi) using MQL5"

 

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:

  • Open = (open of previous candle + close of the previous candle) / 2
  • Close = (open + close + high + low of the current candle) / 4
  • High = the highest value from the high, open, or close of the current period
  • Low = the lowest value from the low, open, or close of the current period

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.

 ha indicator

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

Documentation on MQL5: Language Basics / Variables / Visibility Scope and Lifetime of Variables
Documentation on MQL5: Language Basics / Variables / Visibility Scope and Lifetime of Variables
  • www.mql5.com
Visibility Scope and Lifetime of Variables - Variables - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

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.

 
Great Article. Thanks