How to apply ADXWilder to another subwindow indicator?

 
Hi there!

I am trying to apply ADXWilder to another subwindow indicator.  My goal is to calculate ADXWilder based on renko bars from subwindow indicator. I mean in MQL4 we had option like iMAOnArray etc but in MQL5 I couldn't do same. So please help me if you can.

Thanks.

//+------------------------------------------------------------------+
//|                                   ADXW based on Renko Charts.mq5 |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label1"
#property indicator_type2   DRAW_LINE
#property indicator_style2  STYLE_DOT
#property indicator_color2  clrBlue
#property indicator_width2  1
//--- plot Label3
#property indicator_label3  "Label1"
#property indicator_type3   DRAW_LINE
#property indicator_style3  STYLE_DOT
#property indicator_color3  clrYellow
#property indicator_width3  1
//--- input parameters
input int            ADXWPeriod = 14;
//--- indicator buffers
double         ADXW_Buffer[];
double         PDI_Buffer[];
double         NDI_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator setting
   IndicatorSetInteger(INDICATOR_DIGITS, 2);
//--- indicator buffers mapping
   SetIndexBuffer(0, ADXW_Buffer, INDICATOR_DATA);
   SetIndexBuffer(1, PDI_Buffer, INDICATOR_DATA);
   SetIndexBuffer(2, NDI_Buffer, INDICATOR_DATA);
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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    renkoHistory = rates_total;
   int    renkoBoxSize = 100;
   double renkoHighArray[];
   double renkoLowArray[];
   double renkoCloseArray[];
   CheckRenko(rates_total, renkoBoxSize, renkoHighArray, renkoLowArray, renkoCloseArray);
   
   //int    adxwHistory = rates_total;
   int    adxwPeriod = 14;
   double adxwMainArray[];
   double adxwPlusArray[];
   double adxwMinusArray[];
   
   CheckADXW(rates_total, adxwPeriod, adxwMainArray, adxwPlusArray, adxwMinusArray);
   
   Comment("Renko Results: ", "\n",
           "   renkoHighArray: ", NormalizeDouble(renkoHighArray[0], Digits()), "\n",
           "   renkoLowArray: ", NormalizeDouble(renkoLowArray[0], Digits()), "\n",
           "   renkoCloseArray: ", NormalizeDouble(renkoCloseArray[0], Digits()), "\n",
           "\n",
           "ADXW Results: ", "\n",
           "   adxwMainArray: ", NormalizeDouble(adxwMainArray[0], Digits()), "\n",
           "   adxwPlusArray: ", NormalizeDouble(adxwPlusArray[0], Digits()), "\n",
           "   adxwMinusArray: ", NormalizeDouble(adxwMinusArray[0], Digits())
          );
//---
   int limit = rates_total - prev_calculated;
   //--- main loop
   for(int i = limit - 1; i >= 0; i--)
   {
      if (i >= MathMin(5000 - 1, rates_total - 1 - 50)) continue; //omit some old rates to prevent 

      ADXW_Buffer[i] = adxwMainArray[i];
      PDI_Buffer[i] = adxwPlusArray[i];
      NDI_Buffer[i] = adxwMinusArray[i];
   }
//--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+
void CheckRenko(int    renkoHistory,
                int    renkoBoxSize,
                double &renkoHighArray[],
                double &renkoLowArray[],
                double &renkoCloseArray[])
{
//---
   int renkoHandle = iCustom(Symbol(), Period(), "renko", renkoBoxSize);
   if(renkoHandle < 0)
   {
      Print("The creation of iCustom has failed: renkoHandle = ", INVALID_HANDLE, "\n",
            "Runtime error = ", GetLastError());
   }
   //---
   ArraySetAsSeries(renkoHighArray, true);
   CopyBuffer(renkoHandle, 1, 0, renkoHistory, renkoHighArray);
   //---
   ArraySetAsSeries(renkoLowArray, true);
   CopyBuffer(renkoHandle, 2, 0, renkoHistory, renkoLowArray);
   //---
   ArraySetAsSeries(renkoCloseArray, true);
   CopyBuffer(renkoHandle, 3, 0, renkoHistory, renkoCloseArray);
//---
}
//+------------------------------------------------------------------+
void CheckADXW(int    adxwHistory,
               int    adxwPeriod,
               double &adxwMainArray[],
               double &adxwPlusArray[],
               double &adxwMinusArray[])
{
//---
   int adxwHandle = iADXWilder(Symbol(), Period(), adxwPeriod);
   if(adxwHandle < 0)
   {
      Print("The creation of iADXWilder has failed: adxwHandle = ", INVALID_HANDLE, "\n",
            "Runtime error = ", GetLastError());
   }
   //---
   ArraySetAsSeries(adxwMainArray, true);
   CopyBuffer(adxwHandle, 1, 0, adxwHistory, adxwMainArray);
   //---
   ArraySetAsSeries(adxwPlusArray, true);
   CopyBuffer(adxwHandle, 2, 0, adxwHistory, adxwPlusArray);
   //---
   ArraySetAsSeries(adxwMinusArray, true);
   CopyBuffer(adxwHandle, 3, 0, adxwHistory, adxwMinusArray);
//---
}
//+------------------------------------------------------------------+
Files:
renko.mq5  15 kb
 
My second try is this but I get array out of range error in include file. This is link for it(https://www.mql5.com/en/code/1356).

//+------------------------------------------------------------------+
//|                                          ADXW based on Renko.mq5 |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label1"
#property indicator_type2   DRAW_LINE
#property indicator_style2  STYLE_DOT
#property indicator_color2  clrBlue
#property indicator_width2  1
//--- plot Label3
#property indicator_label3  "Label1"
#property indicator_type3   DRAW_LINE
#property indicator_style3  STYLE_DOT
#property indicator_color3  clrYellow
#property indicator_width3  1
//--- input parameters
input int            ADXWPeriod = 14;
//--- indicator buffers
double         ADXW_Buffer[];
double         PDI_Buffer[];
double         NDI_Buffer[];
//--- class with the ADXW indicator calculation methods
#include <IncOnRingBuffer\CADXWOnRingBuffer.mqh>
CADXWOnRingBuffer adxw;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- initialize the ADXW indicator class instance:
   if(!adxw.Init(ADXWPeriod))
   {
      return(INIT_FAILED);
   }
//--- indicator setting
   IndicatorSetInteger(INDICATOR_DIGITS, 2);
//--- indicator buffers mapping
   SetIndexBuffer(0, ADXW_Buffer, INDICATOR_DATA);
   SetIndexBuffer(1, PDI_Buffer, INDICATOR_DATA);
   SetIndexBuffer(2, NDI_Buffer, INDICATOR_DATA);
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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    renkoHistory = rates_total;
   int    renkoBoxSize = 100;
   double renkoHighArray[];
   double renkoLowArray[];
   double renkoCloseArray[];
   CheckRenko(rates_total, renkoBoxSize, renkoHighArray, renkoLowArray, renkoCloseArray);
   
   int    adxwHistory = rates_total;
   int    adxwPeriod = ADXWPeriod;
   double adxwMainArray[];
   double adxwPlusArray[];
   double adxwMinusArray[];
   
   CheckADXW(rates_total, adxwPeriod, adxwMainArray, adxwPlusArray, adxwMinusArray);
   
   Comment("Renko Results: ", "\n",
           "   renkoHighArray: ", NormalizeDouble(renkoHighArray[0], Digits()), "\n",
           "   renkoLowArray: ", NormalizeDouble(renkoLowArray[0], Digits()), "\n",
           "   renkoCloseArray: ", NormalizeDouble(renkoCloseArray[0], Digits()), "\n",
           "\n",
           "ADXW Results: ", "\n",
           "   adxwMainArray: ", NormalizeDouble(adxwMainArray[0], Digits()), "\n",
           "   adxwPlusArray: ", NormalizeDouble(adxwPlusArray[0], Digits()), "\n",
           "   adxwMinusArray: ", NormalizeDouble(adxwMinusArray[0], Digits())
          );
//---
   //adxw.MainOnArray(rates_total, prev_calculated, high, low, close);
   adxw.MainOnArray(rates_total, prev_calculated, renkoHighArray, renkoLowArray, renkoCloseArray);

   int start = 0;
   
   if(prev_calculated == 0)
   {
      start = rates_total - adxw.Size() + 1;
      PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, start);
      ArrayInitialize(ADXW_Buffer, EMPTY_VALUE);
      ArrayInitialize(PDI_Buffer, EMPTY_VALUE);
      ArrayInitialize(NDI_Buffer, EMPTY_VALUE);
   }
   else
   {
      start = prev_calculated - 1;
   }
//---
   for(int i = start; i < rates_total; i++)
   {
      ADXW_Buffer[i] = adxw[rates_total - 1 - i];
      PDI_Buffer[i] = adxw.pdi[rates_total - 1 - i];
      NDI_Buffer[i] = adxw.ndi[rates_total - 1 - i];
   }
//---
//   int limit = rates_total - prev_calculated;
//   //--- main loop
//   for(int i = limit - 1; i >= 0; i--)
//   {
//      if (i >= MathMin(5000 - 1, rates_total - 1 - 50)) continue; //omit some old rates to prevent 
//
//      ADXW_Buffer[i] = adxwMainArray[i];
//      PDI_Buffer[i] = adxwPlusArray[i];
//      NDI_Buffer[i] = adxwMinusArray[i];
//   }
//--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+
void CheckRenko(int    renkoHistory,
                int    renkoBoxSize,
                double &renkoHighArray[],
                double &renkoLowArray[],
                double &renkoCloseArray[])
{
//---
   int renkoHandle = iCustom(Symbol(), Period(), "renko", renkoBoxSize);
   if(renkoHandle < 0)
   {
      Print("The creation of iCustom has failed: renkoHandle = ", INVALID_HANDLE, "\n",
            "Runtime error = ", GetLastError());
   }
   //---
   ArraySetAsSeries(renkoHighArray, true);
   CopyBuffer(renkoHandle, 1, 0, renkoHistory, renkoHighArray);
   //---
   ArraySetAsSeries(renkoLowArray, true);
   CopyBuffer(renkoHandle, 2, 0, renkoHistory, renkoLowArray);
   //---
   ArraySetAsSeries(renkoCloseArray, true);
   CopyBuffer(renkoHandle, 3, 0, renkoHistory, renkoCloseArray);
//---
}
//+------------------------------------------------------------------+
void CheckADXW(int    adxwHistory,
               int    adxwPeriod,
               double &adxwMainArray[],
               double &adxwPlusArray[],
               double &adxwMinusArray[])
{
//---
   int adxwHandle = iADXWilder(Symbol(), Period(), adxwPeriod);
   if(adxwHandle < 0)
   {
      Print("The creation of iADXWilder has failed: adxwHandle = ", INVALID_HANDLE, "\n",
            "Runtime error = ", GetLastError());
   }
   //---
   ArraySetAsSeries(adxwMainArray, true);
   CopyBuffer(adxwHandle, 0, 0, adxwHistory, adxwMainArray);
   //---
   ArraySetAsSeries(adxwPlusArray, true);
   CopyBuffer(adxwHandle, 1, 0, adxwHistory, adxwPlusArray);
   //---
   ArraySetAsSeries(adxwMinusArray, true);
   CopyBuffer(adxwHandle, 2, 0, adxwHistory, adxwMinusArray);
//---
}
//+------------------------------------------------------------------+
The class for drawing the ADX Wilder using the ring buffer
The class for drawing the ADX Wilder using the ring buffer
  • www.mql5.com
File of the CADXWOnRingBuffer.mqh class should be placed in the IncOnRingBuffer folder that need to be established in MQL5\Include\. Two files with the examples used by the class from this folder are attached to the description. File with the class of the ring buffer and the class of Moving Average also must be in this folder. To get the...
Reason: