I tried the mt5 TradeClass today ,Why I can't get the Ask price?

 

#include <Trade\SymbolInfo.mqh>
CSymbolInfo mysymbol;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   double Ask=mysymbol.Ask();
   Print("Ask is : ",Ask);
  }

print result is 0.0,   I don't know why? maybe I missed something?

thanks your reply,,,




 

Add this in your code:

mysymbol.RefreshRates();
 
Anthony Garot:

Add this in your code:

Where should I add it, like this ? :-D


#include <Trade\SymbolInfo.mqh>
CSymbolInfo mysymbol;
//+------------------------------------------------------------------+
//| Script program start function                                    |

mysymbol.RefreshRates();
//+------------------------------------------------------------------+
void OnStart()
  {
   double Ask=mysymbol.Ask();
   Print("Ask is : ",Ask);
  }

 
Alain Verleyen:
Where should I add it, like this ? :-D

Ha! Point taken.

:-D

void OnStart()
  {
   mysymbol.RefreshRates();
   double Ask=mysymbol.Ask();
   Print("Ask is : ",Ask);
  }
 
Anthony Garot:

Ha! Point taken.

:-D

Tanks so much!   The first time to try mt5 TradeClass   : -(
Reason: