Cnotey: I need to access the last 14 values of a variable in the code below.
double candle_height[](double open, double high, double low, double close)
ShadowsBuffer[i] = (shadow_height(open[i], high[i], low[i], close[i])/C
The variables passed to OnCalculate, are not guaranteed to be in series order (newest = 0.) The Predefined Variables - MQL4 Reference (e.g. Close[]) are.double candle_height[](double open, double high, double low, double close)
Bogus. You need to access n values, but you pass single values, so it can't possibly work. Just use the predefined's and you only have to pass the starting index.double candle_height_raw[] = CHraw - shadow_height_raw;
You have a empty array, it can't be assigned to. Your function has no loop to fill the array, so can't work.I don't use any of the arguments. Use the predefined's int limit=rates_total-prev_calculated; if(prev_calculated>0) limit++; for(int i=0; i<limit; i++)
You have a look back of 14 ("last 14 values") you must handle the it to avoid error 4002. int counted = IndicatorCounted(); for(int i=Bars -1 -MathMax(14, counted); i >= 0; --i){ :
WHRoeder:
Thank you for your help. Do I still need to loop through to fill the predefined variables (e.g. Close[]) to fill the values? Or do I just give it Close[i..14]?
- The variables passed to OnCalculate, are not guaranteed to be in series order (newest = 0.) The Predefined Variables - MQL4 Reference (e.g. Close[]) are.
- Bogus. You need to access n values, but you pass single values, so it can't possibly work. Just use the predefined's and you only have to pass the starting index.
- You have a empty array, it can't be assigned to. Your function has no loop to fill the array, so can't work.
I don't use any of the arguments. Use the predefined's You have a look back of 14 ("last 14 values") you must handle the it to avoid error 4002.
Entry #5 didn't get saved. I don't know what you are trying to compute; I can't follow your code. Try something like:
double average_body_percent(int shift, int len=14){ double sum=0; for(int i=shift + len - 1; i >= shift; --i){ double body = MathAbs(Open[i] - Close[i]); sum += body / (High[i] - Low[i]); } return sum / len * 100; }
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
Hi there,
New to the MQL4 language and C++ in general. I am a C# coder by nature, so as you can imagine MQL4 is being a bit difficult. My normal MQL4 coder is out of town for a week, so I need a bit of help with something.
I am trying to loop through the last [X] number of indexes for a defined variable. I need to access the last 14 values of a variable in the code below.
I am not expecting someone to write the code for me. Just point me in the correct direction.