Error number 1:
Never put your hands into the name of arrays.
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[]) {
There is a regulation and only it is correct:
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[]) {
Error 2:
when working with 'double', you cannot divide by '2' - you need to divide by '2.0'.
Error 3:
You have division operations — but you never check division by zero.
Like that:
You also seem to have added a third buffer. When I was browsing the forum earlier I saw a post mentioning always having at least 2 buffers. (He wasn't clear as to why and the post was old anyway) Is INDICATOR_CALCULATIONS required to process the buffer values in an EA?
Error 2:
when working with 'double', you cannot divide by '2' - you need to divide by '2.0'.
You can divide by 2, this not an error. You could even use doublevar=2/doubleconst and the result would still be correct
Is ?0.0 all I need to avoid dividing by 0?
No, a division by zero would stop any EA or indicator and would not return such results.
I used iCustom to get the handler from the indicator:
This is pretty much the only place where I think I could be making an error. The documentation for iCustom has parameters field, but it says that if they are left empty, the indicator will have default values, which I checked the indicator and it looks like it has defaults:
Then I used CopyBuffer on the custom indicator the same way I used it on a built-in indicator:
I did not read the whole code, but I stumbled at these sentences. iCustom initiates the background calculation of an indicator, this does NOT mean, that the data is ready when you try to access it and this is where zero values could come from. Now you may ask, when this data is ready, but the answer is: Nobody knows, it's available when it's done. Sleep(n) won´t help you here. My experience is, that the only solutions is an asynchronous check, based on a timer.
You also seem to have added a third buffer. When I was browsing the forum earlier I saw a post mentioning always having at least 2 buffers. (He wasn't clear as to why and the post was old anyway) Is INDICATOR_CALCULATIONS required to process the buffer values in an EA?
The third buffer stores the calculated values.
I made a third buffer on purpose — I fixed your mistake: you saved the value to a variable.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I managed to get input from a built-in indicator, so now I wanted to try with a custom made indicator. I downloaded an indicator off the internet and put it in MT5. It successfully shows the values in a buffer.
[picture of the indicator with buffer.] (For some reason it doesn't accept my link. But trust me it shows an actual value)
I used iCustom to get the handler from the indicator:
This is pretty much the only place where I think I could be making an error. The documentation for iCustom has parameters field, but it says that if they are left empty, the indicator will have default values, which I checked the indicator and it looks like it has defaults:
Then I used CopyBuffer on the custom indicator the same way I used it on a built-in indicator:
The problem is, with the custom indicator, I get an array, that is full of 0.0 values, whereas with the built-in one I get actual values. Both indicators have buffers.
I've attached the custom indicator in case you need to look into it, but I'm fairly certain I'm the one not doing something correctly, due to there being legit values in the buffer when I place the indicator in a graph.
I also have another question, which is when copying with CopyBuffer into an array called arrBuffer[].
Is the value of arrBuffer[0] going to be the latest (right-most) value of the indicator, or the oldest (left-most) value?