Display Heiken Ashi Candles Higher Timeframe On Main Chart

 

Hi, I searched through the entire forum and used google to find an example of an indicator that displays Heiken Ashi candles from higher timeframes onto the current main window of the chart. For example, I use the MQL5 standard Heiken_Ashi.ex5 indicator on the M1 timeframe to display the bars. Now, I want to use this indicator in addition to display Heiken Ashi candles from M15 timeframe. However, just changing the period did not do the trick:

// Current timeframe (M1) Heiken Ashi
hHeikenAshi=iCustom(_Symbol,_Period,"::Experts\\AlgoTrading\\Indicators\\Heiken_Ashi\\Heiken_Ashi.ex5");

// Timeframe M15 Heiken Ashi
hHeikenAshi_M15=iCustom(_Symbol,PERIOD_M15,"::Experts\\AlgoTrading\\Indicators\\Heiken_Ashi\\Heiken_Ashi.ex5");

I found some MQL4 examples but I am not able to translate this to MQL5. I found the following MQL5 indicator that illustrates my needs:

https://www.mql5.com/en/market/product/51137?source=Site+Search

And finally I found the following MQL5 indicator using TimeFrame and CopyOpen etc. functions for the time shift:

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots   1
#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1  DodgerBlue, Red
#property indicator_label1  "Heiken Ashi Open;Heiken Ashi High;Heiken Ashi Low;Heiken Ashi Close"
//--- indicator buffers
double ExtOBuffer[];
double ExtHBuffer[];
double ExtLBuffer[];
double ExtCBuffer[];
double ExtColorBuffer[];

ENUM_TIMEFRAMES timeframe = PERIOD_M15;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
{
    //--- indicator buffers mapping
    SetIndexBuffer(0, ExtOBuffer, INDICATOR_DATA);
    SetIndexBuffer(1, ExtHBuffer, INDICATOR_DATA);
    SetIndexBuffer(2, ExtLBuffer, INDICATOR_DATA);
    SetIndexBuffer(3, ExtCBuffer, INDICATOR_DATA);
    SetIndexBuffer(4, ExtColorBuffer, INDICATOR_COLOR_INDEX);
    //---
    IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
    //--- sets first bar from what index will be drawn
    IndicatorSetString(INDICATOR_SHORTNAME, "Heiken Ashi M15");
    //--- sets drawing line empty value
    PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0);
}
//+------------------------------------------------------------------+
//| Heiken Ashi                                                      |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    int start;
    //--- preliminary calculations
    if (prev_calculated == 0)
    {
        ExtLBuffer[0] = low[0];
        ExtHBuffer[0] = high[0];
        ExtOBuffer[0] = open[0];
        ExtCBuffer[0] = close[0];
        start = 1;
    }
    else
        start = prev_calculated - 1;

    //--- the main loop of calculations
    for (int i = start; i < rates_total && !IsStopped(); i++)
    {
        //double ha_open = (CopyOpen(Symbol(), timeframe)[i - 1] + CopyClose(Symbol(), timeframe)[i - 1]) / 2;
        //double ha_close = (CopyOpen(Symbol(), timeframe)[i] + CopyHigh(Symbol(), timeframe)[i] + CopyLow(Symbol(), timeframe)[i] + CopyClose(Symbol(), timeframe)[i]) / 4;
        //double ha_high = MathMax(CopyHigh(Symbol(), timeframe)[i], MathMax(ha_open, ha_close));
        //double ha_low = MathMin(CopyLow(Symbol(), timeframe)[i], MathMin(ha_open, ha_close));
        
        double ha_open;
        double ha_close;
        double ha_high;
        double ha_low;

        ExtLBuffer[i] = ha_low;
        ExtHBuffer[i] = ha_high;
        ExtOBuffer[i] = ha_open;
        ExtCBuffer[i] = ha_close;

        //--- set candle color
        if (ha_open < ha_close)
            ExtColorBuffer[i] = 0.0; // set color DodgerBlue
        else
            ExtColorBuffer[i] = 1.0; // set color Red
    }
    //---
    return (rates_total);
}
//+------------------------------------------------------------------+

I adjusted the code and added the timeframe variable above but commented out the 4 lines of the Copy part as I do not understand this part at all. I don't understand if this is anyhow the way to do it or if it goes into the wrong direction and it is not possible to do it this way? I have to less u nderstanding of the indicators unfortunately

Buy the 'MTF Candles PRO' Technical Indicator for MetaTrader 5 in MetaTrader Market
Buy the 'MTF Candles PRO' Technical Indicator for MetaTrader 5 in MetaTrader Market
  • www.mql5.com
Tool that allows viewing candles in multiple timeframes. This way, it helps the analysis in multiple timeframes. This is another product developed by
 
ammer.jens: but it is not compiling:

Do not post code that will not even compile. Compare your call and the documentation and fix the first, compile, repeat.

Your code
Documentation.
int OnCalculate(
   const int rates_total,
   const int prev_calculated,
   const datetime &time[],
   const double &open[],
   const double &high[],
   const double &low[],
   const double &close[],
   const long &tick_volume[],
   const long &volume[],
   const int &spread[],
   const int timeframe         
){
int OnCalculate (
   const int rates_total,     // size of input time series
   const int prev_calculated, // bars handled in previous call
   const datetime& time[],    // Time
   const double& open[],      // Open
   const double& high[],      // High
   const double& low[],       // Low
   const double& close[],     // Close
   const long& tick_volume[], // Tick Volume
   const long& volume[],      // Real Volume
   const int& spread[]        // Spread
                                              
   );
 
William Roeder #:

Do not post code that will not even compile. Compare your call and the documentation and fix the first, compile, repeat.

Your code
Documentation.

Fixed this error. Please see above, I edited my original post. thank you