How do you Sum up info from LTF to a single shift in HTF?

 

Hello Guys,

I'm having difficulty trying to sum up and collect Total Bull Candle Body size and Total Bear Candle Body size for each day(resets everyday)

from M5 to a single shift in H1 using a double loop for a few hours, Still I coulnd't get it to work correctly. 

So, every shift on H1, I'm trying to make the indicator fetch all the bull candle body size in M5 that has happened today and add them all up in a histogram. Vice versa for Bear Candles.

Any help and advise will be appreciated.


 int ExtCountedBars=IndicatorCounted();
 if (ExtCountedBars<0) return(-1);
 int pos;
 int limit=Bars-5;
 if(ExtCountedBars>2) limit=Bars-ExtCountedBars-1;
 pos=limit;    
   
      //---------Loop Starts---------------------------
      for(int t=0; t<=limit; t++) 
      {   
         double TempUp = 0, TempDn = 0;
         
         for( int p=t; p<t+288; p++)
         {
            if( TimeDay(iTime(_Symbol, PERIOD_M5, p)) != TimeDay(iTime(_Symbol, PERIOD_M5, t)) ) break;
            
            double ClosePrice = iClose( _Symbol, PERIOD_M5, iBarShift(_Symbol, PERIOD_M5, iTime(_Symbol, PERIOD_M5, p) ) );
            double OpenPrice = iOpen( _Symbol, PERIOD_M5, iBarShift(_Symbol, PERIOD_M5, iTime(_Symbol, PERIOD_M5, p) ) );
            double Bodysize = MathAbs( ClosePrice-OpenPrice );
            
            if( ClosePrice > OpenPrice ) TempUp += Bodysize; 
            if( ClosePrice < OpenPrice ) TempDn += Bodysize;
         }
         TodayBull[t] = TempUp;
         TodayBear[t] = TempDn;         
      
      }
It would look something like this, but mine is not collecting the correct data
something like this
 
  1. I Kai Wu: Still I coulnd't get it to work correctly.

    “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. (2004)
              When asking about code
              Be precise and informative about your problem

  2. I Kai Wu: So, every shift on H1,

    I assume the current chart is the H1. If I understand what you want correctly, for each candle

    1. Get the candle end time: Time[i]+PeriodSeconds(PERIOD_CURRENT)-1
    2. Get the start of the day: date()
                date/time (2017)
                Find bar of the same time one day ago - MQL4 programming forum (2017)

    3. Now get the M5 shifts for № 1 and № 2 and sum.

  3. At the start of OnCalculate, unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 (2019)

  4. You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)

 
William Roeder #:
  1. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. (2004)
              When asking about code
              Be precise and informative about your problem

  2. I assume the current chart is the H1. If I understand what you want correctly, for each candle

    1. Get the candle end time: Time[i]+PeriodSeconds(PERIOD_CURRENT)-1
    2. Get the start of the day: date()
                date/time (2017)
                Find bar of the same time one day ago - MQL4 programming forum (2017)

    3. Now get the M5 shifts for № 1 and № 2 and sum.

  3. At the start of OnCalculate, unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 (2019)

  4. You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)


Yes, you are correct, my chart is on H1. I'll give it another try using the method you provided. And also updating my event handlers as well.

Thank you so much for the advice William and sorry if I was asking question in an inefficent manner.

Reason: