Banned temporary for too many messages ? - page 2

 

Hello, hope you all good. This is my first time coding. 

I'm getting this error with (Bid and Ask for MQL5) when I'm compiling my code for mt5


this is my code:

// Calculate current spread()

      double calculate_current spread()

   {

    current_spread = current_spreadInPoints;

    double current_spread = Ask - Bid;

    double current_spreadInPoints = current_spread/_Point;

    return(current_spreadInPoints);

   }


I'm getting this error: "Bid" undeclared identifier >>> "Ask" undeclared identifier

>> The code works well on MQL4 but this terms "Bid" and "Ask" are giving me errors  on MQL5 code

>> My question is how do I call a Bid price and the Ask price in MQL5?

is there a term that i need to use?

 
Documentation on MQL5: Market Info / SymbolInfoTick
Documentation on MQL5: Market Info / SymbolInfoTick
  • www.mql5.com
SymbolInfoTick - Market Info - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Senku Johannes #: I'm getting this error with (Bid and Ask for MQL5) when I'm compiling my code for mt. this is my code: I'm getting this error: "Bid" undeclared identifier >>> "Ask" undeclared identifier. The code works well on MQL4 but this terms "Bid" and "Ask" are giving me errors  on MQL5 code. My question is how do I call a Bid price and the Ask price in MQL5? is there a term that i need to use?

Unlike MQL4, MQL5 does not have the predefined variables "Ask" and "Bid". So, you will have to assign them yourself, either by using the SymbolInfoDouble() function or by using the SymbolInfoTick() function.

Example using SymbolInfoDouble() function (sample code is untested/uncompiled):

double
   Ask = SymbolInfoDouble( _Symbol, SYMBOL_ASK ),   // Get symbol's current Ask price
   Bid = SymbolInfoDouble( _Symbol, SYMBOL_BID );   // Get symbol's current Bid price

Example using SymbolInfoTick() function (sample code is untested/uncompiled):

MqlTick oTick; // Declare variable of MqlTick structure

if( SymbolInfoTick( _Symbol, oTick ) )
{
   double
      Ask = oTick.ask,   // Get symbol's current Ask price or just use "oTick.ask" directly in your code instead of "Ask"
      Bid = oTick.bid;   // Get symbol's current Bid price or just use "oTick.bid" directly in your code instead of "Bid"

   // Rest of your code goes here ...
};

If you want to mimic the MQL4 style of predefined variables, then you can use one the following examples (sample code is untested/uncompiled):

double Ask, Bid; // Globally scoped Ask and Bid prices

void OnTick()
{
   Ask = SymbolInfoDouble( _Symbol, SYMBOL_ASK ),   // Get symbol's current Ask price
   Bid = SymbolInfoDouble( _Symbol, SYMBOL_BID );   // Get symbol's current Bid price

   // Rest of your code goes here
};
double Ask, Bid; // Globally scoped Ask and Bid prices

void OnTick()
{
   MqlTick oTick; // Declare variable of MqlTick structure

   if( SymbolInfoTick( _Symbol, oTick ) )
   {
      Ask = oTick.ask,   // Get symbol's current Ask price
      Bid = oTick.bid;   // Get symbol's current Bid price

      // Rest of your code goes here ...
   };
};
Documentation on MQL5: Market Info / SymbolInfoDouble
Documentation on MQL5: Market Info / SymbolInfoDouble
  • www.mql5.com
SymbolInfoDouble - Market Info - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: