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
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hint:
Hint:
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?
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: ...
... 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?
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.
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.
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 :
1° @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 don't want to offend you but :
1° @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
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.