Loading…

Feature Vector Streamer

Anyone running a model outside the terminal - Python, R, a separate service - needs a reliable way to get live market features out of MetaTrader 4 without polling the terminal directly. MQL4 cannot open a socket to an arbitrary local process by itself, but it can write files, and a file an external process can read on its own schedule is a workable, dependency-free bridge. This EA computes one feature vector per closed bar: OHLC, tick volume, a 1-bar return, an N-bar-lagged return and momentum, a fast/slow SMA pair plus the distance of price from the slow SMA, RSI, ATR, and a rolling standard deviation of recent 1-bar returns as a volatility measure. Every field is computed from the most recently CLOSED bar (shift 1), never the bar still forming, so a partially-formed bar's incomplete OHLC never contaminates the feature vector - a naive shift-0 implementation would leak an unfinished bar's high/low into every row until that bar closes. Two files are written every bar: an append-only log building a full historical dataset for training, and a "latest" snapshot that is fully overwritten each time so a live-inference consumer only ever needs to read one small, current row rather than tailing a growing file. Notes and limitations Files are plain overwrite/append operations, not atomic - an external process reading the latest-snapshot file at the exact instant it is being rewritten could see a partial row on a very unlucky timing coincidence. In practice the write is fast enough that this is rare, but a consumer doing high-frequency polling should tolerate an occasional malformed row (e.g. a column-count check) rather than assume every read is guaranteed clean. The log file grows without bound - nothing in this EA prunes or rotates it. Archive or trim it periodically for a long-running instance. Feature values are computed from this chart's symbol and timeframe only; running a second instance on a different chart with a different InpFilePrefix streams a second, independent pair of files. This EA never trades - it only reads price/indicator data and writes files.

Expert advisor · MT4 · v1.0 · Free

About Feature Vector Streamer

Feature Vector Streamer is a script for MetaTrader 4 based on RSI, Moving Average and ATR. It has 8 settings, such as Fast ma period, Slow ma period and Rsi period. MQL source code included.

Files in the download: FeatureVectorStreamer.ex4, FeatureVectorStreamer.mq4, FeatureVectorStreamer.txt.

Settings

SettingDefaultWhat it does
Fast ma period10Fast SMA period
Slow ma period50Slow SMA period
Rsi period14RSI period
Atr period14ATR period
Return lag bars5Bars back for the multi-bar return and momentum features
Std dev sample20Bars of 1-bar returns used to compute the volatility feature
Stream every tickfalsefalse = only on a new bar close, true = every tick (heavier)
File prefixFeatureVectorStreamerFilename prefix under MQL4\Files

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: RSI · Moving Average · ATR · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria