Indicators: Heikin Ashi Lines

 

Heikin Ashi Lines:

A simpler way to display Heikin Ashi

Heikin Ashi Lines

Author: Fernando Carreiro

 
   // Define OnCalculate loop sequencing macros
      #ifdef __MQL4__   // for MQL4 (as series)
         #define MOnCalcNext(  _index          ) ( _index--             )
         #define MOnCalcBack(  _index, _offset ) ( _index + _offset     )
         #define MOnCalcCheck( _index          ) ( _index >= 0          )
         #define MOnCalcValid( _index          ) ( _index < rates_total )
         #define MOnCalcStart \
            ( rates_total - ( prev_calculated < 1 ? 1 : prev_calculated ) )
      #else             // for MQL5 (as non-series)
         #define MOnCalcNext(  _index          ) ( _index++             )
         #define MOnCalcBack(  _index, _offset ) ( _index - _offset     )
         #define MOnCalcCheck( _index          ) ( _index < rates_total )
         #define MOnCalcValid( _index          ) ( _index >= 0          )
         #define MOnCalcStart \
            ( prev_calculated < 1 ? 0 : prev_calculated - 1 )
      #endif

Why are you not using ArraySetAsSeries()? This would make it possible to use the same macros for both versions of the language.

I'm not criticizing, I'm just curious.

I guess it's just more convenient for you.

 
Incredibly
 
Vladislav Boyko #: Why are you not using ArraySetAsSeries()? This would make it possible to use the same macros for both versions of the language. I'm not criticizing, I'm just curious. I guess it's just more convenient for you.

I choose to use macros so that the decision is done at compile time instead of ArraySetAsSeries() which is done at runtime, in the name of some extra efficiency.

In this case, given that it is a very simple indicator it does not really make much of a difference at all, but for much more complex indicators, it can.

 
Roberto Jacobs #: Incredibly

My apologies, but I did not quite understand the meaning of your post. Can you elaborate?

 
Fernando Carreiro #:

I choose to use macros so that the decision is done at compile time instead of ArraySetAsSeries() which is done at runtime, in the name of some extra efficiency.

In this case, given that it is a very simple indicator it does not really make much of a difference at all, but for much more complex indicators, it can.

Thank you!

 
Thank you Fernando , incredibly helpful to a newbie. Also Thanks for the Public Projects Tip. I didn't even know it was there . Somehow, I had missed that feature . Hopefully I will find some documentation on how to user this feature .
 
Vladislav Boyko #: Thank you!
linfo2 #Thank you Fernando , incredibly helpful to a newbie. Also Thanks for the Public Projects Tip. I didn't even know it was there . Somehow, I had missed that feature . Hopefully I will find some documentation on how to user this feature .

You are welcome!

 

I was looking for how the calculations are made for the Heiken-Ashi and for the maximums they explain "the maximum value from the high, open, or close of the current period" and "for the minimums" the minimum value from the low, open, or close of the current period". Isn't that the same as saying that the highs and lows coincide with the bars? If this is so, your idea of showing them as lines is simple and brilliant, you can see the Heiken-Ashi trend first sight without abandoning normal candles.

Automated translation applied by moderator. On the English forum, please write in English.

 
@Daniel Eduardo San Martin #: Isn't that the same as saying that the highs and lows coincide with the bars?

Most of the time yes, but when the Heikin Ashi Open (moving average) is beyond the high/low of the normal candle, then that becomes the Heikin Ashi High/Low.

 
Fernando Carreiro #:

My apologies, but I did not quite understand the meaning of your post. Can you elaborate?

I feel your code is very good and powerful. I didn't download mq5.
With the code for MT4 that you shared, I just copy and paste it into MetaEditor MQL5 and save as mq5, and everything runs smoothly.