Best way to apply iCustom to an array?

 

Hi folks, apologies if I have posted this in the wrong section of the forum.


I'm relatively new to MQL4 and am having some trouble applying values from a custom indicator to an array in my EA. Sometimes it works fine, and other times it doesn't.


At the moment I'm using: #define CUST1 0 to define the variable and then CUST1[history][buffer_size] = icustom..... to call the custom indicator. This works well for me most of the time and I like doing it this way as I can look back to CUST1[history][NOW-1] etc etc. Sometimes however, the value after the declaration is returned (i.e. 0 in this case) will the indicator is plotted correctly on the chart.


I'm sure I'm going about this the wrong way....


Thanks in advance,


FB

 
FBarrone:

At the moment I'm using: #define CUST1 0

That defines CUST1 as constant 0 for the preprocessor (MQL4 Reference -> Basics -> Preprocessor -> Constant declaration), which means before compilation all instances of CUST1 in the code will be replaced by 0. That doesn't make any sense. Are u sure u got that right?

 
gordon:

That defines CUST1 as constant 0 for the preprocessor (MQL4 Reference -> Basics -> Preprocessor -> Constant declaration), which means before compilation all instances of CUST1 in the code will be replaced by 0. That doesn't make any sense. Are u sure u got that right?

Hi Gordon, yes, that's what I'm doing, but like you said, I think it's probably wrong.... I picked it up somewhere from another EA I was using, but can't figure out how best to do a different way.

How would you recommend I call a custom indicator and apply it to an array in my EA?


FB

 
FBarrone:

Hi Gordon, yes, that's what I'm doing, but like you said, I think it's probably wrong.... I picked it up somewhere from another EA I was using, but can't figure out how best to do a different way.

How would you recommend I call a custom indicator and apply it to an array in my EA?


FB

I am not sure what u r trying to do, but generally u need to declare the array properly first. If u haven't read it yet -> https://book.mql4.com/variables/arrays.

Reason: