On Arrays

 

If you populate an array via a for loop from another indicators offset values (starting with 0), something like:

double TestArray[];

for(i = 0 to 9)

{

TestArray[i] = Indicator(Symbol(), PERIOD_1HR...., i)

}

Is it already in the correct order to use any of the IndicatorOnArray functions? or do you need to use ArraySetAsSeries


Also any idea why there isn't an iADXOnArray or why it's difficult to find one?

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 
iRick: Is it already in the correct order to use any of the IndicatorOnArray functions? or do you need to use ArraySetAsSeries

Also any idea why there isn't an iADXOnArray or why it's difficult to find one?

  1. xOnArray needs to know what direction the values come from [i+(L-1) … i] or [i-(L-1) … i] Set as-series before you populate the array with series data.
  2. Start with the definition of ADX.
              Average Directional Index - ADX Definition and Uses
    It includes ATR. How do you think you can compute ATR (H/L/previous C) from a 1D array? Then there is +DM derived from the highs, -DM from the lows, and ADX from both. How do you think you can compute them from a 1D array?
 
William Roeder:
  1. xOnArray needs to know what direction the values come from [i+(L-1) … i] or [i-(L-1) … i] Set as-series before you populate the array with series data.
  2. Start with the definition of ADX.
              Average Directional Index - ADX Definition and Uses
    It includes ATR. How do you think you can compute ATR (H/L/previous C) from a 1D array? Then there is +DM derived from the highs, -DM from the lows, and ADX from both. How do you think you can compute them from a 1D array?

1. I guess I can just plug in 0, 1, 2, 3,.......... into an array and then put that in iMAOnArray to see what pops out as offset 1, 2, 3... if the returned value gets higher with higher offsets then it's in the right order

2. I have an idea on how to start... plug in 3 Arrays for Close, High and Low values, then loop through them to populate new -DM, +DM and TR arrays then it gets a bit tricker from there.. look like you need to go back twice the period you want to get smoothed values and then more calculations from there.... but I'm at work for the next 8hrs... so was kinda hoping that this was something already done and shared around already... like a lot of the code in CodeBase

 

I'm hoping I can strip out the logic from this:

https://www.mql5.com/en/code/viewcode/7955/130165/ADX.mq4

Altering it to use different High, Low and Close arrays and come up with an iADXOnArray