New version of the MetaTrader 4 Platform build 1350

MetaQuotes
Moderator
239257

The MetaTrader 4 platform update will be released on Thursday, October 14, 2021. This version provides error fixes and platform stability improvements.

The update will be available through the Live Update system.

Sergey Golubev
Moderator
123754
Sergey Golubev  

I updated MT4 instances to build 1350:

Enau
104
Enau  

the date of metaeditor is wrong

Alain Verleyen
42646
Enau #:

the date of metaeditor is wrong

It's not.
Alexander Martinez
2775

I reported this bug last time, but I finally figured out what causes it, so I'm here to report it again.

Issue: For a channel, calling ObjectGetValueByTime with line_id=1 returns an incorrect value if you check the object type beforehand using ObjectGetInteger instead of ObjectType.

I hope you guys look into it because there's no way to call ObjectGetValueByTime on multi-line object in another chart if you need to check the object type.

Here's the code, I left a comment for you to alternate between the commented and uncommented lines to check for yourselves.

To test it, just create an Equidistant Channel, select it, then move it around. It will make a Comment displaying the price. You'll see that the bug displays a wrong value.

#property strict
#property indicator_chart_window

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {
  return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]) {

  return (rates_total);                
}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {
  CheckBoundary();
}

void CheckBoundary() {
  for (int i = ObjectsTotal() - 1; i >= 0; i--) {
    const string name = ObjectName(i);
    
    //--- Alternate between these two lines to see the bug
    const long type   = BuggedType(name);
    //const int type    = WorkingType(name);
    
    if (type == OBJ_CHANNEL) {
      const double price  = ObjectGetValueByTime(0, name, Time[0], 1);
      
      Comment("Price: ", DoubleToStr(price, Digits));
    }
  }
}

int WorkingType(const string obj_name) {
  return ObjectType(obj_name);
}

long BuggedType(const string obj_name, const long chart_id=0) {
  return ObjectGetInteger(chart_id, obj_name, OBJPROP_TYPE);
}