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. - page 2

 
I see that there will be no sense. Sorry, I am leaving this topic.
 

Hint:

indicator buffer binding - the indicator buffer after binding (in OnInit) has a size of "0":



and only at the first call (in OnCalculate) the indicator buffer changes its size by a value equal to:


 
Vladimir Karputov:

Hint:

indicator buffer binding - the indicator buffer after binding (in OnInit) has a size of "0":



and only at the first call (in OnCalculate) the indicator buffer changes its size by a value equal to:


Thanks for hint Vladimir.

I tried to resize arrays in OnInit function but I still get same issues. Please tell me how to fix it. the problem is in ADMI_Calc input(rates_total) or there is no another way to change indicator buffer size second time?

 
Revazi Tchitanava:

Thanks for hint Vladimir.

I tried to resize arrays in OnInit function but I still get same issues. Please tell me how to fix it. the problem is in ADMI_Calc input(rates_total) or there is no another way to change indicator buffer size second time?

... and only at the first call (in OnCalculate) the indicator buffer changes its size by a value equal to: ...

 
Vladimir Karputov:

... and only at the first call (in OnCalculate) the indicator buffer changes its size by a value equal to: ...

okay I got it. what is your suggestion?

 
Revazi Tchitanava :

okay I got it. what is your suggestion?

In the "header" of the program, declare a flag (bool) with the name "first_start" = false. In OnCalculate, at the first start (follow the flag), fill in your arrays.

 
Vladimir Karputov:

In the "header" of the program, declare a flag (bool) with the name "first_start" = false. In OnCalculate, at the first start (follow the flag), fill in your arrays.

please give me small code sample.

thanks you very much for helping.

 
Revazi Tchitanava:

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

I don't want to offend you but :

@Naguisa Unada gives you the reason for the main problem, you didn't listen to him. If you need help don't overlook experimented coders advices, otherwise they will not try to help you a second time. He is right, your buffers are not well declared. you ALWAYS need to declare them in sequence, never change the order like you did. And THERE ARE duplicates !

2° Your code is a total mess. I don't know if it's due to the original mql4 or to your attempts to convert it to mql5. Just some examples :

2.1 What is the point to declare a bunch of variables to later fill an array ? Use arrays from the start for ALL repeating variables, and struct when needed.

   length_1[0] =  extinpADXperiods_1_1;
   length_1[1] =  extinpADXperiods_2_1;
   length_1[2] =  extinpADXperiods_3_1;
   length_1[3] =  extinpADXperiods_4_1;
   length_1[4] =  extinpADXperiods_5_1;
   length_1[5] =  extinpADXperiods_6_1;

2.2 What are these variable names ? Never do that, use understandable variable's name.

void SetADMI(int& cnt, string s, double& main[], double& p[], double& m[], color c1, color c2, color c3, int w1, int w2, int w3)
  {
   SetBuffer(cnt, m, c3, w3, "M_"+s);
   SetBuffer(cnt, p, c2, w2, "P_"+s);
   SetBuffer(cnt, main, c1, w1, "Main_"+s);
  }

Or

               buf_P_1[i]>=buf_M_1[i] && buf_P_2[i]>=buf_M_2[i] && buf_P_3[i]>=buf_M_3[i]
               && buf_M_1[i]<=buf_M_2[i] && buf_M_1[i]<=buf_M_3[i] && buf_Main_1[i]>=buf_M_1[i]

Additionally, why using yet an other function "SetBuffer" where the cnt is modified ?

2.3 Don't code useless function calls. If you really want to use time value for the current symbol/period, use the time[] array from OnCalculate(...)

   if(Candle != iTime(_Symbol, _Period, 0))
     {
      Candle = iTime(_Symbol, _Period, 0);

You don't need time[] at all to check for a new bar. Use for example :

if(prev_calculated!=0 && rates_total!=prev_calculated)
  {
   // We have a new bar  
   ...
  }

2.4 Never do the following, it's a way to failure. Declare your handles in OnInit(), use CopyBuffer() in OnCalculate() or sub-functions of course.

      int handle=iADX(_Symbol, TF[admi], inpADXperiods);
      
      CopyBuffer(handle, 0, bar, i, buf_Main);

ALWAYS check the return value of CopyBuffer() and handle it. You can be sure you WILL have errors from time to time on multi-symbol or multi-timeframe data.

2.5 What is the point to use ArraySetAsSeries() again and again ?

// In calculate function...
      ArraySetAsSeries(buf_Main, true);
      ArraySetAsSeries(buf_P, true);
      ArraySetAsSeries(buf_M, true);

It's just some remarks that comes to my mind while looking at your code.

 
Alain Verleyen:

I don't want to offend you but :

@Naguisa Unada gives you the reason for the main problem, you didn't listen to him. If you need help don't overlook experimented coders advices, otherwise they will not try to help you a second time. He is right, your buffers are not well declared. you ALWAYS need to declare them in sequence, never change the order like you did. And THERE ARE duplicates !

2° Your code is a total mess. I don't know if it's due to the original mql4 or to your attempts to convert it to mql5. Just some examples :

2.1 What is the point to declare a bunch of variables to later fill an array ? Use arrays from the start for ALL repeating variables, and struct when needed.

2.2 What are these variable names ? Never do that, use understandable variable's name.

Or

Additionally, why using yet an other function "SetBuffer" where the cnt is modified ?

2.3 Don't code useless function calls. If you really want to use time value for the current symbol/period, use the time[] array from OnCalculate(...)

You don't need time[] at all to check for a new bar. Use for example :

2.4 Never do the following, it's a way to failure. Declare your handles in OnInit(), use CopyBuffer() in OnCalculate() or sub-functions of course.

ALWAYS check the return value of CopyBuffer() and handle it. You can be sure you WILL have errors from time to time on multi-symbol or multi-timeframe data.

2.5 What is the point to use ArraySetAsSeries() again and again ?

It's just some remarks that comes to my mind while looking at your code.

I have changed several things. I also moved indicator handle to Oninit function but still indicator didn't work. please if you can help me.

thanks you very much

Files:
 
Revazi Tchitanava:

I have changed several things. I also moved indicator handle to Oninit function but still indicator didn't work. please if you can help me.

thanks you very much

Read all the topic once again and come back when you will have understood and changed your code according to all good remarks you received.

Stop wasting people time.

Reason: