Download MetaTrader 5

How to get current price

To add comments, please log in or register
metatraderpk
20
metatraderpk 2015.12.21 18:33 

Hi all,


I am developing an EA. I want to get the current price, please tell me how to get it.


I have read that Bid is the current market price, is that true,


Thanks.

Snelle Moda
607
Snelle Moda 2015.12.21 19:07  

Hi

Use this to get the current BID, ASK price.

For STP brokers the BID price is used for the current market price as a reference punt.


// Info of the last tick.
//-----------------------
   
// To be used for getting recent/latest price quotes
   MqlTick Latest_Price; // Structure to get the latest prices      
   SymbolInfoTick(Symbol() ,Latest_Price); // Assign current prices to structure 

// The BID price.
   static double dBid_Price; 

// The ASK price.
   static double dAsk_Price; 

   dBid_Price = Latest_Price.bid;  // Current Bid price.
   dAsk_Price = Latest_Price.ask;  // Current Ask price.
Snelle Moda
607
Snelle Moda 2015.12.21 19:22  

You can also use this method:


// Info of the last BAR
//---------------------------------

// Rates Structure for the data of the Last incomplete BAR
   MqlRates BarData[1]; 
   CopyRates(Symbol(), Period(), 0, 1, BarData); // Copy the data of last incomplete BAR

// Copy latest close prijs.
   double Latest_Close_Price = BarData[0].close;
Xiangdong Guo
3784
Xiangdong Guo 2015.12.22 15:13  
metatraderpk:

Hi all,

I am developing an EA. I want to get the current price, please tell me how to get it.

I have read that Bid is the current market price, is that true,

Thanks.

double current_bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);

double current_ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); 

To add comments, please log in or register