I have Developed Multi ADX indicator in mql4 and now I am trying to run it on mql5. I have converted everything but i get array out of range error.

 
Revazi Tchitanava :
please help me. problem is in:
array out of range in 'TurboADMI.mq5' (1800,25)

thanks in advanced

Write a simple version: for only one indicator and only for one tafframe. Remove from the code everything that has the name "MQL4". After that, you can put your code in order.


Added: I will be happy to help you get rid of the MQL4 heritage.

 
Vladimir Karputov:

Write a simple version: for only one indicator and only for one tafframe. Remove from the code everything that has the name "MQL4". After that, you can put your code in order.


Added: I will be happy to help you get rid of the MQL4 heritage.

Hello. thanks for your respond. I used this article to covert indicator to MQL5: https://www.mql5.com/en/articles/81

I added screenshot where you can see that its draws lines but then get array out of range issue. thats my problem.

I will try to do what you requested.

thanks


Migrating from MQL4 to MQL5
Migrating from MQL4 to MQL5
  • www.mql5.com
Practical Application Of Databases For Markets Analysis Working with data has become the main task for modern software - both for standalone and network applications. To solve this problem a specialized software were created. These are Database Management Systems (DBMS), that can structure, systematize and organize data for their computer...
 

How to do better: see an example of an indicator based on ADX: iADX .

Here is the code (I threw out everything unnecessary from the example):

//+------------------------------------------------------------------+
//|                                                    Demo_iADX.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.001"
#property description "The indicator demonstrates how to obtain data"
#property description "of indicator buffers for the iADX technical indicator."
#property description "A symbol and timeframe used for calculation of the indicator,"
#property description "are set by the symbol and period parameters."
#property description "The method of creation of the handle is set through the 'type' parameter (function type)."

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3
//--- plot ADX
#property indicator_label1  "ADX"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrLightSeaGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot DI_plus
#property indicator_label2  "DI_plus"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrYellowGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot DI_minus
#property indicator_label3  "DI_minus"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrWheat
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- input parameters
//--- ADX
input int               Inp_ADX_adx_period= 14;          // ADX: averaging period
//--- indicator buffers
double         ADXBuffer[];
double         DI_plusBuffer[];
double         DI_minusBuffer[];
int    handle_iADX;        // variable for storing the handle of the iADX indicator
int    bars_calculated=0;  // we will keep the number of values in the Average Directional Movement Index indicator
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- assignment of arrays to indicator buffers
   SetIndexBuffer(0,ADXBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,DI_plusBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,DI_minusBuffer,INDICATOR_DATA);
//--- indicator digits
   IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- create handle of the indicator iADX
   handle_iADX=iADX(Symbol(),Period(),Inp_ADX_adx_period);
//--- if the handle is not created
   if(handle_iADX==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code
      PrintFormat("Failed to create handle of the iADX indicator for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early
      return(INIT_FAILED);
     }
//--- normal initialization of the indicator
   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[])
  {
//--- number of values copied from the iADX indicator
   int values_to_copy;
//--- determine the number of values calculated in the indicator
   int calculated=BarsCalculated(handle_iADX);
   if(calculated<=0)
     {
      PrintFormat("BarsCalculated() returned %d, error code %d",calculated,GetLastError());
      return(0);
     }
//--- if it is the first start of calculation of the indicator or if the number of values in the iADX indicator changed
//---or if it is necessary to calculated the indicator for two or more bars (it means something has changed in the price history)
   if(prev_calculated==0 || calculated!=bars_calculated || rates_total>prev_calculated+1)
     {
      //--- if the iADXBuffer array is greater than the number of values in the iADX indicator for symbol/period, then we don't copy everything
      //--- otherwise, we copy less than the size of indicator buffers
      if(calculated>rates_total)
         values_to_copy=rates_total;
      else
         values_to_copy=calculated;
     }
   else
     {
      //--- it means that it's not the first time of the indicator calculation, and since the last call of OnCalculate()
      //--- for calculation not more than one bar is added
      values_to_copy=(rates_total-prev_calculated)+1;
     }
//--- fill the array with values of the Average Directional Movement Index indicator
//--- if FillArraysFromBuffer returns false, it means the information is nor ready yet, quit operation
   if(!FillArraysFromBuffers(ADXBuffer,DI_plusBuffer,DI_minusBuffer,handle_iADX,values_to_copy))
      return(0);
//--- memorize the number of values in the Average Directional Movement Index indicator
   bars_calculated=calculated;
//--- return the prev_calculated value for the next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Filling indicator buffers from the iADX indicator                |
//+------------------------------------------------------------------+
bool FillArraysFromBuffers(double &adx_values[],      // indicator buffer of the ADX line
                           double &DIplus_values[],   // indicator buffer for DI+
                           double &DIminus_values[],  // indicator buffer for DI-
                           int ind_handle,            // handle of the iADX indicator
                           int amount                 // number of copied values
                          )
  {
//--- reset error code
   ResetLastError();
//--- fill a part of the iADXBuffer array with values from the indicator buffer that has 0 index
   if(CopyBuffer(ind_handle,0,0,amount,adx_values)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("Failed to copy data from the iADX indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      return(false);
     }

//--- fill a part of the DI_plusBuffer array with values from the indicator buffer that has index 1
   if(CopyBuffer(ind_handle,1,0,amount,DIplus_values)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("Failed to copy data from the iADX indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      return(false);
     }

//--- fill a part of the DI_minusBuffer array with values from the indicator buffer that has index 2
   if(CopyBuffer(ind_handle,2,0,amount,DIminus_values)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("Failed to copy data from the iADX indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      return(false);
     }
//--- everything is fine
   return(true);
  }
//+------------------------------------------------------------------+
//| Indicator deinitialization function                              |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
Documentation on MQL5: Technical Indicators / iADX
Documentation on MQL5: Technical Indicators / iADX
  • www.mql5.com
//|                                                    Demo_iADX.mq5 | //|                        Copyright 2011, MetaQuotes Software Corp. | //|                                              https://www.mql5.com | "The method of creation of the handle is set through the 'type' parameter (function type...
Files:
Demo_iADX.mq5  16 kb
 
Vladimir Karputov:

How to do better: see an example of an indicator based on ADX: iADX .

Here is the code (I threw out everything unnecessary from the example):

I am calling in OnCalculate function ADMI_Calc 3 times. if I comment 2 of them indicator runs correctly but my target is to run all 3 to get same results as I am getting in mt4 terminal. if I run only 1 ADMI_Calc i dont get array out of range error but I also dont get fully working indicator. I have deleted MQ4 code from it so please check. I will also add some screenshots to show you whats the problem is.

thanks for you helping.

Files:
 
Line 469.            The "cnt" should start at 0.
Line 471 ~ 490.   Buffer0 ~ buffer53 is used.
Line 494 ~ 540.   You should use buffer54 and above. (Some buffer numbers are duplicated here)

The "Array out of range" error disappears after modifying them, but it does not work properly. As Vladimir Karputov said, I think it is better to rewrite it in the official MQL5 format.

You should program the most basic parts first, and then expand them by checking how they work. Writing a large program from scratch usually fails.
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
  • www.mql5.com
Some technical indicators have several buffers drawn in the chart. Numbering of indicator buffers starts with 0. When copying indicator values using the CopyBuffer() function into an array of the double type, for some indicators one may indicate the identifier of a copied buffer instead of its number.
 
Revazi Tchitanava :

I am calling in OnCalculate function ADMI_Calc 3 times. if I comment 2 of them indicator runs correctly but my target is to run all 3 to get same results as I am getting in mt4 terminal. if I run only 1 ADMI_Calc i dont get array out of range error but I also dont get fully working indicator. I have deleted MQ4 code from it so please check. I will also add some screenshots to show you whats the problem is.

thanks for you helping.

It’s too early for you to write multi-timeframe indicators.

My advice remains the same - on the basis of the skeleton ( ), gradually increase the meat of your indicator. BUT: be sure to FIRST ask, then DO.

I have Developed Multi ADX indicator in mql4 and now I am trying to run it on mql5. I have converted everything but i get array out of range error.
I have Developed Multi ADX indicator in mql4 and now I am trying to run it on mql5. I have converted everything but i get array out of range error.
  • 2019.11.14
  • www.mql5.com
please help me. problem is in: array out of range in 'TurboADMI.mq5' (1800,25) thanks in advanced...
 
Naguisa Unada:
Line 469.            The "cnt" should start at 0.
Line 471 ~ 490.   Buffer0 ~ buffer53 is used.
Line 494 ~ 540.   You should use buffer54 and above. (Some buffer numbers are duplicated here)

The "Array out of range" error disappears after modifying them, but it does not work properly. As Vladimir Karputov said, I think it is better to rewrite it in the official MQL5 format.

You should program the most basic parts first, and then expand them by checking how they work. Writing a large program from scratch usually fails.

thanks for your reply. please could you send me code what you have changed? the problem is that on second call of ADMI_Calc it returns array with size of 0 and I don't understand why and how it change array size. thats the reason why I am getting array out of range error.what about buffers I dont think there is any duplicate buffers because I am using 3 times 6 ADX with has 3 buffers to total buffers of adx must be equal to 54. what about another buffers I am using them for visualization of strong or weak trends. I have converted lots of multi timeframe indicators from mql4 to mql5 but this is first time when I get such issue. so if you can please tell me what I am doing wrong and why it change array size to 0.

thanks

 
Vladimir Karputov:

It’s too early for you to write multi-timeframe indicators.

My advice remains the same - on the basis of the skeleton ( ), gradually increase the meat of your indicator. BUT: be sure to FIRST ask, then DO.

Vladimir I dont think that its too early for me to write multi-timeframe indicator as I have developed lots of them. I just asked for help. so if you can please tell me why array size are changed to 0 on 2nd call even if I am doing array resize?

 
Revazi Tchitanava :

Vladimir I dont think that its too early for me to write multi-timeframe indicator as I have developed lots of them. I just asked for help. so if you can please tell me why array size are changed to 0 on 2nd call even if I am doing array resize?

Simplify your example. I gave you a skeleton. Going beyond the bounds of the array is a gross error.

 
Vladimir Karputov:

Simplify your example. I gave you a skeleton. Going beyond the bounds of the array is a gross error.

I can't simplify it because then I don't get this error. as I said I am calling 3 times ADMI_Calc in OnCalculate function. if I will call only one then it starts working and dont get array out of range error. but my goal is to get all 3 work. as I said above on 2 call of ADMI_Calc arrays go resized to 0 and thats why I am getting array out of range error. so if you can explain why it resizes arrays(several from 6 not all as you can see in image what I have send above) to 0 that will be great.

thanks for your helping