Loading…

Cross Strategy Signal Netter

Running several strategies on one terminal without a netting layer usually means each one calls OrderSend independently, and the terminal ends up holding both a long and a short position on the same symbol that only differ by magic number - paying spread and swap twice for exposure that nets to something much smaller, or fighting itself every time one strategy opens what another is about to close. This library is a decision layer, not an execution layer. Each strategy reports its own desired signed position on a symbol - positive lots for long, negative for short, zero for flat - by calling SubmitSignal with its own name. The library sums every strategy's opinion on a symbol into one net desired position, reads the terminal's actual current net position by walking the live order pool, and reports the delta: how many lots to buy or sell to bring the real position in line with the combined intent. What the caller does with that delta - send one order, refuse if it is below a minimum size, log it for a human to approve - is deliberately left outside this header, because a bug in a decision layer can compute a wrong number, but it can never place a wrong order if it never calls OrderSend at all. Reading the current position uses the same forward OrdersTotal()/ OrderSelect(SELECT_BY_POS) walk this catalogue's read-only patterns always use, filtered by symbol and, optionally, by magic number. This matters specifically because MQL4 always allows more than one order per symbol (hedging is the only model MQL4 has) - there is no single "the order" on a symbol to read with a shortcut, so every matching ticket has to be inspected and summed explicitly rather than assumed. Notes and limitations - This library never sends, closes or modifies an order. It computes a number; acting on it, including any lot-step/min-lot/max-lot rounding via MODE_LOTSTEP etc., is entirely the caller's responsibility. - SubmitSignal replaces a strategy's previous value for that symbol - it is a "current desired state" table, not an append-only signal log. A strategy that wants to stop contributing must call SubmitSignal with 0.0 (explicitly flat) or RemoveSignal/RemoveStrategy (no opinion at all) - these are different things and the library does not guess which one you meant. - CurrentNetLots() only counts market orders (OP_BUY/OP_SELL). Pending orders are excluded on purpose - they carry no position until filled, so including them would net against exposure that does not exist yet. - There is no persistence. Signals live in memory for the object's lifetime; a terminal restart clears every strategy's submitted signal and the netter starts from an empty table again. - Netting several strategies down to one net order changes each strategy's own attribution - a partial fill of the combined delta cannot be split back into "this much was TrendFollower's, this much was MeanReversion's" without separate bookkeeping outside this header.

Script · MT4 · v1.0 · Free

About Cross Strategy Signal Netter

Cross Strategy Signal Netter is a script for MetaTrader 4. It has 1 setting, such as Magic filter. MQL source code included.

Files in the download: CrossStrategySignalNetter.mqh, CrossStrategySignalNetter.txt, CrossStrategySignalNetterDemo.mq4.

Settings

SettingDefaultWhat it does
Magic filter-1Magic filter for reading the current position, -1 = any

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: Buy/Sell Arrows · Trend · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria