Indicator buffer
Also called buffer, indicator buffers, data buffer, MQL5 buffer, signal buffer
An indicator buffer is the list of numbers an indicator stores, one value per candle, for each line, histogram or arrow it draws. Expert Advisors and alerts read these buffers to get the indicator's values.
Each line, histogram or arrow uses at least one buffer, and buffers are numbered from 0. When an Expert Advisor (EA, a program that trades for you) or an alert asks for "buffer number", this is the number it means. The wrong buffer or the wrong bar feeds a wrong value into your stop and your lot size.
What an indicator buffer holds, bar by bar
Think of a buffer as one column of numbers. A single moving average needs one buffer.
Two numbers locate any value. The buffer index says which column, counted from 0. The bar index says which candle. When an EA or alert reads it, the bar index is also counted from 0, starting at the candle still forming and going back in time. So bar 1 is the last closed candle.
In code the two numbers sit side by side. CopyBuffer(handle, 1, 1, 1, value) in MQL5 copies 1 value from buffer 1 starting at bar 1: the third argument is the starting bar and the fourth is how many values to copy. iCustom(..., 1, 1) in MQL4 means buffer 1, bar 1.
Not every buffer is a line you can see.
| Buffer kind | What it stores | Visible on the chart |
|---|---|---|
| Line or histogram | A value on every bar | Yes |
| Arrow or signal | Usually the price where the arrow sits, only on signal bars, empty elsewhere (some indicators store a flag such as 1 instead) | Yes, only where filled |
| Calculation | Intermediate numbers the indicator needs | No |
The grid below shows a volatility indicator with three buffers across four bars. ATR (Average True Range) measures how far price typically moves per candle. Here a fast (short-period) ATR fills buffer 0 and a slow (long-period) ATR fills buffer 1. Buffer 2 is a signal flag. It is empty on every bar except bar 2, where it holds 1 to mark a signal.
How a wrong buffer number changes your position size
The figures here are an illustrative example. You risk $150 per trade on a pair where one pip is 0.0001 and one standard lot (100,000 units) pays $10 per pip. Your rule: stop distance = 1.5 × the slow ATR, read on the last closed candle.
The slow ATR sits in buffer 1. On bar 1 it reads 0.0020, which is 20 pips.
Now set the EA to buffer 0 by mistake. It reads the fast ATR instead: 0.0010, or 10 pips.
- Stop distance: 10 × 1.5 = 15 pips
- Loss per lot if stopped: 15 × $10 = $150
- Lots: $150 ÷ $150 = 1.00
The money at risk is still $150. But you now hold twice the size behind a stop half as far away, and ordinary price movement reaches a 15-pip stop sooner than a 30-pip one. Nothing in the EA flags an error, because 0.0010 is a valid number.
Where buffers show up on your trading platform
The term comes from MQL4 and MQL5, the programming languages of the MetaTrader platforms, but you can meet buffers without writing code:
- The data readout. On the desktop platform, hover over a candle with the crosshair. The data window lists the value of each drawn line or arrow for that bar (colour and calculation buffers are not shown).
- EA and alert inputs. Fields such as "buffer number", "signal buffer" or "bar shift" ask you which column and which candle to read.
One common misread: the order you see on screen is not always the buffer index. In the indicator's settings, each drawn line, histogram or arrow gets its own row, but one drawn item can take more than one buffer.
Take a two-colour line. Its values sit in buffer 0 and its colour sits in buffer 1, so the next line you see is buffer 2, not buffer 1. Some plot types take several buffers each: a filled band takes 2, and drawn candles take 4, or 5 with colour. Every buffer after them moves down the numbering.
Checks before an EA or alert reads a buffer
- Map the numbers first. On the desktop platform where the EA runs, tap or hover over one closed candle (crosshair), note each value in the data readout, then confirm the EA logs the same value for the buffer you chose.
- Use the developer's buffer list if there is one. It beats counting lines on the chart.
- If the decision must not change, read bar 1. Bar 0 is still forming, so its value moves with every tick.
- If the buffer holds arrows, test for the indicator's empty marker (usually a very large number, sometimes 0). Check which one on a bar with no arrow.
- Check the units. A buffer may hold a price, a distance in price, or a plain score. Convert to pips before sizing a trade.
- Re-check after an indicator update. A new version can add a buffer and shift every index after it.
FAQ
Why does my EA get 0 or an error instead of a value from a custom indicator?
Usually the EA cannot load the indicator or it is not ready yet. The file name or folder the EA was given may not match, or the inputs it passes may not match the indicator's own input list. Right after a chart opens, the indicator may also still be calculating, so the first read fails. Check the platform's log for a loading error, fix the name and inputs, and let the EA try again on the next tick.
Can an EA read boxes, zones or text labels through a buffer?
Usually not. Rectangles, trend lines and labels are chart objects, which are stored separately from buffers. An EA can only read them through a buffer if the indicator's author also writes the zone prices into one.
Can a buffer value change after the candle has closed?
Yes, if the indicator recalculates past bars. A buffer only stores what the indicator writes, and the indicator can overwrite old cells. Scroll back after a few new candles and compare the values with what you noted earlier.









