Loading…

EA To Indicator Series Bridge

An EA can compute something worth drawing - an internal state value, a synthetic level, a running signal score - that has no chart representation of its own, because only an indicator can plot a buffer. There is no MQL4 API for one running program to hand a value directly to another; an EA and an indicator are two separate programs even when attached to the same chart. The two mechanisms that DO cross that boundary are a single scalar GlobalVariable and a shared file in the MQL4\Files sandbox - neither one is a series by itself. This header combines them into one protocol. CEaSeriesPublisher (used by the EA) appends {time,value} points into a small fixed-capacity ring buffer file with an explicit binary layout (magic, capacity, write cursor, point count, then the point slots), overwriting the oldest point once the ring is full rather than growing forever - this is a live bridge, not a permanent log. After every successful write it bumps ONE GlobalVariable holding a sequence counter, and only after the file write has actually completed, so a subscriber that trusts the counter never sees a sequence number promising data that is not on disk yet. CEaSeriesSubscriber (used by the indicator) polls that GlobalVariable each OnCalculate - a single cheap read, no file I/O - and only re-opens the ring buffer file when the sequence number has actually moved since the last poll. This is a POLLING bridge, not a push notification: the indicator only ever sees data as fresh as its last poll interval. A write landing mid-read is handled, not prevented - ReadLatest() re- checks the sequence number after finishing a read and retries once if it moved again during the read, rather than any real file lock, which MQL4 has no primitive for at all. This is sufficient for a value republished every tick, where a rare torn read simply gets superseded next poll; it is not a guarantee suitable for a one-shot value that is never republished. Notes and limitations - This is polling, not push. An indicator only sees new data on its next OnCalculate after the EA published it - there is no way for the EA to wake the indicator up immediately, since MQL4 gives independent programs no signalling mechanism beyond the GlobalVariable/file pair this header already uses. - The ring buffer has a fixed capacity chosen at Init() time. Publishing faster than the subscriber polls loses only the oldest unread points, never crashes or corrupts the file. - Concurrent access is handled by detect-and-retry, not a real lock - MQL4 has no cross-program file locking primitive. A read that races a write retries once; a second race in a row is treated as "good enough, move on" rather than retried indefinitely, since the value gets republished again on the next tick regardless. - Both sides must agree on the exact series name string - there is no discovery mechanism, and a subscriber pointed at a name no publisher has ever Init()'d simply gets -1 from ReadLatest() forever. - useCommon (FILE_COMMON) is only useful when the EA and the indicator run on different terminal instances sharing the same broker's common data folder - leave it false for the normal case of both programs running in the same terminal.

Script · MT5 · v1.0 · Free

About EA To Indicator Series Bridge

EA To Indicator Series Bridge is a script for MetaTrader 5. It has 3 settings, such as Series name, Capacity and Points to write. MQL source code included.

Files in the download: EaIndicatorSeriesBridge.mq5.mqh, EaIndicatorSeriesBridge.txt, EaIndicatorSeriesBridgeDemo.ex5, EaIndicatorSeriesBridgeDemo.mq5.

Settings

SettingDefaultWhat it does
Series nameDemoSignalSeries name shared between publisher and subscriber
Capacity8Ring buffer capacity (small on purpose, to show wraparound)
Points to write12Points published - deliberately more than capacity

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: Buy/Sell Arrows · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria