Good way to collect OHLC data for 'exotic' timeframes inside single EA?

 

I'm having trouble with my current EA.

I need to collect OHLC for time frames not preprogrammed in mql4.

I start at first m1 bar in history and I get the time of the first opening minute bar where day of month, day of week and time of day = 0.

From that time i count forward where every next bar for specified time frame should be greater or equal to. I then collect data and put it into array.

I'm having problems where I'm assuming m1 times aren't aligning properly. For instance on the H2 frame the opening for each candle is off by a few minutes( opentime[1]=1:03. )

They are also uneven where as it should be at intervals of 2:00 starting from 00:00 instead of 1:00 or 3:00.

Could you think of any way to get OHLC data and have them align properly as period converter script would? I'm trying to keep it all in one program as I don't want

to have to write to files from several opened charts with period converter opt. Not entirely serious but tips would be appreciated.

 

Coolaid:

I'm having problems where I'm assuming m1 times aren't aligning properly. For instance on the H2 frame the opening for each candle is off by a few minutes( opentime[1]=1:03. )

They are also uneven where as it should be at intervals of 2:00 starting from 00:00 instead of 1:00 or 3:00.

Could you think of any way to get OHLC data and have them align properly as period converter script would? I'm trying to keep it all in one program as I don't want

  1. If there are no ticks in the first two minutes, the M1 starts at 1:03. You must align your H2 time to multiple of 2 hours.
  2. Why are you using a M1 to generate a H2? Using a H1 means you'll have more history.
  3. I'm currently doing a complete rewrite of my code, into OOP, and expanding with STL, custom charts: timeframes, tick, and price (renko) charts. I just finished writing exactly what your asking.
    Not compiled, not tested.
    void                 cCustomChartTime::MergeFill(void){
       cTry try(__FUNCTION__ + "(" + IntegerToString(mPeriod) + ")");
       const int   ps       = PeriodSeconds(mPeriod);
       MqlRates curBar      = mRates[0];         bool  isUpdateing = true;
       datetime barEnd      = curBar.time + ps;
       // mSrcBar contains the date and volume of the mStandardChart bar that was
       // last used to update mRates[0]
       curBar.tick_volume  -= mSrcBar.tick_volume;  // re-add updated value below.
       for(int iSrc = mStandardChart.Shift(mSrcBar.time); iSrc >= 0; --iSrc){
          mSrcBar           = mStandardChart[iSrc];
          if(mSrcBar.time >= barEnd){
             if(isUpdateing){  mRates.Put(0, curBar);     isUpdateing = false;    }
             else              if(!MakeNewBar(curBar) )                     return;
             curBar.time          = mSrcBar.time /ps * ps;   // Possible gap.
             barEnd               = curBar.time + ps;
             curBar.open          = mSrcBar.open;      curBar.high = mSrcBar.high;
             curBar.close         = mSrcBar.close;     curBar.low  = mSrcBar.low;
             curBar.tick_volume   = mSrcBar.tick_volume;
          }else{   // Merge
             if(curBar.high < mSrcBar.high)      curBar.high = mSrcBar.high;
             if(curBar.low  > mSrcBar.low)       curBar.low  = mSrcBar.low;
             curBar.close         = mSrcBar.close;
             curBar.tick_volume  += mSrcBar.tick_volume;
          }
       }  // iSrc
       if(isUpdateing)   mRates.Put(0, curBar);
       else              MakeNewBar(curBar);
    }  // MergeFill
    
    Not compiled, not tested.