MarketInfo Universal Lib for MQL 4

Universal MarketInfo Service Library for MT4 & MT5

Bring simplicity and power to your trading projects with the Universal MarketInfo Service — a professional library that exposes a unified API for both MetaTrader 4 and MetaTrader 5.

No more rewriting code for each platform. With this library, you can:
  • Access symbol data, OHLC prices, spreads, and volatility with a single call.
  • Query account balance, free margin, stop levels, and lot constraints.
  • Work with currency precision, pip values, and normalized volumes.
  • Retrieve time data and detect Strategy Tester mode.

Whether you’re building Expert Advisors, indicators, or scripts, this library ensures your code is portable, reliable, and future‑proof.

💡 Write once, run everywhere — MT4 & MT5.

⚡ Save time, reduce errors, and focus on strategy, not boilerplate.

You can download the free source code of this library from github and you can include it directly in your EA code; please note that the source file is compatible with both MT4 and MT5 platforms.


Method Documentation

Symbol & Prices

  • string GetSymbol() → Returns the name of the current chart symbol.

  • double GetAskPrice() → Latest known seller’s price (ask).

  • double GetBidPrice() → Latest known buyer’s price (bid).

  • double GetSpread() → Spread value in points.

OHLC Data

  • double GetClose(int shift=0, ENUM_TIMEFRAMES tf=PERIOD_CURRENT) → Close price of a bar.

  • double GetOpen(int shift=0, ENUM_TIMEFRAMES tf=PERIOD_CURRENT) → Open price of a bar.

  • double GetHigh(int shift=0, ENUM_TIMEFRAMES tf=PERIOD_CURRENT) → High price of a bar.

  • double GetLow(int shift=0, ENUM_TIMEFRAMES tf=PERIOD_CURRENT) → Low price of a bar.

Volume & Lot

  • double GetMinVolToPlay() → Minimum permitted lot size.

  • double GetMaxVolToPlay() → Maximum permitted lot size.

  • double GetCurrencyLotSize() → Lot size in base currency.

  • double GetCurrencyLotStep() → Step for changing lots.

  • double NormalizeVolume(double volume) → Normalizes volume within min/max constraints.

Account & Risk

  • double GetAccountBalance() → Current account balance.

  • double GetFreeMarginAfterCheck(double volume, int opType, double price=0.0) → Free margin after opening an order.

  • double GetMinStopLevel() → Minimum stop level in points.

  • double GetFreezeLevel() → Freeze level in points.

Currency Precision

  • int GetCurrencyDigits() → Number of digits after decimal.

  • void SetCurrencyDigits(int customDigits) → Override digits precision.

  • double GetCurrencyPoint() → Point size in quote currency.

  • int GetCurrencyPipeVal() → Pip value for the currency.

  • string DoubleToCurrencyString(double subject) → Formats a double as currency string.

  • double AdaptToCurrency(double subject) → Normalizes a value to currency precision.

Time Utilities

  • datetime GetTime(int shift=0, ENUM_TIMEFRAMES tf=PERIOD_CURRENT) → Time of a bar.

  • int GetHour() → Hour of last known server time.

  • int GetHour(datetime time) → Hour of a given time.

  • int GetMinute() → Minute of last known server time.

  • int GetMinute(datetime time) → Minute of a given time.

Volatility

  • double GetVolatility(int period, double multiplier, ENUM_TIMEFRAMES tf=PERIOD_CURRENT) → Volatility (ATR‑based).

Environment

  • bool IsTestingMode() → Returns true if running in Strategy Tester.

  • void Destroy() → Cleans up the service instance.


Usage Example 

// Include the market info API header
#import "vladefix/market-info-lib-v1.00.ex5"
   string GetSymbol();
   double GetAskPrice();
   double GetBidPrice();
   double GetClose(int, ENUM_TIMEFRAMES);
   double GetOpen(int, ENUM_TIMEFRAMES);
   double GetHigh(int, ENUM_TIMEFRAMES);
   double GetLow(int, ENUM_TIMEFRAMES);
   double GetSpread();
   double GetMinVolToPlay();
   double GetMaxVolToPlay();
   double GetCurrencyLotSize();
   double GetCurrencyLotStep();
   double NormalizeVolume(double);
   double GetAccountBalance();
   double GetMinStopLevel();
   double GetFreezeLevel();
   double AdaptToCurrency(double);
   double GetVolatility(int, double, ENUM_TIMEFRAMES);
   int GetCurrencyDigits();
   void SetCurrencyDigits(int);
   double GetCurrencyPoint();
   int GetCurrencyPipeVal();
   datetime GetTime(int, ENUM_TIMEFRAMES);
   int GetHour();
   int GetHour(datetime);
   int GetMinute();
   int GetMinute(datetime);
   double GetFreeMarginAfterCheck(double, int, double);
   string DoubleToCurrencyString(double);
   bool IsTestingMode();
   void DestroyMarketInfoLib();
#import

//-------------------------------------------------------
// Initialization function (OnInit)
//-------------------------------------------------------
int OnInit()
{
   Print("Symbol: ", GetSymbol());
   Print("Ask: ", GetAskPrice(), " | Bid: ", GetBidPrice());
   Print("Spread: ", GetSpread(), " points");

   double lot = NormalizeVolume(0.158);
   Print("Normalized lot: ", lot);

   double balance = GetAccountBalance();
   Print("Account Balance: ", DoubleToCurrencyString(balance));

   if(IsTestingMode())
      Print("Running in Strategy Tester...");
}


void OnDeinit(const int reason)
  {
     DestroyMarketInfoLib()
  }

Altri dall’autore
Just another plain Super Trend indicator.  On this one i have added another buffer (on index 2) which can be used on EA; the values is -1 to identify a bearish trend while for bullish trend the value  is 1. Here a code snippet:  int trend = ( int ) iCustom ( NULL , Timeframe, "SuperTrend" , Period , Multiplier, 2 , 1 );   It work on every timeframe.  If you need help to integrate it on your EA, don't hesitate to contact me.
FREE
This simple logging library is designed to provide clear and contextual log output with minimal hassle. It exposes five  methods: LogError Message (message) LogWarn Message (message) LogInfo Message (message) LogDebug Message (message) LogTrace Message (message) Each method prints the provided message to the console only if the severity level meets or exceeds the current threshold set by a global variable logLevel. This means you control the verbosity of your application's logs by adjusting logL
FREE
This simple logging library is designed to provide clear and contextual log output with minimal hassle. It exposes five  methods: LogErrorMessage(message) LogWarn Message (message) LogInfo Message (message) LogDebug Message (message) LogTrace Message (message) Each method prints the provided message to the console only if the severity level meets or exceeds the current threshold set by a global variable logLevel. This means you control the verbosity of your application's logs by adjusting logLev
FREE
This  EA is a swing strategy  with a martingale  system used to recover trades whenever the trend goes in the opposite direction in order to minimize the looses. The settings are simplified in order to work in almost every condition and it was designed to work with small accounts; though, the minimum recommended is 500$. A s every martingale system, it works efficiently if it has enough margin, so keep enough margin free. Here some reccomended configurations:  Property Name GBPUSD AUDJPY  EURGB
Universal MarketInfo Service Library for MT4 & MT5 Bring simplicity and power to your trading projects with the Universal MarketInfo Service — a professional library that exposes a unified API for both MetaTrader 4 and MetaTrader 5. No more rewriting code for each platform. With this library, you can: Access symbol data, OHLC prices, spreads, and volatility with a single call. Query account balance, free margin, stop levels, and lot constraints . Work with currency precision, pip values, and
FREE
Filtro:
Nessuna recensione
Rispondi alla recensione