mql4mt4

MT4 Expert Advisor EA issue with updating price for offline chart


The following script uses a timer and works well in normal charts to comment current candle closing price every 1 second on chart. However, on offline chart, it only loads the closing price once and does not update it every second. Here is the code:

void OnTimer()
  {
  int m=TimeSeconds(TimeLocal());


  double CloseValue = Close[0]; //Current Candle Close Value
  string CloseValueString = DoubleToString(CloseValue,5); //Current price 


  Comment(
  "Current value :",CloseValueString,"\n",
  "Candle time :",m
  );
}

enter image description here


Solution

  • Solved by adding the Refreshrates() function which updates data for the offline chart at the end of my function:

    void OnTimer()
    {
     int m=TimeSeconds(TimeLocal());
    
    
      double CloseValue = Close[0]; //Current Candle Close Value
      string CloseValueString = DoubleToString(CloseValue,5); //Current price 
    
    
      Comment(
      "Current value :",CloseValueString,"\n",
      "Candle time :",m
      );
    RefreshRates();
    }