Problem of iVolume() in 1Min Chart

 

Hi Everyone, I had a problem on iVolume() as the result of iVolume() in MetaEditor is different to what I see in the MT4 Chart. Pls see attached captioned screens that the average of the volume in the charts are more than 10, but average of the volume is 1 when I printed iVolumn() at the back test. Can anyone can help? Thank you very much!


iVolume("XAUUSD",1,0);

Files:
 
what code and language did you use ?
 

I'm using MQL4 Language in Metaeditor. I would like to open Buy order when the volume is over 60.0 but the volume which show in the backtest is huge different to the chart in MT4 platform. Do you know what is the problem? Pls see below. Thank you.


double Vol0;
double VLine=60.0;

Vol0=iVolume("XAUUSD",1,0); // Check Volume in 1 Min chart

Print("Volume =", Vol0);

if(Vol0>VLine) // Open Order when Volume > 60.0
         {
         OrderSend(Symbol(), OP_BUY, 1, Ask, 3, 0, 0); 
         PlaySound("alert. wav");
         }
 
Your first image shows only one Print per minute (Volume=1). I guess the code you posted is inside a new bar check. Context matters, post all the relevant code if you need help.
          New candle - MQL4 programming forum
 

I would like to open order when Stoch Up Cross AND Volume is above 60.0. Since I have not finished coding yet, please see below code for your ref. Thank you for your help.


string symbol="XAUUSD";
int period=1;
double Lots=0.1;
int StochDateK=5;
int StochDateD=3;
int StochDateS=3;
double StochM0, StochM1, StochS0, StochS1;
double Vol0;
double VLine=60.0;
string Status;
datetime LastActiontime;

void OnTick()
  {
   if(LastActiontime!=Time[0])
   {
      StochM0=iStochastic(symbol,period,StochDateK,StochDateD,StochDateS,MODE_SMA,0,MODE_MAIN,0);
      StochS0=iStochastic(symbol,period,StochDateK,StochDateD,StochDateS,MODE_SMA,0,MODE_SIGNAL,0);
      StochM1=iStochastic(symbol,period,StochDateK,StochDateD,StochDateS,MODE_SMA,0,MODE_MAIN,1);
      StochS1=iStochastic(symbol,period,StochDateK,StochDateD,StochDateS,MODE_SMA,0,MODE_SIGNAL,1);

   if(StochM0>StochS0 && StochM1<StochS1)
      {
      Status="UpCross";
      }   
      
   Vol0=iVolume("XAUUSD",1,0); 
   
   Print("Volume =", Vol0);
   
      //---Open Order
      if(Vol0>VLine && Status=="UpCross") 
         {
         OrderSend(Symbol(), OP_BUY, 1, Ask, 3, 0, 0); 
         PlaySound("alert. wav");
         }
            
   }

      LastActiontime=Time[0];
   }
Files:
1.jpg  153 kb
2.jpg  188 kb
 

Your

Print("Volume =", Vol0);

Only runs on the first tick of a new bar because it is inside the new bar check.