Array with OBJ_* and OBJPROP_* possible?`

 

Good evening!

is it possible to create an array of OBJ_* (such as OBJ_RECTANGLE, OBJ_TREND) or OBJPROP_* (such as OBJPROP_BACK, OBJPROP_COLOR)?

I could not yet figure out what type the array has to be of, if it is possible at all.

Best!

 
algotrader01:

Good evening!

is it possible to create an array of OBJ_* (such as OBJ_RECTANGLE, OBJ_TREND) or OBJPROP_* (such as OBJPROP_BACK, OBJPROP_COLOR)?

I could not yet figure out what type the array has to be of, if it is possible at all.

Best!

        ENUM_OBJECT objs[7];
        
        objs[0] = OBJ_VLINE;
        objs[1] = OBJ_HLINE;
        objs[2] = OBJ_TREND;
        ...
 
Anthony Garot:
Nothing in impossible
 
Big thank you, Anthony! works like a charme. I knew of enums but not of the ENUM_OBJECT enumartion :-)
 
algotrader01:
Big thank you, Anthony! works like a charme. I knew of enums but not of the ENUM_OBJECT enumartion :-)

It's mentioned here (but it's easy to miss):

https://www.mql5.com/en/docs/constants/objectconstants/enum_object

When a graphical object is created using the ObjectCreate() function, it's necessary to specify the type of object being created, which can be one of the values of the ENUM_OBJECT enumeration. Further specifications of object properties are possible using functions for working with graphical objects.

 
Cool, thank you for pointing that out. Still not yet an expert in MQL5 so such things that might be obvious to others are not for beginners :-)
 

You can also simplify it by using an array initialization list. 


ENUM_OBJECT objs[] = {
    OBJ_VLINE,
    OBJ_HLINE,
    OBJ_TREND
};
 
Good morning Nicholi!
I could derive that initialization from the "normal" array behaviour but still thank you for pointing that out. Might be useful to others for sure :-)
 
algotrader01:
Good morning Nicholi!
I could derive that initialization from the "normal" array behaviour but still thank you for pointing that out. Might be useful to others for sure :-)

I'm not sure what you mean... That's how you should initialize an array when you know all of the values prior to run-time. 

It goes for anything...


string working_symbols[] = {"EURUSD", "USDJPY, "GPBUSD"};
ArrayPrint(working_symbols);
 
well, that is what I meant :-)
 
algotrader01:
well, that is what I meant :-)

oh... lol. Gotcha. :)