Download MetaTrader 5

Is This a Bug, a Feature or a Lazy Broker?

To add comments, please log in or register
Carl Schreiber
7354
Carl Schreiber  
Hi,

I need the quotes of the m1 bars together with the quotes of the bars of the current chart to go back for "LookBackBars" (if possible) of the actual timeframe

Mt4 now offers 'me' for this 3 'data-streams':
  1. time[] (or Time[]) from Bars-1 to 0 (=current)
  2. MqlRates of _Period and
  3. MqlRates of M1.

So I wrote a little script

  1. to get the oldest common date of all three 'streams'
  2. to get the number of bars of each 'stream'
  3. and to load by CopyRate the quotes.

I get for the chart with timeframe M5:

  1. GIVEN
    LookBackBars 10000: 2017.01.24 00:09             // <= oldest required date
    Bars 133356: 2014.01.01 22:00
    M1 50005: 2016.12.21 07:46                           // <= oldest available date M1
    P0 10001: 2016.04.11 04:55                            //  <= oldest available date Chart   
    =>  newBarsBack: 10000 t 2017.01.24 00:09  // maxdate to begin calculation

  2. GOT
    Time[133355]:                         2014.01.01 22:00    - 2017.02.27 17:30 // no problem
    m1, 35572 =?= 50005              2017.01.24 00:10 - 2017.02.27 17:34 // fine as requested
    p0, 3115 =?= 10001             2017.02.12 22:00 - 2017.02.27 17:30 // uups - what happened here?? Wasn't I told that 10001 bars can be requested?

For the first part I did:
   TimeMaxBars = TimeCurrent() - (LookBackBars+1)*_Period*60;
   Str1 = StringConcatenate("\nGIVEN\nLookBackBars ",LookBackBars,": ",TimeToString(TimeMaxBars),"\nBars ",Bars,": ",TimeToString(Time[Bars-1]));
  
   TimeOldM1 = (datetime)SeriesInfoInteger(_Symbol, PERIOD_M1, SERIES_SERVER_FIRSTDATE);
   BarsOldM1 =           SeriesInfoInteger(_Symbol, PERIOD_M1, SERIES_BARS_COUNT);
   TimeOldP0 = (datetime)SeriesInfoInteger(_Symbol,   _Period, SERIES_SERVER_FIRSTDATE);
   BarsOldP0 =           SeriesInfoInteger(_Symbol,   _Period, SERIES_BARS_COUNT);
  
   TimeOldCalc = fmax3(TimeMaxBars,TimeOldM1,TimeOldP0);
   BarsOldP0 = (TimeCurrent() - TimeOldCalc)/(_Period*60); //Chart
   BarsOldM1 = (TimeCurrent() - TimeOldCalc)/(60); //Min
  
   if ( BarsOldP0 < LookBackBars ) {
      Str1 = Str1 +"\nCORRECTED";
      LookBackBars = (int)BarsOldP0;
   }
in the calculation part:
   MqlRates rMin[], rPer[];
   int allMin = CopyRates(_Symbol, PERIOD_M1, TimeCurrent(),TimeOldCalc, rMin),
       allPer = CopyRates(_Symbol,   _Period, TimeCurrent(),TimeOldCalc, rPer),
       lim    = Bars - 1;
   Str2 = StringConcatenate("\nGOT\nTime[",lim,"]: ",TimeToString(Time[lim])," - ",TimeToString(Time[0]),
      "\nm1, ",allMin," =?= ",BarsOldM1," ",TimeToString(rMin[0].time)," - ",TimeToString(rMin[allMin-1].time),
      "\np0, ",allPer," =?= ",BarsOldP0," ",TimeToString(rPer[0].time)," - ",TimeToString(rPer[allPer-1].time)
    );

Why do I get such a stupid small value for the array size (allPer)  for rPer - not only once, but again and again?
funnily - LEO: Übersetzung im Englisch ⇔ Deutsch Wörterbuch
  • dict.leo.org
Übersetzung für 'funnily' in LEOs Englisch ⇔ Deutsch Wörterbuch. Mit Flexionstabellen, Aussprache und vielem mehr.
Files:
To add comments, please log in or register