iVolume Question

 

I am able to find the candle / period over 288 periods with the highest volume. " iHighest(NULL,0,MODE_VOLUME,288,0); "  But when I try to find the volume of that candle " int HighVolC = iVolume(NULL,PERIOD_M5,mz); "  I don't get the correct volume of that candle / period.  Is there something that I'm missing?  Mz = the 249th candle.  Volume should be 1086, but getting 159.


Thanks!

 
Did 250th candle gives you 1086?
 
 iHighest(NULL,0,MODE_VOLUME,288,0)          //Does this value get applied to mz?

 int HighVolC = iVolume(NULL,PERIOD_M5,mz);  //This calculates on the 5 minute chart whereas the previous line calculates on 
                                             //the current chart time-frame, Is the current chart time-frame 5 minute?
 
GumRai:


Yes and Yes.   Below is the code.  288 is the total number of 5 minute periods in 24 hours.
   int CntBarsz = 288;
   
   int lowshiftz=iLowest(NULL,0,MODE_VOLUME,CntBarsz,0);
    double Minimumz=Close[lowshiftz];  
   datetime lowtimez=Time[lowshiftz];
                        
   int maxshiftz=iHighest(NULL,0,MODE_VOLUME,CntBarsz,0);
    double Maximumz=Close[maxshiftz];  
   datetime maxtimez=Time[maxshiftz];
        

   for(i=0;i<CntBarsz-1;i++)                      .
     {                                            
      if (Low[i]< Minimumz)                        
         {Minimumz=Low[i]; nz = i;             //  nz returns lowest candle / period number     
         
         
ObjectCreate("UpSymbolAz", OBJ_ARROW, 0, lowtimez,Minimumz);         
ObjectSet("UpSymbolAz", OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
ObjectSet("UpSymbolAz", OBJPROP_COLOR,White);
                 
      }  
                          
      if (High[i]> Maximumz)                       
         {Maximumz=High[i]; mz = i;            //  mz returns highest candle / period number         
 
ObjectCreate("DnSymbolAz", OBJ_ARROW, 0, maxtimez,Maximumz);                  
ObjectSet("DnSymbolAz", OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
ObjectSet("DnSymbolAz", OBJPROP_COLOR,Yellow);        
         
     }           
                  
     }  
   
   
   
      int LowVolC = iVolume(NULL,PERIOD_M5,nz);   //  should return volume of lowest candle
      int HighVolC = iVolume(NULL,PERIOD_M5,mz);  //  should return volume of highest candle
 
Yellowbeard:

Yes and Yes.   Below is the code.  288 is the total number of 5 minute periods in 24 hours.

You could have more than one candle where this is true . . .

if (Low[i]< Minimumz)                        
         {Minimumz=Low[i]; nz = i;             //  nz returns lowest candle / period number   

 . . .  so the code can be called more than once and the last value may not be the "lowest" . . .  Minimumz is not the lowest value but the lowest Close . . .  if you want the Lowest Low why don't you simply get it ? 

 

My Questions

GumRai:

 iHighest(NULL,0,MODE_VOLUME,288,0)          //Does this value get applied to mz?

 int HighVolC = iVolume(NULL,PERIOD_M5,mz);  //This calculates on the 5 minute chart whereas the previous line calculates on 
                                             //the current chart time-frame, Is the current chart time-frame 5 minute?

 



 You answered Yes and Yes.

But, looking at your posted code, clearly, you should have answered the first question "No" ,

As Raptor has already said, the code in the loops does not return the highest/lowest bar.

I have no idea what you are trying to achieve with your code. 

 

   int lowshiftz=iLowest(NULL,0,MODE_VOLUME,CntBarsz,0);
    double Minimumz=Close[lowshiftz];  
   datetime lowtimez=Time[lowshiftz];

 This finds the bar with the lowest volume and stores the close and time of that bar in variables

Let's call that bar bar[n] 

Incidentally when a new candle has just formed, bar[0] will almost certainly be the bar with the lowest volume

 

                                           
      if (Low[i]< Minimumz)                        
         {Minimumz=Low[i]; nz = i;             //  nz returns lowest candle / period number     

 As this is in a loop, nz will be the shift of the oldest bar in the range with its low lower than Close[n]

 

        
ObjectCreate("UpSymbolAz", OBJ_ARROW, 0, lowtimez,Minimumz);         
ObjectSet("UpSymbolAz", OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
ObjectSet("UpSymbolAz", OBJPROP_COLOR,White);

 No matter what the result from your loop, this will draw an arrow using Time[n] and Close[n] as the co-ordinates.

So what's the point of having it in the loop?.

Once it has been created, subsequent attempts to create an object with the same name will fail, depending on what you actually want from your code, it may be better to create the object in init and then move the object in your code. 

 

int LowVolC = iVolume(NULL,PERIOD_M5,nz);   //  should return volume of lowest candle

 Returns the volume of bar[nz], not the lowest.

Again, the code assumes that the current chart time-frame is M5 

 

288 is the total number of periods in which to find the candle / period with the highest volume and the candle / period with the lowest.  The chart is a 5 minute chart.   The code was an attempt to find these candles, with their respective number and volume count, and place an arrow on them, so that I can know that I'm identifying the right candle.  The code is placing arrows on the right candle(s), with regards to the highest and lowest volume count, but I'm not getting the right count ( candle / period number ) or volume.  What I'm getting is the candle number for the highest high and the lowest low with their respective volume counts.


Thanks!

 
Yellowbeard:

288 is the total number of periods in which to find the candle / period with the highest volume and the candle / period with the lowest.  The chart is a 5 minute chart.   The code was an attempt to find these candles, with their respective number and volume count, and place an arrow on them, so that I can know that I'm identifying the right candle.  The code is placing arrows on the right candle(s), with regards to the highest and lowest volume count, but I'm not getting the right count ( candle / period number ) or volume.  What I'm getting is the candle number for the highest high and the lowest low with their respective volume counts.

I already explained a reasonable explanation of why you are getting inconsistent results . . .

Try this and see for yourself . . .  change this:

   for(i=0;i<CntBarsz-1;i++)                      .
     {                                            
      if (Low[i]< Minimumz)                        
         {Minimumz=Low[i]; nz = i;             //  nz returns lowest candle / period number     
         
         
ObjectCreate("UpSymbolAz", OBJ_ARROW, 0, lowtimez,Minimumz);         
ObjectSet("UpSymbolAz", OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
ObjectSet("UpSymbolAz", OBJPROP_COLOR,White);
                 
      }  

 to this . . . 

   for(i=0;i<CntBarsz-1;i++)                      .
     {                                            
      if (Low[i]< Minimumz)                        
         {Minimumz=Low[i]; nz = i;             //  nz returns lowest candle / period number     
         
         Print("nz = ", nz);                //  <--- add this line
         
      ObjectCreate("UpSymbolAz", OBJ_ARROW, 0, lowtimez,Minimumz);         
      ObjectSet("UpSymbolAz", OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
      ObjectSet("UpSymbolAz", OBJPROP_COLOR,White);
                 
      }  

 
Then run the code and if you get a result you think is wrong look at the log and see how many times nz has been printed out,  if it's more than once then there is your issue.

Do some testing,  come back with the results.

 

Results for   Print("nz = ", nz);    Looping six times per tick.


11:42:06 Custom Test Ijf USDCHF,M5: nz = 165
11:42:06 Custom Test Ijf USDCHF,M5: nz = 166
11:42:06 Custom Test Ijf USDCHF,M5: nz = 180
11:42:06 Custom Test Ijf USDCHF,M5: nz = 233
11:42:06 Custom Test Ijf USDCHF,M5: nz = 234
11:42:06 Custom Test Ijf USDCHF,M5: nz = 235
11:42:08 Custom Test Ijf USDCHF,M5: nz = 165
11:42:08 Custom Test Ijf USDCHF,M5: nz = 166
11:42:08 Custom Test Ijf USDCHF,M5: nz = 180
11:42:08 Custom Test Ijf USDCHF,M5: nz = 233
11:42:08 Custom Test Ijf USDCHF,M5: nz = 234
11:42:08 Custom Test Ijf USDCHF,M5: nz = 235
11:42:10 Custom Test Ijf USDCHF,M5: nz = 165
11:42:10 Custom Test Ijf USDCHF,M5: nz = 166
11:42:10 Custom Test Ijf USDCHF,M5: nz = 180
11:42:10 Custom Test Ijf USDCHF,M5: nz = 233
11:42:10 Custom Test Ijf USDCHF,M5: nz = 234
11:42:10 Custom Test Ijf USDCHF,M5: nz = 235
11:42:10 Custom Test Ijf USDCHF,M5: nz = 165
11:42:10 Custom Test Ijf USDCHF,M5: nz = 166
11:42:10 Custom Test Ijf USDCHF,M5: nz = 180
11:42:10 Custom Test Ijf USDCHF,M5: nz = 233
11:42:10 Custom Test Ijf USDCHF,M5: nz = 234
11:42:10 Custom Test Ijf USDCHF,M5: nz = 235
11:42:10 Custom Test Ijf USDCHF,M5: nz = 165
11:42:10 Custom Test Ijf USDCHF,M5: nz = 166
11:42:10 Custom Test Ijf USDCHF,M5: nz = 180
11:42:10 Custom Test Ijf USDCHF,M5: nz = 233
11:42:10 Custom Test Ijf USDCHF,M5: nz = 234
11:42:10 Custom Test Ijf USDCHF,M5: nz = 235
11:42:11 Custom Test Ijf USDCHF,M5: nz = 165
11:42:11 Custom Test Ijf USDCHF,M5: nz = 166
11:42:11 Custom Test Ijf USDCHF,M5: nz = 180
11:42:11 Custom Test Ijf USDCHF,M5: nz = 233
11:42:11 Custom Test Ijf USDCHF,M5: nz = 234
11:42:11 Custom Test Ijf USDCHF,M5: nz = 235

 

This code works as far as finding the candle / period number with the highest high and lowest low, with the correct volume count for each candle.  Not sure if this is the correct way to do this.  Or perhaps, there is a simpler,

 int CntBarsz = 288;
   
   int lowshiftl=iLowest(NULL,0,MODE_LOW,CntBarsz,0);
   
    double Minimuml=Close[lowshiftl];  
   datetime lowtimel=Time[lowshiftl];
                
                
                
                        
   int maxshifth=iHighest(NULL,0,MODE_HIGH,CntBarsz,0);
  
    double Maximumh=Close[maxshifth];  
   datetime maxtimeh=Time[maxshifth];
        




   for(i=0;i<CntBarsz-1;i++)                       
     {                                            
      if (Low[i]< Minimuml)                        
         {Minimuml=Low[i]; nl = ( i + 1 );                  
     
      } 
 
                          
      if (High[i]> Maximumh)                       
         {Maximumh=High[i]; mh = ( i + 1 );                 
         
     }           
                  
     }  
  
 
 
 
 
ObjectCreate("UpSymbolBz", OBJ_ARROW, 0, lowtimel,Minimuml);         
ObjectSet("UpSymbolBz", OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
ObjectSet("UpSymbolBz", OBJPROP_COLOR,Red); 
 
   
ObjectCreate("DnSymbolBz", OBJ_ARROW, 0, maxtimeh,Maximumh);                  
ObjectSet("DnSymbolBz", OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
ObjectSet("DnSymbolBz", OBJPROP_COLOR,Blue);     


  
   
   
      int LowVolC =  Volume[nl-1];  //  iVolume(NULL,PERIOD_M5,nl);
      int HighVolC = Volume[mh-1];  //  iVolume(NULL,PERIOD_M5,mh);
      
  
      
    

 
     
       text="MZ =  "+mz+"  "+HighVolC+"  "+mh;  //  
       Write("MP34109", Side, MP_X+200, MP_Y+310, text, 11, "Tahoma", Yellow);
     

      
  
      text="NZ =  "+nz+"  "+LowVolC+"  "+nl;  // 
      Write("MP34110", Side, MP_X+200, MP_Y+330, text, 11, "Tahoma", White);    
      

 better way of accomplishing this.  Let me know.  Ignore MZ and NZ.  These are for the candles with the highest and lowest volume count.  If you wish to test this yourself you will also need the following code:

extern string Settings_n_1 = "--------------------------";
extern int Side = 1;
extern int MP_Y = 0; 
extern int MP_X = 0;



and


 // Write Procedure
    void Write(string LBL, double side, int pos_x, int pos_y, string text, int fontsize, string fontname, color Tcolor=CLR_NONE)
       {
       ObjectCreate(LBL, OBJ_LABEL, 0, 0, 0);
       ObjectSetText(LBL,text, fontsize, fontname, Tcolor);
       ObjectSet(LBL, OBJPROP_CORNER, side);
       ObjectSet(LBL, OBJPROP_XDISTANCE, pos_x);
       ObjectSet(LBL, OBJPROP_YDISTANCE, pos_y);
       }


Thanks!

Reason: