Search code examples
mql4

How to check which 1 is the oldest object or price?


enter image description here

On the picture above, blue horizontal line object is the oldest object, how to get it?

something like :

if (blue < yellow) &&  (blue < pink) &&  (blue < red)) { printf ("blue is the oldest object"); }

Do I need to use ibarshift? May I have example of code?


Solution

  • string oldestObjectName="", name;
    datetime oldestObjectDate=INT_MAX, tmpDate;
    for(int i=ObjectsTotal()-1;i>=0;i--)
    {
       name=ObjectName(i);
       tmpDate=ObjectGetInteger(0,name,OBJPROP_TIME1);
       if(tmpDate<oldestObjectDate)
       {
          oldestObjectDate=tmpDate;
          oldestObjectName=name;
       }
    }
    printf("oldest object is %s, its time1=%s",oldestObjectName,TimeToString(oldestObjectDate));