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.
Popular Symbols Trading Hours
Open/close times, weekend hours & live market status:
Related Articles
Is MT5 Good for Beginners? A Straightforward Answer for 2026
Is MT5 good for beginners in 2026? Learn the pros, cons, and how Camovia Tray turns MT5 into a tray tool for quick quotes and position management without keeping the terminal open.
Best MT5 Brokers for Algo Trading in 2026: Where to Run Your EAs with Confidence
Discover the best MT5 brokers for algo trading in 2026 and learn how Camovia Tray helps you monitor quotes, manage positions, and keep your terminal secure—all from your system tray.
MetaTrader Scripts vs. Tray Tools: The Better Way to Manage Open Orders
Manage MT5/MT4 open orders without launching the terminal. Camovia Tray lets you view positions, check P&L, and close trades from the system tray—data stays local.
Pattern Indicators Are Not Trading Signals: A Common Misconception That Costs Traders
For MetaTrader traders using pattern indicators, Camovia Tray lets you monitor quotes and manage positions from the system tray without keeping the terminal open.
Mastering Candlestick Patterns: Why Your Chart Indicator Isn't Enough Without a Clear Workspace
Discover how Camovia Tray helps candlestick pattern traders eliminate workspace friction, keep MT5/MT4 data accessible from the system tray, and never miss a signal again—all while keeping your quotes and positions local.