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 structureif( 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 pricesvoidOnTick()
{
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 pricesvoidOnTick()
{
MqlTick oTick; // Declare variable of MqlTick structureif( 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 ...
};
};
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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:
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.
If you want to mimic the MQL4 style of predefined variables, then you can use one the following examples (sample code is untested/uncompiled):