MarketInfo Universal Lib for MQL 4
- librerie
- COSTEL VLAD
- Versione: 1.0
- 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.
💡 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.
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() }
