Refresh Chart Data for Indicator Use

To add comments, please log in or register
Richard Read
343
Richard Read  

Hi there,

I am trying to get indicator data from a chart other than the one that I have my EA/Indicator/Script active on. The problem is, if that chart is currently open, the data is accurate. However if that chart is closed, the data is more often than not inaccurate.

I am testing this using the following script:

//+------------------------------------------------------------------+
//|                                                       values.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#include <WinUser32.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   string cur="USDTHB";
   for(int i=0;i<20;i++)
     {
      double val=iMA(cur,15,10,0,MODE_SMA,0,1);
      Alert(i+" "+val);
      if(val>0)
         break;
     }
  }
//+------------------------------------------------------------------+

Say I have not accessed "USDTHB" for a long time, and I have the chart currently closed.

The first time I run the script, I get the following info:


It will return 0 hundreds of times...

However, if I immediately run the script again:

It produces a value the first time.

So somewhere between the first and second attempts of the script, the chart data for USDTHB updated, allowing me to get data on the second run.

My question is, is there a way I can "force" this update of information, to ensure that I can get values n the first run?

Thanks in advance.

Richard

William Roeder
20207
William Roeder  
Richard Read: However if that chart is closed, the data is more often than not inaccurate.
On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors.
          Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
To add comments, please log in or register