Bug in CSymboInfo.mqh ? Need help

 
#include <Trade/SymbolInfo.mqh>
CSymbolInfo sym;

int OnInit()
  {

  

double askprice =sym.Ask();

Print ( "askprice =", Ask());

}

//I got the result : askprice = 0. I cant manage to get the last ask price from OOP. So it is bug in SymbolInfo.mqh?


What is wrong here? 

 

See help for this method - https://www.mql5.com/en/docs/standardlibrary/tradeclasses/csymbolinfo/csymbolinfoask:

Note

The symbol should be selected by Name method.

Documentation on MQL5: Standard Library / Trade Classes / CSymbolInfo / Ask
  • www.mql5.com
Standard Library / Trade Classes / CSymbolInfo / Ask - Documentation on MQL5
 

Hi Rosh,

can you write the solution here? :)


 
#include <Trade/SymbolInfo.mqh>
CSymbolInfo sym;

int OnInit()
  {


sym.Name(_Symbol);    <----? this one?

  

double askprice =sym.Ask();

Print ( "askprice =", Ask());

}



// still doesnt work. Got zero as answer.

 
thien_v:

#include <Trade/SymbolInfo.mqh>
CSymbolInfo sym;

int OnInit()
  {


sym.Name(_Symbol);    <----? this one?

  

double askprice =sym.Ask();

Print ( "askprice =", Ask());

}



// still doesnt work. Got zero as answer.

Try to call RefreshRates() method before you try to get any rates.

 

Hi,


I attempted with sym.Refreshrate(); , but still dont work.  Can you try it in your metatrader5? Something wrong with my metatrader?



 

hi! Thanks a lot guys! =) it is working now!
 
Could you please say what it was that you did to fix your error please?

I am also having this problem.

thanks
 
Trew:
Could you please say what it was that you did to fix your error please?

I am also having this problem.

thanks

This code should work correctly

#include <Trade/SymbolInfo.mqh>
CSymbolInfo sym;
int OnInit()
  {
   sym.Name(_Symbol);
   if(sym.RefreshRates())
     {
      double askprice=sym.Ask();
      Print("askprice =",askprice);
     }
  }

 

 
Thanks a lot, that does work.

 

Hi All,

I have similar problem, but with "LastHigh()" and "LastLow()" methods from CSymbolInfo. I have tried all the above suggestions, but I still get a ZERO value returned for these.

I can get valid numbers for others like AskHigh(), Ask(), etc...   So, I don't have a clue what wrong at this point.

Any assistance/suggestions would be appreciated.

Thanks in advance.

Reason: