INDICATOR_DATA = 0
INDICATOR_COLOR_INDEX = 1
INDICATOR_CALCULATIONS = 2
ahh they are ints, nice, thanks qjol .. so are ENUMs a similar thing to a #define ?
example function to initialize buffers
So I might want to pass ENUM_INDEXBUFFER_TYPE as INDICATOR_DATA, or as INDICATOR_CALCULATIONS but I cant use it like a variable data type, is there another way of doing this or do I need to learn something in mql5 ?
void initbuffer(double &array[], ENUM_INDEXBUFFER_TYPE buffertype, int type=DRAW_NONE, int style=EMPTY,int width=EMPTY) { SetIndexBuffer(Buffers,array,buffertype); SetIndexStyle(Buffers, type, style, width); Buffers++; }
Thanks angevoyaguer it seems to work both ways, I found it also works if you declare it as an int in the function parameters and pass either the integer value or pass it as INDICATOR_DATA, INDICATOR_CALCULATIONS etc in the function call. SetIndexBuffer also accepts either the integer value or the ENUM identifier for the the third parameter.
So I am thinking ENUMs are like #defines, you can use either the formal identifier or the value it represents is that correct ?
void initbuffer(double &array[], int buffertype, int type=DRAW_NONE, int style=EMPTY,int width=EMPTY) { SetIndexBuffer(Buffers,array,buffertype); SetIndexStyle(Buffers, type, style, width); Buffers++; } InitBuffer(drawbuffer1,INDICATOR_DATA,DRAW_LINE); InitBuffer(calcbuffer1,INDICATOR_CALCULATIONS); InitBuffer(calcbuffer2,INDICATOR_CALCULATIONS);
Either way I like it, no need to simulate extra buffers for calculating anymore, SetIndexBuffer() does it all :)
Thanks angevoyaguer it seems to work both ways, I found it also works if you declare it as an int in the function parameters and pass either the integer value or pass it as INDICATOR_DATA, INDICATOR_CALCULATIONS etc in the function call. SetIndexBuffer also accepts either the integer value or the ENUM identifier for the the third parameter.
So I am thinking ENUMs are like #defines, you can use either the formal identifier or the value it represents is that correct ?
Either way I like it, no need to simulate extra buffers for calculating anymore, SetIndexBuffer() does it all :)
ENUMs are not exactly as #define :
- #define are preprocessor directive, before compiling the identifier is replaced by its value (expression).
- ENUMs are managed by the compiler, the advantage of using enums is that the compiler will check it :
If you declare a function this way :
void initbuffer(double &array[], ENUM_INDEXBUFFER_TYPE buffertype, int type=DRAW_NONE, int style=EMPTY,int width=EMPTY)
If you try to call it with :
initbuffer(array[],18);
The compiler will catch 18 as a invalid value for this parameter. If you declared it as an int the compiler don't worry. To resume an ENUM is an int, but an int is not an ENUM.
- Also when you declare an ENUMs values are automatically incremented (or you can set the values yourself).
Old mql4 allowed | // double iMA( string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift) ... iMA(NULL,0, -1, 0, PRICE_CLOSE, MODE_SMA, 0); ^TF ^ma_method ^applied_price |
New mql4 won't compile | double ima(string symbol, int timeframe, ENUM_TIMEFRAMES ma_period, int ma_shift, ENUM_MA_METHOD ma_method, ENUM_APPLIED_PRICE applied_price, int shift); ... iMA(NULL,0, -1, 0, PRICE_CLOSE, MODE_SMA, 0); ^TF ^ ma_method ^ applied_price int not ENUM_TIMEFRAMES ^ ENUM_APPLIED_PRICE is not ENUM_MA_METHOD ^ ENUM_MA_METHOD is not ENUM_APPLIED_PRICE |

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
example function to initialize buffers
So I might want to pass ENUM_INDEXBUFFER_TYPE as INDICATOR_DATA, or as INDICATOR_CALCULATIONS but I cant use it like a variable data type, is there another way of doing this or do I need to learn something in mql5 ?