How to Get Candlestick and Bar Prices in MQL4
Camovia Tray Team · 2026-09-15
You’re staring at a chart, and you know the story is in the bars—the opens, the highs, the lows, the closes. Whether you're coding an Expert Advisor to spot a breakout or just trying to understand why that last trade went south, you need a way to pull those numbers into your MQL4 code. It’s the foundation of almost any automated strategy, yet it’s surprisingly easy to get tripped up by the way MetaTrader actually stores this data.
In MQL4, every bar’s price data is sitting there, waiting for you to grab it. The key is understanding how it’s organized.
First, forget everything you know about reading a chart from left to right. MetaTrader stores price data in something called a timeseries array. In a timeseries, the very first element, index 0, is always the current bar. Index 1 is the bar before that, 2 is the one before that, and so on . So, when you're looking at a 1-hour chart and you want the close price of the last complete hour, you’re asking for Close[1].
The Two Main Ways to Get Your Prices
There are two clear paths to getting this data, and each has its place.
Method 1: The Predefined Arrays (The Quick Route)
If you're working on the current chart, this is the easiest and fastest method. MQL4 gives you four built-in arrays that are automatically filled with the price data for the current symbol and timeframe .
Open[]– The opening price.High[]– The highest price.Low[]– The lowest price.Close[]– The closing price.
Here’s how you’d use them in a script or EA:
// Get the current bar's open price
double currentOpen = Open[0];
// Get the closing price of the previous bar
double previousClose = Close[1];
// Find the highest price of the bar 3 bars ago
double highThreeBarsAgo = High[3]; While this is super convenient, remember that Close[0] is the current price, which is still changing. For a final, confirmed close, you'll want Close[1] .
Method 2: The i Functions (The Versatile Route)
Need data from a different symbol or timeframe than the one you're looking at? That’s where the i functions shine. Functions like iOpen(), iHigh(), iLow(), and iClose() let you specify exactly what you want .
The format is simple: iOpen(symbol, timeframe, shift).
// Get the current close price for EURUSD on the H1 chart
double eurUsdH1Close = iClose("EURUSD", PERIOD_H1, 0);
// Get the open price of the previous bar on the current chart
double currentSymbolOpen = iOpen(Symbol(), 0, 1); This flexibility is essential for strategies that watch multiple pairs or timeframes simultaneously. You can also use functions like iHigh() and iLow() to find the highest or lowest value over a specific number of bars , giving you a quick way to build a range check.
Beyond the Code: A Faster Way to Watch?
Once you’ve written your code, you’ll find yourself jumping back and forth—running a test, checking the chart, tweaking a number. That’s the cycle. But when you’re actually managing the positions that your logic is built to trade, the constant need to bring MetaTrader’s full window to the front just to check a current quote can break your flow.
That’s where Camovia Tray comes in. It essentially turns your MT5 or MT4 into a tray tool, giving you a quick, local snapshot of live quotes by simply hovering over the system tray icon. You can manage open positions—seeing their current profit and loss—and even close them with a click, all without restoring the full platform. It’s a quick way to stay on top of the market data, especially when you're refining your code and want to see the direct impact of the bars and prices you're working with.
MT4/MT5 Tray Assistant
Silent tracking, one-click close - check quotes and manage positions right from the tray.
Download Camovia TrayFrequently Asked Questions
Can the tray icon be disguised?
Yes. The tray icon can disguise itself as a cloud drive or a common system tool, so market watching stays low-key.
What is the tray lock feature?
Lock the tray function instantly at key moments to protect your privacy and prevent private information from leaking.
What information can I monitor?
Quotes and open positions: symbol, direction, open time, current P&L, and more - all visible in the popup positions tab. Click an order to close it.
Which languages are supported?
Chinese and English, switchable on both the website and the client.
Online Tools
Popular Symbols Trading Hours
Open/close times, weekend hours & live market status:
Related Articles
USOIL Market Open Time in Pakistan: A Complete Guide for Crude Oil Traders
USOIL market open time in Pakistan is 6:30 PM PKT during US daylight saving. Learn USOIL market hours, close time, and how Camovia Tray helps Pakistani traders check quotes and manage positions from the system tray.
The MQL4 to MQL5 ChatGPT Conversion Trap: What Every Trader Gets Wrong
Discover the MQL4 to MQL5 ChatGPT conversion trap and why AI code migration often fails. Learn what to fix and how Camovia Tray streamlines your MT5 workflow.
Dukascopy Historical Data in MT4: Import for Backtesting
Import Dukascopy tick and M1 data into MT4 for realistic backtests—download, convert, and verify—while live trades stay in view.
MT4 Global Variables: What They Do and How to Use Them
Discover how MT4 terminal global variables really work and why visibility matters. Camovia Tray lets you monitor your terminal state from the system tray.
3 MT4 Settings That Are Secretly Hurting Your Trading (And How to Fix Them)
Transform your MT4 with smarter settings. Check quotes & manage positions from the system tray using Camovia Tray—keep your workflow focused and private.
More Articles
How to Close All Positions on MT5 Mobile: 4 Taps
MT5 mobile closes every position in about four taps via Bulk Operations, but One-Click Trading must be enabled and the batch stops if you minimize the app.
The Biggest Misconception About "Making Indicators" in MT4/MT5 (And What It Actually Means for Traders)
Transform how you interact with MT5/MT4. Camovia Tray lets you view live quotes, manage positions, and close trades directly from the system tray—no terminal window required. Fast, private, and Windows-native.
CME Market Hours Thanksgiving: What Traders Should Know Before the Holiday Shortens Your Session
Check CME market hours for Thanksgiving and holiday weeks, plus a practical way to monitor futures quotes and positions from your system tray with Camovia Tray.
USOIL Trading Time in India: A Practical Guide for Evening Sessions
Track USOIL trading time in India, including US oil trading hours in IST, key evening sessions, and how Camovia Tray helps you monitor positions discreetly.
Can I Automate Options Trading on News Sentiment? The Reality Behind the Headlines
Discover how Camovia Tray helps you manage MT5/MT4 positions efficiently while exploring the realities of automating options trading on news sentiment.