Download MetaTrader 5

Bug in CSymboInfo.mqh ? Need help

To add comments, please log in or register
thien_v
91
thien_v  
#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? 

Rashid Umarov
Admin
12400
Rashid Umarov  

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
thien_v
91
thien_v  

Hi Rosh,

can you write the solution here? :)


thien_v
91
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.

Alexey Da
Moderator
6601
Alexey Da  
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.

thien_v
91
thien_v  

Hi,


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



thien_v
91
thien_v  

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

I am also having this problem.

thanks
Alexey Da
Moderator
6601
Alexey Da  
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);
     }
  }

 

Trew
10
Trew  
Thanks a lot, that does work.

kan1
23
kan1  

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.


To add comments, please log in or register