Discussion of article "Migrating from MQL4 to MQL5" - page 11

 

Hi Everyone,

do you know how to use ObjectSet(objname,OBJPROP_FIRSTLEVEL+level,value) in MQL5? i tried to search OBJPROP_FIRSTLEVEL but don't find it in MQL5

mql4: 

void _SetFibLevel(string objname, int level, double value, string description)

//+------------------------------------------------------------------+

{

    ObjectSet(objname,OBJPROP_FIRSTLEVEL+level,value);

    ObjectSetFiboDescription(objname,level,description);

}

-----------------------------------

 
vietlh216:

do you know how to use ObjectSet(objname,OBJPROP_FIRSTLEVEL+level,value) in MQL5? i tried to search OBJPROP_FIRSTLEVEL but don't find it in MQL5

mql4: 

void _SetFibLevel(string objname, int level, double value, string description)

//+------------------------------------------------------------------+

{

    ObjectSet(objname,OBJPROP_FIRSTLEVEL+level,value);

    ObjectSetFiboDescription(objname,level,description);

}

-----------------------------------


You can read my blogpost for a ready-made solution.

 
Stanislav Korotky:

You can read my blogpost for a ready-made solution.


Very useful, thanks :)

 
Stanislav Korotky:

You can read my blogpost for a ready-made solution.


Thanks Stanislav Korotky for your solution, but i am not good much in MQL5 and i still don't know how to convert OBJPROP_FIRSTLEVEL to use in MQL5. i don't find the same object property to convert it

in mql4: 

OBJPROP_FIRSTLEVEL+n

210+n

int

Integer value to set/get the value of Fibonacci object level with index n. Index n can be from 0 (number of levels -1), but not larger than 31

but i don't find it in MQL5

ex:  MQL4  :   ObjectSetFiboDescription(objname,level,description);->MQL5: ObjectSetString(0,objname,OBJPROP_LEVELTEXT,level,description);

MQL4: ObjectSet(objname,OBJPROP_FIRSTLEVEL+level,value); -> MQL5: ???

 
vietlh216:

Thanks Stanislav Korotky for your solution, but i am not good much in MQL5 and i still don't know how to convert OBJPROP_FIRSTLEVEL to use in MQL5. i don't find the same object property to convert it

in mql4: 

OBJPROP_FIRSTLEVEL+n

210+n

int

Integer value to set/get the value of Fibonacci object level with index n. Index n can be from 0 (number of levels -1), but not larger than 31

but i don't find it in MQL5

ex:  MQL4  :   ObjectSetFiboDescription(objname,level,description);->MQL5: ObjectSetString(0,objname,OBJPROP_LEVELTEXT,level,description);

MQL4: ObjectSet(objname,OBJPROP_FIRSTLEVEL+level,value); -> MQL5: ???


ah, I find it 

ObjectSetDouble(0,objname,OBJPROP_LEVELVALUE,level,value); 

^^

 
vietlh216:

ah, I find it 

ObjectSetDouble(0,objname,OBJPROP_LEVELVALUE,level,value); 

^^


You can try the following addendum to my include:

class OBJPROP_DOUBLE_BROKER_EXTENDED: public OBJPROP_DOUBLE_BROKER
{
  public:
    OBJPROP_DOUBLE_BROKER_EXTENDED(const ENUM_OBJECT_PROPERTY_DOUBLE property, const int modifier): OBJPROP_DOUBLE_BROKER(property, modifier)
    {
    }
    
    OBJPROP_DOUBLE_BROKER_EXTENDED *operator+(const int add)
    {
      i = add;
      return &this;
    }
};

OBJPROP_DOUBLE_BROKER_EXTENDED OBJPROP_FIRSTLEVEL(OBJPROP_LEVELVALUE, 0);

After this your inital MQL4 code should work as is.

 
Stanislav Korotky:

You can try the following addendum to my include:

After this your inital MQL4 code should work as is.


Now I understood how it work, Thanks Stanislav Korotky so much.

 

I would suggest to replace

string StringConcatenate(..);

by

string StringFormat("",..);

Both functions return a string which makes it easier to replace it under certain conditions!

 
Stanislav Korotky:

You can try the following addendum to my include:

After this your inital MQL4 code should work as is.

I added class OBJPROP_DOUBLE_BROKER_EXTENDED to your ind4to5 include and it seems not to be working as in the latest Metaeditor build 1958 call of ObjectSetDouble(chart_ID,name,OBJPROP_PRICE1,price1) returns compilation error 'ObjectSetDouble' - no one of the overloads can be applied to the function call. Any ideas?

 

I figured out myself that ObjectSetDouble was not included in ind4to5. I added the following code to mqh and it solved the problem.

bool ObjectSetDouble(long chart_id, const string name, const OBJPROP_DOUBLE_BROKER &property, const double value)
{
  return ObjectSetDouble(chart_id, name, property.p, property.i, value);
}