Array with OBJ_* and OBJPROP_* possible?`

To add comments, please log in or register
algotrader01
114
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!

Anthony Garot
1826
Anthony Garot  
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;
        ...
ayunbokhai Emmanuel
11
ayunbokhai Emmanuel  
Anthony Garot:
Nothing in impossible
algotrader01
114
algotrader01  
Big thank you, Anthony! works like a charme. I knew of enums but not of the ENUM_OBJECT enumartion :-)
Anthony Garot
1826
Anthony Garot  
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.

algotrader01
114
algotrader01  
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 :-)
nicholi shen
1874
nicholi shen  

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


ENUM_OBJECT objs[] = {
    OBJ_VLINE,
    OBJ_HLINE,
    OBJ_TREND
};
algotrader01
114
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 :-)
nicholi shen
1874
nicholi shen  
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);
algotrader01
114
algotrader01  
well, that is what I meant :-)
nicholi shen
1874
nicholi shen  
algotrader01:
well, that is what I meant :-)

oh... lol. Gotcha. :)

To add comments, please log in or register