Loading…

Bar Construction Comparison EA

A time bar closes on the clock, regardless of how much actually happened during it - one minute can hold three ticks or three hundred. A tick bar closes after a fixed number of price changes instead, so it speeds up in busy conditions and slows down in quiet ones. This EA builds both constructions from the same live tick feed at once: the chart's own PERIOD_CURRENT time bars, and a synthetic series built here by counting InpTicksPerBar price ticks per bar, stored in a plain array and averaged with a hand-written SMA helper (kept intentionally simple - both series are compared using the identical SMA logic, not two different indicator methods that would make the comparison meaningless). Every time either series finishes a new bar, its directional read (fast SMA above or below slow SMA) is compared against the most recently known read from the OTHER series, and the agreement is tallied. Direction-change ("flip") counts are tracked for each series separately too, since a construction that flips direction far more often than the other is itself informative about how much noise each one is picking up. It never sends an order. Notes and limitations - Report-only. This EA places no orders and manages no positions. - The tick-bar series is built purely from this chart's own ticks while the EA is running - it has no history before attach, and cannot be backfilled from past ticks the terminal never recorded. It is also capped at 5000 stored tick bars; once full, further ticks still advance the forming bar count but new closed tick bars stop being recorded (logged once to the Experts tab). - The tick-bar SMA is a plain, fully-recomputed average - not the built-in iMA() function, which only operates on the chart's own time-bar series. Using a hand-written helper for both is what keeps the two constructions genuinely comparable. - Because "one tick" in MetaTrader 4 means one price update on this feed, tick-bar timing is specific to this broker's quote stream - the same InpTicksPerBar value will form bars at a different real wall-clock rate on a different broker or symbol.

Expert advisor · MT5 · v1.0 · Free

About Bar Construction Comparison EA

Bar Construction Comparison EA is a script for MetaTrader 5 based on Moving Average. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Fast period, Slow period and Ticks per bar. MQL source code included.

Files in the download: BarConstructionComparison.ex5, BarConstructionComparison.mq5, BarConstructionComparison.txt.

Settings

SettingDefaultWhat it does
Fast period10Fast SMA period, in bars of EITHER construction
Slow period30Slow SMA period
Ticks per bar50Number of price ticks that close one synthetic tick bar
Report every n events20Write the CSV report after this many new samples (either series)
Report file nameBarConstructionComparison_report.csvReport file, written under MQL5\Files\

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Moving Average · Alerts · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria