Seconds Tick and Range Charts MT5

  • Utilities
  • Quoc Dat Quach
    Quoc Dat Quach
    Software engineer with 8 years in fintech and mobile, writing MQL4/MQL5 since 2017. I build Expert Advisors, indicators, trade and risk-management panels and utilities for MT4/MT5, and I trade forex and gold on MT5 myself.
  • Version: 1.0
  • Activations: 10

Seconds bars (1 to 30 seconds), tick bars and range bars for MetaTrader 5, built from the broker's real tick history as a custom symbol and updated on every tick. Any indicator, template or EA can run on the chart. A helper on the chart shows the real time of every bar. It never trades on a chart.

What it does

Attach the EA to the chart of a broker symbol. It:

  • creates a custom symbol, for example EURUSD_S5, with the specifications of the source symbol
  • builds its history from the broker's real ticks, the last 3 days by default, in slices (in the tests 3 days of BTCUSDm, 376,095 ticks, took 2.0 s)
  • opens the custom chart, with your template if you name one
  • adds every new tick of the source to the custom chart as it arrives
  • reads every new bar back from the terminal a few times per second (measured in MetaTrader 5 build 6230: bars that the terminal builds from live ticks can go missing when no chart or program reads them; regular reads prevent it)
  • checks the bars against the broker's tick history every 60 seconds, and counts the ticks the custom symbol holds for them
  • when it starts again on an existing custom chart (after a terminal restart, for example), checks that the bars of the last part of the history are all there before it continues
  • if a bar stays wrong, builds the whole custom symbol again from the tick history, from the same first tick: the only repair that was exact in every test (measured in build 6230: writing single bars or deleting part of a custom symbol that receives live ticks can make the terminal lose other bars or ticks)

Chart types

  • Seconds bars: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20 or 30 seconds. A bar holds the ticks of one interval. An interval without ticks has no bar, the same way a minute without ticks has no bar on M1.
  • Tick bars: a new bar every N ticks.
  • Range bars: a new bar opens when the next price would make the bar's high-low range larger than N points, so no bar is larger than N points. When the price jumps, the new bar opens at the new price; no filler bars are drawn for the jump.

Bars are drawn from the Bid price. The tick volume of a bar is the number of ticks in it.

Several copies can run at once, one EA per custom symbol: for example 5-second bars of EURUSD on one chart and 200-point range bars of XAUUSD on another. A second EA for the same custom symbol does not start and says why on its panel.

Every tick in exactly one bar

The custom symbol receives the broker's ticks themselves, not a copy of the bars. In the tests the bars were compared with an independent rebuild from the broker's tick history:

  • the sum of the tick volumes equals the number of source ticks
  • every bar, open, high, low, close and tick volume, equals the rebuild
  • for seconds bars, every interval without a bar had no source tick

In a 75-minute test with 10 custom symbols at once (1, 2 and 5-second bars, 20, 50 and 100-tick bars, 200 and 1000-point range bars; 2,537,558 ticks in all), all three held for every symbol, also for the symbols built again after the terminal had been frozen for 2 minutes.

Gaps on seconds charts: on BTCUSDm (about one tick per second on a Saturday) the 1-second chart had 81,920 bars for 121,859 ticks. Every 1-second interval without a bar was checked against the broker's ticks and had none. A gap on a seconds chart is a time in which the broker sent no tick, not a lost bar.

The time scale (please read)

MetaTrader 5 has no timeframe below one minute, and a custom chart is always drawn on the M1 time scale. So each bar of the custom chart takes one minute slot, and the dates under the chart count these slots from January 1971: they are not the clock. This is the only way bars shorter than a minute can exist on a MetaTrader 5 chart.

The EA adds a small helper to the custom chart that shows the real time (everywhere in this description, real time means the broker's server time, as on the broker symbol's own chart):

  • Last bar: start time to the millisecond, length and number of ticks
  • Cursor bar: the same for the bar under the mouse
  • a second time scale with real times above the chart's own one
  • whether the chart is updated: "Live: updated on every tick of EURUSD", "Building history from real ticks: 40.0%", "Waiting for the connection to the trade server", "Checking the bars after the start (up to 60 s)", "Not updating for 12 s: check the EA on the EURUSD chart" or "Not updating: no EA builds EURUSD_S5 now"

Keep the custom chart on M1: one M1 bar is one seconds, tick or range bar. A higher timeframe merges several bars.

Speed

Measured in a 75-minute test with 10 EAs and 8 custom charts at once in one terminal: the time from the moment an indicator on the source chart saw a tick to the moment an indicator on the custom chart saw it. BTCUSDm was live on a demo account. Gold and the Nasdaq index were closed (Saturday), so their charts were fed with Friday's real ticks at their real pace, up to 61 ticks per second.

Custom chart Ticks per second Median 99% of ticks within Slowest
BTCUSDm 5-second bars (live) 1 0.2 ms 30 ms 262 ms
BTCUSDm 1-second bars (live) 0.9 0.3 ms 35 ms 262 ms
BTCUSDm 50-tick bars (live) 1 0.2 ms 32 ms 281 ms
Gold 1-second bars (replay) 12 0.4 ms 65 ms 173 ms
Gold 100-tick bars (replay) 12 0.3 ms 111 ms 140 ms
Nasdaq 5-second bars (replay) 61 0.6 ms 40 ms 1.7 s (*)
Nasdaq 1000-point range bars (replay) 61 0.8 ms 41 ms 2.5 s (*)

(*) In the 2 minutes after the terminal had been frozen for 2 minutes: the delayed ticks arrived at once and the EA built the symbol again. At all other times the slowest tick took 142 ms and 156 ms. Over the 75 minutes the terminal used about one CPU core in all and 680 to 703 MB of memory, with no slowdown from the first to the last 10 minutes.

The panel on the source chart shows the EA's own write time per tick event, median and 99th percentile, while it runs (0.03 ms median in the test).

Connection loss, restart and changes

Measured in the same 75-minute test, the terminal restarts after it and a separate test of input changes:

  • Terminal frozen for 2 minutes: when it came back it reported the connection to the trade server lost and restored. Within 15 seconds the EAs found 4 custom symbols with missing bars or ticks and built them again (0.2 to 2.4 s each). Afterwards all 10 symbols passed the check above. A network cut of several minutes was not tested.
  • Timeframe of the source chart changed (M1 to M5 and back): the EA continued from the last bar, no rebuild.
  • Inputs changed through a template with other inputs: the EA continued from the last bar.
  • Chart type changed on a running EA (5-second to 50-tick bars and back): it built the new custom symbol and left the old chart in place; back on 5-second bars after 91 s, it continued the old symbol and added the ticks of the 91 s. Both symbols passed the check above.
  • Source chart closed for 3 minutes: the helper showed "Not updating: no EA builds BTCUSDm_S1 now". When the chart was opened again with the EA, it continued from the last bar and the ticks of the 3 minutes were on the chart 0.34 s later.
  • Terminal closed and started again 7 times (closed for 3 seconds to about 1.5 minutes): 40 of the 51 EA starts continued from their last bars. 11 found bars missing (dropped by the terminal, see the limits), waited the 60 seconds (with the final version the helper shows "Checking the bars after the start" meanwhile) and built their symbols again (0.2 to 1.3 s each). After 5 of the 7 starts the terminal dropped bars of the symbol without an open chart a few minutes later; the EA found it with its next check and built the symbol again (in 2 tests the test ended before that check).
  • A second EA for the same custom symbol did not start, also at 7 terminal starts, when all the EAs of the terminal start together.

Removing the EA leaves the custom symbol and its chart in place. Attach it again with the same settings and it continues from the last bar, after checking that the bars before it are all there (if not, it builds the history again by itself).

Inputs

Input Default Meaning
Chart type Seconds bars Seconds bars, Tick bars, Range bars
Seconds bars: seconds per bar 5 seconds 1, 2, 3, 4, 5, 6, 10, 12, 15, 20 or 30
Tick bars: ticks per bar 100 1 to 100,000
Range bars: range of a bar in points 100 Points of the source symbol
Source symbol empty Empty = the symbol of the chart the EA is attached to
Days of real tick history to build 3 0.01 to 60, used when the custom symbol is built. The broker's tick history may be shorter. A new value does not rebuild an existing custom symbol: set the next input to true once for that
Build the history again at start false Otherwise it continues from the last bar when the chart type, its setting and the source are the same
Custom symbol name empty Empty = automatic, for example EURUSD_S5, EURUSD_T100, EURUSD_R100
Open the custom chart true
Template for the custom chart empty A template from MQL5\Profiles\Templates, applied when the chart opens
Show the real time of the bars on the custom chart true The helper described above
Close the custom chart when the EA is removed false
Tester only: open and close sample positions true See below

Strategy Tester

MetaTrader 5 does not allow custom symbols or new charts in the Strategy Tester (measured: both are refused with error 4014). In the tester the EA therefore builds the same bars in memory, with the same code, from the ticks the tester feeds it, and in visual mode draws them in a subwindow under the tester chart. At the end of a run it writes how many bars it built and that every tick is in exactly one bar. Use "Every tick based on real ticks" to see the bars built from the broker's real ticks.

In the Strategy Tester only, the EA also opens and closes a short series of sample positions, because the Market checks that an Expert Advisor trades:

  • minimum volume, one position at a time, up to 30 positions
  • free margin is checked before every new position; with too little money it writes a note and sends nothing

The sample positions are not a trading strategy and their results say nothing about profit. On a live or demo chart the EA never sends, changes or closes an order.

Limits (please read before buying)

  • The time scale counts slots, not the clock. See "The time scale" above. Indicators that use the time of a bar (sessions, daily pivots, time filters) see slot times on the custom chart, not real times.
  • The quote of the custom symbol is one tick behind. Measured: when an indicator or EA on the custom chart is called for a new tick, the bars and the tick history of the custom symbol already contain it, but the quote of the custom symbol (Market Watch, SymbolInfoTick, the Bid line on the chart) shows the previous tick until the next one is added. Seven ways around it were tried in MetaTrader 5 build 6230 and none worked. An indicator or EA on the custom chart should read prices from the bars (the close of the last bar is the newest tick).
  • Custom symbols cannot be traded. An EA that runs on the custom chart has to send its orders for the broker symbol.
  • Bid charts only. Symbols that the broker draws by Last price (exchange stocks and futures) are refused with a message on the panel.
  • History depth is the broker's. The first build downloads the broker's tick history; brokers keep it for a limited time. A long history of short bars can pass the "Max bars in chart" setting of the terminal (Tools, Options, Charts); the chart then shows only the newest bars. The EA's own checks read at most half of that setting back, so a low setting only makes them look at fewer bars (tested with 5,000 and a 1-second chart of about 80,000 bars: no extra rebuilds in 8 minutes).
  • Seconds bars have room for a limited time. The slots must stay in the past: a 1-second chart has room for about 339 days of bars after its start, a 5-second chart for about 4.6 years. When the room is used up the EA builds the history again by itself.
  • Keep the EA running while you use the custom chart. Measured in build 6230: when the EA was removed or the terminal restarted, the terminal sometimes dropped the bars of the newest part of a custom symbol (up to one slot day, 1,440 bars) while it kept the ticks. A chart left open without the EA then shows a gap. When the EA starts again it finds this and builds the symbol again. After a restart the chart can show such a gap for up to about a minute: the EA waits up to 60 seconds for the terminal to load the bars (the helper then shows "Checking the bars after the start"), and if bars are still missing it builds the symbol again (0.2 to 1.3 s in the tests). In the tests the terminal also dropped bars a few minutes after a restart, with the EA running: the EA found it with its checks (every 60 seconds; in three tests the repair came 74 seconds after the test's own verifier had seen the gap) and built the symbol again; a symbol without an open chart may keep the gap until that check or the next start. It happened most on a custom symbol without an open chart.
  • A repair empties and refills the whole custom symbol. When a check finds a wrong or missing bar, the EA deletes the custom symbol's ticks and bars and writes them again from the same first tick (0.2 to 2.4 s in the tests). Indicators and EAs on the custom chart see the history vanish and come back during that time.
  • One EA per custom symbol, and it uses the EA slot of its chart: attach it to a spare chart of the source symbol, not to the chart of a trading EA.
  • No Strategy Tester on the custom symbol. Measured in build 6230: the tester feeds the ticks of the custom symbol but builds only some of its bars or none (1,324 and 0 of 4,316 M1 bars in two tests), so an EA that needs the bars cannot be tested on it. Test such an EA on the broker symbol.
  • Tested environment:
    • MetaTrader 5 build 6230 only, Windows 10, a 3840 x 2160 screen at 288 dpi
    • a demo account at a retail CFD broker: BTCUSDm and ETHUSDm live, Friday's XAUUSDm and USTECm ticks replayed at their real pace (Saturday tests); EURUSDm, XAUUSDm and USTECm history for the screenshots
    • Strategy Tester: netting and hedging demo accounts of the platform's demo server, EURUSD, GBPUSD, XAUUSD
    • longest test 75 minutes; not tested on other brokers, real-money accounts or MQL5 VPS
  • Please try it with the free Strategy Tester demo first. The demo shows the bars in a subwindow of the tester only (see "Strategy Tester" above); the custom chart on a live or demo account needs the full version.
More from author
Repaint Inspector measures whether an indicator repaints instead of taking the claim on trust. You attach it to a chart, name any custom indicator and its parameter list, and it re-reads that indicator's buffers on bars that have already closed, counting every value that moves, every value that appears and every value that disappears, together with how far back in history that still happens. It is a measuring tool. On a chart it never sends an order. In the Strategy Tester it opens and closes on
FREE
Symbol Spec Auditor puts the part of a symbol's contract specification that decides position size and trading cost into one panel on the chart: point value, spread cost, margin, swap, execution rules and trading sessions. Raw specification values are converted into money per 1.00 lot in the account currency, and the broker settings that quietly break lot-size code are listed as warnings. One button exports the same audit for every Market Watch symbol to a CSV file. It is a checking tool. It plac
FREE
Spread Profile by Hour builds the spread distribution of one symbol for every hour of the server day from your broker's own tick history, and draws it as 24 bars. The solid part of a bar is the median spread of that hour, the lighter cap reaches the 90th percentile. Enter the stop size you normally use and every bar is labelled with its median spread as a share of that stop, so the cost is in the same unit as your risk. It is a measuring tool. It places no orders, uses no DLL and no WebRequest,
FREE
A local trade copier for MetaTrader 5. It copies positions between MT5 terminals on the same Windows PC or VPS and sizes each copy from both brokers' contract specifications (contract size, tick value, account currency), so a copy carries the same exposure even when the two brokers define a lot differently. It never opens a second copy of the same master position. What it does You attach the same EA to one chart in each terminal: In the master terminal, set the Mode input to Master. In each rece
An account ledger for MetaTrader 5 that splits your results by magic number, symbol, weekday and hour, shows price P/L, commission, swap and fees in separate columns, and measures the spread paid at each fill and the slippage against the price you asked for. The totals are checked against the account balance on every update. It never trades on a chart. What it does Attach it to one chart. It reads the account's deal history, rebuilds every position from its deals and shows the result on a panel:
Filter:
No reviews
Reply to review