Problem with time loop

 

I'm trying to point out the candle, on M1,with the biggest volume within an hour for every hour.

The results are puzzling, some do point out the biggest volume, some hours have none. Could you please help me out as i don't know where i'm going wrong with this.

    void DrawMinuteDot(string dayhour, int i)   //function to draw the dot
    {  
         string objName = "volumee"+dayhour; 
         ObjectCreate(objName, OBJ_TEXT, 0, Time[i], Low[i]+15*Point); 
         ObjectSetText(objName, CharToStr(159), 30, "Wingdings", Aqua); 
         ChartRedraw(0);
     }
    void MoveMinuteDot(string dotName) //function to delete current dot
    {
      if(ObjectFind(dotName))
         ObjectDelete(dotName);    
    }   

        int start()
        {    //----
                int minuteVol =0;
           int biggestM1Vol =0;
           int limit;
      int counted_bars = IndicatorCounted();
      if (counted_bars < 0)
        return(-1);
      limit = Bars - 1 - counted_bars;
           for(int i = 0; i < limit; i++)
           {
                      if (TimeMinute(iTime(NULL,PERIOD_M1,i)) >= 0 )
                      {
                        minuteVol = iVolume(NULL,PERIOD_M1,i);
                        if(biggestM1Vol <= minuteVol)
                        {
                            int d = TimeDayOfYear(iTime(NULL,PERIOD_M1,i));
                            int h = TimeHour(iTime(NULL,PERIOD_M1,i));
                            MoveMinuteDot("volumee"+IntegerToString(d)+IntegerToString(h));//delete the dot for curr hour so a new one can be drawn
                            biggestM1Vol = minuteVol;
                            DrawMinuteDot(IntegerToString(d)+IntegerToString(h),i);
                        }
                        if(TimeSeconds(iTime(NULL,PERIOD_M1,i)) == 0 )//resets the count as the new minute starts
                        {
                            minuteVol = 0;
                        }
                      }
                      else
                      {
                         if (TimeMinute(iTime(NULL,PERIOD_M1,i)) ==0 && TimeSeconds(iTime(NULL,PERIOD_M1,i)) == 0)//new hour starts so reset biggest volume to 0
                         {
                            biggestM1Vol = 0;
                         }
                      }
           }
                return(0);
        }
 
zacorbul:

I'm trying to point out the candle, on M1,with the biggest volume within an hour for every hour.

The results are puzzling, some do point out the biggest volume, some hours have none. Could you please help me out as i don't know where i'm going wrong with this.

  1. After the first run, "i" will only be zero, biggestM1Vol will also be zero and you conclude that bar zero is the biggest. You are trying to do it on the fly, you have to look at the old values.
  2. Your code breaks on any chart but the M1. iTime(NULL,PERIOD_M1,i)); You are mixing apples and oranges
  3. Drop everything inside your for loop and do it right.
    1. For chart bar "i," Find the M1 bar. Don't mix apples and oranges
    2. Compute the start of the hour, and find that M1 bar.
    3. Find the M1 with maximum volume.
    4. Find the corresponding chart bar. Don't mix apples and oranges
    5. Draw the object (deleting the old one first)
    datetime TimeChart = Time[i];
    int iM1     = iBarShift(NULL, PERIOD_M1, TimeChart);
    
    datetime beginningHour = TimeChart - TimeChart % 3600;
    int iM1Hour = iBarShift(NULL, PERIOD_M1, BeginningHour);
    
    int iMaxVol = iHighest(NULL, PERIOD_M1, MODE_VOLUME, iM1 - iM1Hour + 1, iM1);
    
    datetime highestVolume = iTime(NULL, PERIOD_M1, iMaxVol);
    int iChart = iBarShift(NULL, PERIOD_CURRENT, highestVolume);
    
    string objName = "volumee"+string(beginningHour); 
    ObjectDelete(objName);
    ObjectCreate(objName, OBJ_TEXT, 0, Time[iChart], Low[iChart]+15*Point); 
    ObjectSetText(objName, CharToStr(159), 30, "Wingdings", Aqua);
Reason: