Am I wrong or is it the new mql5 build 1915? - page 2

 
Carl Schreiber:
I searched for iCustom and asynchronous - but didn't found anything. :(
Do you remember additional terms I can search for?

You can read all my posts, it's somewhere ;-)

Let me check for you...

 
 

I've got it:

//+------------------------------------------------------------------+
//|                                           Test_HaveAllQuotes.mq5 |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   int nB, Hdl = iCustom(_Symbol,_Period, "HaveAllQuotes",0,  0,0 );
   while (!IsStopped()) {
      nB  = BarsCalculated(Hdl);
      Print("Hdl ",Hdl,"  nB ",nB,"  er: ",_LastError );
      if ( nB >= 100000 ) break;
      else Sleep(500);
      ResetLastError();
   }
   Print("DONE :)  Hdl ",Hdl,"  nB ",nB,"  er: ",_LastError );
  }
//+------------------------------------------------------------------+

This prints:

2018.10.20 23:52:51.204    HaveAllQuotes (GBPUSD,H1)    HaveAllQts Sym: GBPUSD  Per: PERIOD_H1 tL: 2018.10.20 23:52:51  TermMax: 100000000   _NoBars 100000  rts_Tot: 101825  prvClc 0 => false
2018.10.20 23:52:51.692    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  nB 101825  er: 0
2018.10.20 23:52:51.692    Test_HaveAllQuotes (GBPUSD,H1)    DONE :)  Hdl 10  nB 101825  er: 0

I guess that the first call of BarsCalculated(Hdl) starts the first calculation of the indicator so that the second call in the loop can return a value greater Zero.

Thanks and a nice weekend!

Calli

 
Carl Schreiber:

I've got it:

This prints:

Thanks and a nice weekend!

Calli

Yes on a script use a loop. On an EA, use iCustom in OnInit() everytime it's possible, it not you can use a loop (I don't recommend it), a timer or just wait next tick and try again.

For reference here is the topic I was thinking to.

 
Carl Schreiber:

I guess that the first call of BarsCalculated(Hdl) starts the first calculation of the indicator so that the second call in the loop can return a value greater Zero.

I've had some luck with something like the following. I don't think BarsCalculated() actually requests data from the server. (See this forum post that discusses this for Bars()). But CopyTime() definitely requests data from the server. So, the following code will load missing data, without using Sleep(), so long as ticks are coming in.

I pulled this out of existing code, so it does not compile or run as it is. Caveat emptor.

int OnCalculate( . . . )
{    
    if(IsStopped()) return false; //Checking for stop flag

    // not all data may be calculated
    int calculated;
    ResetLastError();
    calculated=BarsCalculated(FastHandle);
    if(calculated<rates_total)
    {
        PrintFormat("BarsCalculated() loading data for MA (%d) [%s] (%d bars < %d needed). Code [%d].",
                    InpMaFastPeriod,
                    symbol,
                    calculated,
                    rates_total,
                    GetLastError());

        WrapCopyTimeSingle(time[0], symbol, 0);
        return 0;            // Go back and wait for next tick
    }
}

. . .

datetime WrapCopyTimeSingle(const datetime bartime, const string symbol = NULL, const ENUM_TIMEFRAMES tf = 0)
{
    datetime tmpTimeArray[1];    // Intermediate array for the time of the bar.

    ResetLastError();
    int copied = CopyTime(symbol,tf,bartime,1,tmpTimeArray);    // Requesting only 1 bar!

    if ( copied == -1 )
    {
        // This is NOT an error. This is expected behavior while data
        // is pulled from the broker. Even so, I made it DEBUG level 1.
        PrintFormat("%s(): count [-1] symbol [%s] TF [%s] bartime [%s]. Error [%d]",
                    __FUNCTION__,
                    symbol,
                    EnumToString(tf),
                    TimeToString(bartime),
                    GetLastError());

        // This is OK. I'll just let OnCalculate() know, and it will run that bar again.
        return NULL;
    }

    PrintFormat("%s(): [%s] copied count [%d] TF [%s] value [%s]",
                __FUNCTION__,
                TimeToString(bartime),
                copied,
                EnumToString(tf),
                TimeToString(tmpTimeArray[0]));

    return tmpTimeArray[0];
}
 

To check this: "I don't think BarsCalculated() actually requests data from the server." I continued to play with the tiny indicator and the script.

These are their recent versions. The indicator:

//+------------------------------------------------------------------+
//|                                                HaveAllQuotes.mq5 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_NONE
#property indicator_label1  "AllQts"

//--- input parameters
input bool     dbug = true;
input int      NoBars=0;
int _NoBars, OneDay;
double B[];
int OnInit()  {
   _NoBars = NoBars <= 0 ? 100000 : NoBars;
   OneDay = 86400/(PeriodSeconds(PERIOD_CURRENT)); //Min
   //--- buffer mapping
   SetIndexBuffer(0,B,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,0);
   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                 const datetime& time[],     // Time 
                 const double& open[],       // Open 
                 const double& high[],       // High 
                 const double& low[],        // Low 
                 const double& close[],      // Close 
                 const long& tick_volume[],  // Tick Volume 
                 const long& volume[],       // Real Volume 
                 const int& spread[])         // Spread 
  {
//---
   
   if (dbug) Print("HaveAllQts Sym: ",_Symbol,"  Per: ",EnumToString(ChartPeriod()), //" tL: ",TimeToString(TimeLocal(),TIME_DATE|TIME_SECONDS),
         //"  TermMax: ",TerminalInfoInteger(TERMINAL_MAXBARS)," = ",(int)(TerminalInfoInteger(TERMINAL_MAXBARS)/(365*OneDay))," years!",
         "  ServSync ",SymbolIsSynchronized(_Symbol),"  Bars ",Bars(_Symbol,_Period),"  _NoBars ",_NoBars,"  rts_Tot: ",rates_total,
         "  prvClc ",prev_calculated, " => ",(rates_total<_NoBars?"not enough":"ok enough"),"\nt[0] ",time[0]," t[",(rates_total-1),"] ",time[rates_total-1]);
   //if ( rates_total<_NoBars ) return(0);
   
   return(rates_total);
  }
//+------------------------------------------------------------------+

The script:

//+------------------------------------------------------------------+
//|                                           Test_HaveAllQuotes.mq5 |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   bool dbug = true;
   int  reqBars = 700000;
   string sym = _Symbol;
   ENUM_TIMEFRAMES per = PERIOD_M1;
   int newBars, prvBars=0, nTries = 10, Hdl = iCustom(sym,per, "HaveAllQuotes",dbug,reqBars,  0,0 );
   while (true) {
      ResetLastError();
      newBars = BarsCalculated(Hdl);
      if (dbug) Print(sym,", ",EnumToString(per),"  reqBars ",reqBars,"  Hdl ",Hdl,"  prvBars ",prvBars,"  newBars ",newBars,"  Try: ",nTries,"  er: ",_LastError,"  ServSync ",SymbolIsSynchronized(sym) );
      if ( prvBars == newBars ) nTries--;
      else nTries = 10;
      if ( newBars >= reqBars || IsStopped() || nTries < 0 ) break;
      prvBars = newBars;
      Sleep(2000);
   }
   bool rel = IndicatorRelease(Hdl);
   Print(sym,", ",EnumToString(per),"  reqBars ",reqBars,"  Bars ",Bars(sym,per),"  Hdl ",Hdl,"  prvBars ",prvBars,"  newBars ",newBars,"  Try: ",nTries,
         "  er: ",_LastError,"  ServSync ",SymbolIsSynchronized(sym),"    DONE :)  Indicator released: ",rel );
  }
//+------------------------------------------------------------------+

And I stumbled over things I couldn't explain.

Sometimes this grabs more and more data from the server (so it loads new data!):

NM    0    08:35:41.003    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 101825  er: 4806
KK    0    08:35:41.014    HaveAllQuotes (GBPUSD,H1)    HaveAllQts Sym: GBPUSD  Per: PERIOD_H1 tL: 2018.10.21 08:35:41  TermMax: 100000000 = 11415 years!  Bars 101825  _NoBars 100000  rts_Tot: 101825  prvClc 0 => false
PJ    0    08:35:41.503    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc 101825  Bars 101825  er: 0
GO    0    08:35:41.503    Test_HaveAllQuotes (GBPUSD,H1)    DONE :)  Hdl 10  nB 101825  er: 0
OR    0    08:36:56.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 37387  er: 4806
CI    0    08:36:56.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 74857  er: 4806
KN    0    08:36:57.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 112069  er: 4806
FS    0    08:36:57.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 112069  er: 4806
FG    0    08:36:58.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 112069  er: 4806
CK    0    08:36:58.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 112069  er: 4806
QL    0    08:36:59.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 112069  er: 4806
HP    0    08:36:59.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 112069  er: 4806
FE    0    08:37:00.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 149151  er: 4806
CI    0    08:37:00.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 149151  er: 4806
QM    0    08:37:01.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 149151  er: 4806
HF    0    08:37:01.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 149151  er: 4806
LJ    0    08:37:02.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 149151  er: 4806
MN    0    08:37:02.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 149151  er: 4806
NS    0    08:37:03.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 185846  er: 4806
CG    0    08:37:03.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 185846  er: 4806
KH    0    08:37:04.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 185846  er: 4806
NL    0    08:37:04.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 185846  er: 4806
HP    0    08:37:05.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 185846  er: 4806
IE    0    08:37:05.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 222590  er: 4806
MI    0    08:37:06.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 222590  er: 4806
LM    0    08:37:06.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 222590  er: 4806
JF    0    08:37:07.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 222590  er: 4806
OJ    0    08:37:07.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 222590  er: 4806
OO    0    08:37:08.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 222590  er: 4806
PS    0    08:37:08.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 259828  er: 4806
FG    0    08:37:09.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 259828  er: 4806
KH    0    08:37:09.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 259828  er: 4806
RL    0    08:37:10.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 259828  er: 4806
OP    0    08:37:10.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 259828  er: 4806
EE    0    08:37:11.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 259828  er: 4806
KI    0    08:37:11.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 297067  er: 4806
GR    0    08:37:12.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 297067  er: 4806
JF    0    08:37:12.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 297067  er: 4806
LJ    0    08:37:13.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 297067  er: 4806
EO    0    08:37:13.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 297067  er: 4806
HS    0    08:37:14.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 333919  er: 4806
IG    0    08:37:14.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 333919  er: 4806
KH    0    08:37:15.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 333919  er: 4806
FL    0    08:37:15.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 333919  er: 4806
RQ    0    08:37:16.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 333919  er: 4806
OE    0    08:37:16.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 333919  er: 4806
NI    0    08:37:17.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 370539  er: 4806
CR    0    08:37:17.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 370539  er: 4806
CF    0    08:37:18.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 370539  er: 4806
FJ    0    08:37:18.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 370539  er: 4806
PO    0    08:37:19.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 370539  er: 4806
LS    0    08:37:19.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 407250  er: 4806
OD    0    08:37:20.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 407250  er: 4806
RH    0    08:37:20.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 407250  er: 4806
DL    0    08:37:21.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 407250  er: 4806
MQ    0    08:37:21.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 407250  er: 4806
IE    0    08:37:22.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 407250  er: 4806
QI    0    08:37:22.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 443941  er: 4806
CR    0    08:37:23.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 443941  er: 4806
NF    0    08:37:23.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 443941  er: 4806
FK    0    08:37:24.044    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 443941  er: 4806
CO    0    08:37:24.544    Test_HaveAllQuotes (GBPUSD,H1)    Hdl 10  BarsCalc -1  Bars 443941  er: 4806
GR    0    08:37:24.644    Test_HaveAllQuotes (GBPUSD,H1)    DONE :)  Hdl 10  nB -1  er: 4806

(from \MQL5\Log\20181021.log) I guess that stopped the execution myself (remove expert from chart)

and sometimes I get only this what ever I tried:

QE    0    10:22:15.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 0  newBars -1  Try: 10  er: 4806
LK    0    10:22:15.423    HaveAllQuotes (USDCAD,M30)    HaveAllQts Sym: USDCAD  Per: PERIOD_M30 tL: 2018.10.21 10:22:15  TermMax: 100000000 = 5707 years!  Bars 246326  _NoBars 700000  rts_Tot: 246326  prvClc 0 => not enough
HE    0    10:22:15.424    HaveAllQuotes (USDCAD,M30)    HaveAllQts Sym: USDCAD  Per: PERIOD_M30 tL: 2018.10.21 10:22:15  TermMax: 100000000 = 5707 years!  Bars 246326  _NoBars 700000  rts_Tot: 246326  prvClc 246326 => not enough
DN    0    10:22:17.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars -1  newBars 246326  Try: 10  er: 0
IL    0    10:22:19.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 10  er: 0
FI    0    10:22:21.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 9  er: 0
KK    0    10:22:23.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 8  er: 0
LJ    0    10:22:25.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 7  er: 0
ED    0    10:22:27.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 6  er: 0
JG    0    10:22:29.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 5  er: 0
JQ    0    10:22:31.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 4  er: 0
MP    0    10:22:33.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 3  er: 0
HR    0    10:22:35.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 2  er: 0
OM    0    10:22:37.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 1  er: 0
NO    0    10:22:39.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 0  er: 0
LQ    0    10:22:39.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Bars 246326  Hdl 10  prvBars 246326  newBars 246326  Try: -1  er: 0    DONE :)  Indicator released: true
QE    0    10:23:22.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 0  newBars -1  Try: 10  er: 4806
KL    0    10:23:22.846    HaveAllQuotes (AUDUSD,M30)    HaveAllQts Sym: AUDUSD  Per: PERIOD_M30 tL: 2018.10.21 10:23:22  TermMax: 100000000 = 5707 years!  Bars 1440  _NoBars 700000  rts_Tot: 1440  prvClc 0 => not enough
PH    0    10:23:24.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars -1  newBars 1440  Try: 10  er: 0
OH    0    10:23:26.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 10  er: 0
GD    0    10:23:28.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 9  er: 0
OE    0    10:23:30.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 8  er: 0
DF    0    10:23:32.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 7  er: 0
IG    0    10:23:34.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 6  er: 0
JP    0    10:23:36.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 5  er: 0
KQ    0    10:23:38.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 4  er: 0
CR    0    10:23:40.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 3  er: 0
FS    0    10:23:42.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 2  er: 0
IL    0    10:23:44.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 1  er: 0
HM    0    10:23:46.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 0  er: 0
LQ    0    10:23:46.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Bars 1440  Hdl 10  prvBars 1440  newBars 1440  Try: -1  er: 0    DONE :)  Indicator released: true
RG    0    10:23:54.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 0  newBars -1  Try: 10  er: 4806
CJ    0    10:23:54.961    HaveAllQuotes (AUDUSD,M30)    HaveAllQts Sym: AUDUSD  Per: PERIOD_M30 tL: 2018.10.21 10:23:54  TermMax: 100000000 = 5707 years!  Bars 1440  _NoBars 700000  rts_Tot: 1440  prvClc 0 => not enough
CJ    0    10:23:56.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars -1  newBars 1440  Try: 10  er: 0
HJ    0    10:23:58.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 10  er: 0
DJ    0    10:24:00.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 9  er: 0
EK    0    10:24:02.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 8  er: 0
ND    0    10:24:04.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 7  er: 0
KE    0    10:24:06.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 6  er: 0
HF    0    10:24:08.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 5  er: 0
PG    0    10:24:10.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 4  er: 0
KP    0    10:24:12.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 3  er: 0
RQ    0    10:24:14.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 2  er: 0
QR    0    10:24:16.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 1  er: 0
DS    0    10:24:18.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 0  er: 0
PS    0    10:24:18.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Bars 1440  Hdl 10  prvBars 1440  newBars 1440  Try: -1  er: 0    DONE :)  Indicator released: true
QE    0    10:22:15.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 0  newBars -1  Try: 10  er: 4806
LK    0    10:22:15.423    HaveAllQuotes (USDCAD,M30)    HaveAllQts Sym: USDCAD  Per: PERIOD_M30 tL: 2018.10.21 10:22:15  TermMax: 100000000 = 5707 years!  Bars 246326  _NoBars 700000  rts_Tot: 246326  prvClc 0 => not enough
HE    0    10:22:15.424    HaveAllQuotes (USDCAD,M30)    HaveAllQts Sym: USDCAD  Per: PERIOD_M30 tL: 2018.10.21 10:22:15  TermMax: 100000000 = 5707 years!  Bars 246326  _NoBars 700000  rts_Tot: 246326  prvClc 246326 => not enough
DN    0    10:22:17.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars -1  newBars 246326  Try: 10  er: 0
IL    0    10:22:19.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 10  er: 0
FI    0    10:22:21.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 9  er: 0
KK    0    10:22:23.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 8  er: 0
LJ    0    10:22:25.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 7  er: 0
ED    0    10:22:27.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 6  er: 0
JG    0    10:22:29.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 5  er: 0
JQ    0    10:22:31.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 4  er: 0
MP    0    10:22:33.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 3  er: 0
HR    0    10:22:35.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 2  er: 0
OM    0    10:22:37.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 1  er: 0
NO    0    10:22:39.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 246326  newBars 246326  Try: 0  er: 0
LQ    0    10:22:39.032    Test_HaveAllQuotes (GBPUSD,H1)    USDCAD, PERIOD_M30  reqBars 700000  Bars 246326  Hdl 10  prvBars 246326  newBars 246326  Try: -1  er: 0    DONE :)  Indicator released: true
QE    0    10:23:22.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 0  newBars -1  Try: 10  er: 4806
KL    0    10:23:22.846    HaveAllQuotes (AUDUSD,M30)    HaveAllQts Sym: AUDUSD  Per: PERIOD_M30 tL: 2018.10.21 10:23:22  TermMax: 100000000 = 5707 years!  Bars 1440  _NoBars 700000  rts_Tot: 1440  prvClc 0 => not enough
PH    0    10:23:24.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars -1  newBars 1440  Try: 10  er: 0
OH    0    10:23:26.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 10  er: 0
GD    0    10:23:28.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 9  er: 0
OE    0    10:23:30.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 8  er: 0
DF    0    10:23:32.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 7  er: 0
IG    0    10:23:34.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 6  er: 0
JP    0    10:23:36.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 5  er: 0
KQ    0    10:23:38.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 4  er: 0
CR    0    10:23:40.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 3  er: 0
FS    0    10:23:42.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 2  er: 0
IL    0    10:23:44.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 1  er: 0
HM    0    10:23:46.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 0  er: 0
LQ    0    10:23:46.549    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Bars 1440  Hdl 10  prvBars 1440  newBars 1440  Try: -1  er: 0    DONE :)  Indicator released: true
RG    0    10:23:54.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 0  newBars -1  Try: 10  er: 4806
CJ    0    10:23:54.961    HaveAllQuotes (AUDUSD,M30)    HaveAllQts Sym: AUDUSD  Per: PERIOD_M30 tL: 2018.10.21 10:23:54  TermMax: 100000000 = 5707 years!  Bars 1440  _NoBars 700000  rts_Tot: 1440  prvClc 0 => not enough
CJ    0    10:23:56.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars -1  newBars 1440  Try: 10  er: 0
HJ    0    10:23:58.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 10  er: 0
DJ    0    10:24:00.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 9  er: 0
EK    0    10:24:02.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 8  er: 0
ND    0    10:24:04.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 7  er: 0
KE    0    10:24:06.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 6  er: 0
HF    0    10:24:08.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 5  er: 0
PG    0    10:24:10.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 4  er: 0
KP    0    10:24:12.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 3  er: 0
RQ    0    10:24:14.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 2  er: 0
QR    0    10:24:16.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 1  er: 0
DS    0    10:24:18.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Hdl 10  prvBars 1440  newBars 1440  Try: 0  er: 0
PS    0    10:24:18.949    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_M30  reqBars 700000  Bars 1440  Hdl 10  prvBars 1440  newBars 1440  Try: -1  er: 0    DONE :)  Indicator released: true
RJ    0    10:24:41.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars 0  newBars -1  Try: 10  er: 4806
HK    0    10:24:41.590    HaveAllQuotes (AUDUSD,H1)    HaveAllQts Sym: AUDUSD  Per: PERIOD_H1 tL: 2018.10.21 10:24:41  TermMax: 100000000 = 11415 years!  Bars 720  _NoBars 700000  rts_Tot: 720  prvClc 0 => not enough
EQ    0    10:24:41.590    HaveAllQuotes (AUDUSD,H1)    HaveAllQts Sym: AUDUSD  Per: PERIOD_H1 tL: 2018.10.21 10:24:41  TermMax: 100000000 = 11415 years!  Bars 720  _NoBars 700000  rts_Tot: 720  prvClc 720 => not enough
IR    0    10:24:43.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars -1  newBars 720  Try: 10  er: 0
JQ    0    10:24:45.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars 720  newBars 720  Try: 10  er: 0
LQ    0    10:24:47.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars 720  newBars 720  Try: 9  er: 0
OQ    0    10:24:49.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars 720  newBars 720  Try: 8  er: 0
GP    0    10:24:51.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars 720  newBars 720  Try: 7  er: 0
PP    0    10:24:53.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars 720  newBars 720  Try: 6  er: 0
QO    0    10:24:55.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars 720  newBars 720  Try: 5  er: 0
JN    0    10:24:57.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars 720  newBars 720  Try: 4  er: 0
CN    0    10:24:59.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars 720  newBars 720  Try: 3  er: 0
JM    0    10:25:01.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars 720  newBars 720  Try: 2  er: 0
CL    0    10:25:03.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars 720  newBars 720  Try: 1  er: 0
PL    0    10:25:05.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Hdl 10  prvBars 720  newBars 720  Try: 0  er: 0
NG    0    10:25:05.576    Test_HaveAllQuotes (GBPUSD,H1)    AUDUSD, PERIOD_H1  reqBars 700000  Bars 720  Hdl 10  prvBars 720  newBars 720  Try: -1  er: 0    DONE :)  Indicator released: true

Here I get for USDCAD, PERIOD_M30   246326 bars but for AUDUSD, M3 I only get 1440?

The whole log-file is attached for you to check. As I didn't expect so big differences between the symbols ~450'000 H1 bars for GBPUSD (~50 years) and 720 for AUDUSD as well H1 and just wanted to play with different versions to break out of the loop I haven't documented my changes so gthat I don't know whether I used a magic combinations of functions to get moren more or it is just a server sided setting. :(

Despite that I don' really understand why the indicator did not prints out its line eachtime it is called - maybe it is bypassed as no new tick or quotes has arrived.

What I can say is that SymbolIsSynchronized() cannot be used to control the download.

Files:
20181021.log  207 kb
 

It's run on a live chart the week-end right ? there is no new tick so OnCalculate() is only call once (or twice, I noticed that too and never found a clear logic why it's 1 or 2 times).

For the rest your code doesn't download any data by itself. It starts an indicator on a given symbol/timeframe, if the data are already on the terminal it uses it, otherwise it download a given amount of data.

On your first run GBPUSD, H1 on the chart itself, it gets more bars, not sure why exactly, maybe you move the chart itself to see past data ?

 

Just catching up here... 


I said use CopyBuffer since it implements some kind of logic behind the scenes in order to wait for the indicator to come up. See here

void OnStart()
{
   {
      int h = iCustom(_Symbol, _Period, "RatesTotal");
      int bars_calulated = 0;
      int loops = 0;
      do{
         loops++;
         ResetLastError();
         bars_calulated = BarsCalculated(h);
      }while(_LastError != ERR_SUCCESS);
      printf("loops = %d", loops);
      IndicatorRelease(h);
   }{
      int h = iCustom(_Symbol, _Period, "RatesTotal");
      int loops = 0;
      double res[];
      do{
         loops++;
         ResetLastError();
         int copied = CopyBuffer(h, 0, 0, 1, res);
      }while(_LastError != ERR_SUCCESS);
      printf("loops = %d", loops);
      IndicatorRelease(h);
   }
}

OUTPUT:

loops = 15543
loops = 1


Also, the only way to deal with calling one indicator from another when there are no ticks (weekend) is to set a timer event so "this" indicator can exit and release thread lock to allow "other" indicator to run on the same thread. 

 
Carl Schreiber:

Sometimes this grabs more and more data from the server (so it loads new data!):

Yeah, I hate that. Especially when loading data for other currency pairs or time frames.

To limit to the number of bars available on the chart, I do this in OnCalculate().

    // initializing charts of used currency pairs
    static int rates_total_hold = -1;
    if ( rates_total_hold != rates_total )
    {
        if ( ! pEnsureData(rates_total, time[0]) )
        {
            return 0;
        }

        if ( ! pFillBuffers(to_copy) )
        {
            return 0;
        }

        rates_total_hold = rates_total;
    }

Where pEnsureData() is basically the code I described above, and pFillBuffers() calls CopyBuffer().

But note: what I am describing happens when ticks are coming in. @Alain Verleyen brings up a crucial point: you ran your code on a weekend, so what I am describing will not be directly applicable to what you are currently seeing.
 

One other thing to note:

I've noticed that sometimes BarsCalculated() returns 0, even though the data is already there. That is, BarsCalculated() may have been returning 510 for two or three dozen ticks when, all of a sudden, it returns 0. Then, on the very next tick, BarsCalculated() returns 510 again.

I've got a simple:

if ( calculated == 0 ) continue;     // Why does this happen?

in my code for now to compensate for this.

Reason: