Download MetaTrader 5

Bug in CSymboInfo.mqh ? Need help

To add comments, please log in or register
Have you made a screenshot in MetaTrader? Share it with friends!
thien_v
91
thien_v 2011.07.31 13:59 
#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
11821
Rashid Umarov 2011.07.31 15:05  

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 2011.07.31 15:36  

Hi Rosh,

can you write the solution here? :)


thien_v
91
thien_v 2011.07.31 16:14  

#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
6604
Alexey Da 2011.08.01 09:19  
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 2011.08.01 23:10  

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 2011.08.01 23:17  

hi! Thanks a lot guys! =) it is working now!
Trew
10
Trew 2011.09.19 20:12  
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
6604
Alexey Da 2011.09.20 10:56  
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 2011.09.20 14:52  
Thanks a lot, that does work.

kan1
23
kan1 2012.04.11 16:06  

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