resolved by self

 
sarahfoxwell:

HI does anyone know how to create a heiken ashi RSI indicator for mql5 that I can use in an EA. I looked on the codebase and around the net I could not find the code for it. I want to get the values of the RSI based on the heiken ashi candles. I was looking at the default RSI script 

I am confused how to implement it, I thought I could get the price to be calculated based on the (open high low close/4.0) but I am not sure how that works with the starting value. I would appreciate some guidance or if anyone has the code for it.

Thanks

Please create a freelance order.

 
sarahfoxwell #: I was asking for help
  1. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
              No free help (2017)

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2018)

    We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
              No free help (2017)

  2.       int first_unstable = prev_calculated - _period + 1;
    
          if (first_unstable < 0)
    
             first_unstable = 0;
    
          int start = max(first_unstable, 1);

    See How to do your lookbacks correctly #9#14 & #19. (2016)

  3.       ArrayResize(HA_open, rates_total);
          ArrayResize(HA_close, rates_total);
          ArrayResize(HA_high, rates_total);
          ArrayResize(HA_low, rates_total);

    Why are you computing HA all bars every tick. Make them a non-visiable buffer and compute once. Or just read the HA close directly off the chart.
              take candle color hekin ashi - MQL4 and MetaTrader 4 #8-10 or #1 (2018)

  4.          HA_close[i] = (open[i] + close[i] + high[i] + low[i]) / 4;
    1. Arrays must be manually sized. They have no direction. You must move elements if you want a stack/as-series (set non-series, enlarge the array, set as-series).

    2. Buffers are automatically size, are as-series, and elements are moved for you, new elements are set to EMPTY_VALUE (or your designated. They can also draw on the chart automatically.

    3. In MT4, buffers and MT4 predefined arrays are all ordered AsSeries. There is a difference between the arrays passed to OnCalculate (e.g. low[]) and the MT4 predefined variables (e.g. Low[].) The passed arrays have no default direction, just like MT5.

      To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[], call ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for those arrays, which are expected to work with.
                Event Handling Functions - Functions - Language Basics - MQL4 Reference

    4. In MT5, you must set the direction.

      To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
                Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5
 
sarahfoxwell: HI does anyone know how to create a heiken ashi RSI indicator for mql5 that I can use in an EA. I looked on the codebase and around the net I could not find the code for it. I want to get the values of the RSI based on the heiken ashi candles. I was looking at the default RSI script I am confused how to implement it, I thought I could get the price to be calculated based on the (open high low close/4.0) but I am not sure how that works with the starting value. I would appreciate some guidance or if anyone has the code for it. Thanks This is what I have so far not sure if it is correct? 

As you have stated, the close price of an Heikin Ashi is simply the current total price ( ( open + high + low + close) / 4 ). You don't need to compute the full Heikin Ashi to calculate the RSI of the current total price.

However, since you are struggling, simply use the built-in RSI indicator with the the Typical or Weighted applied price instead, which are similar and the difference is minor. This will save you from having to code anything. And if you need to use it in an EA, just use the iRSI() function with the PRICE_TYPICAL or PRICE_WEIGHTED.

 
sarahfoxwell #: hi thanks for the suggestion, I have tried PRICE_WEIGHTED in the RSI handle but for some reason the values are different there is a integer of 3 difference, is there a way I can change the default RSI script to use the PRICE_WEIGHTED constant. I don't see an area to change this to PRICE_WEIGHTED in the default RSI script. default RSI mql5:

The MetaQuotes example RSI code, uses the default applied prices, stored in the price[] array parameter.

Instead, consider using my rendition (in the CodeBase) and adapt it as you wish ...

EDIT: Please note that it uses conditional compilation for both MQL4 and MQL5. So mix and match it as you need to.

Code Base

Wilder's Relative Strength Index

Fernando Carreiro, 2023.01.22 18:12

An implementation of the Relative Strength Index indicator by John Welles Wilder Jr. as described in his book—New Concepts in Technical Trading Systems [1978].
Reason: