Loading…

Equity Curve Trading Filter

A strategy with a genuine long-run edge still comes in streaks. Trading the equity curve is the practice of watching the strategy's OWN running equity rather than the market, and standing aside when the current streak looks like the bad kind - because a backtest's long-run average return says nothing about whether the last several trades were part of it. This library compares the latest equity sample to a simple moving average of its own recent history, and separately tracks drawdown from the running peak. Both conditions have to hold for EcfAllowTrading to say yes: equity at or above its own average, AND drawdown from peak under a chosen limit. Either one alone can look acceptable while the other quietly says the strategy is not currently working - equity can sit above a slow-moving average while still deep in a drawdown from an earlier peak, for instance, so both checks are required rather than either being treated as sufficient on its own. The moving average window is a plain ring buffer array that the CALLER declares and owns, sized once with ArrayResize at startup, rather than living inside the state struct. This was originally an MQL4 workaround (older compiler builds do not support a clean, portable dynamically-sized array as a struct member), but the external-buffer shape is kept identical on the MQL5 side too, deliberately - MQL5 structs can hold a dynamic array member cleanly, yet keeping the buffer external still means one EA can run several independent filters, one per strategy variant, over differently sized windows without any of them sharing state, which is worth keeping on either platform. The header is self-contained. No dependencies, no DLLs, and no trade, position or account calls at all - one small struct and plain functions that operate on it and a caller-supplied array. Notes and limitations - This filters SIGNALS, not open positions - EcfAllowTrading answers "should a new trade be taken right now", it does not close anything that is already open. Wire the false case to skip new entries, not to flatten the book. - The window is a simple moving average of raw equity, not returns or a smoothed indicator. It reacts one full window's worth of samples behind a turn - a smaller window reacts faster and whipsaws more, a larger window reacts slower and misses more of a recovery before re-enabling. - What counts as one "sample" is entirely up to the caller. Feeding it every tick turns this into an intraday equity filter; feeding it once per closed trade (the usual choice, and what the demo does) turns it into a streak filter. Pick one and be consistent - mixing sample cadences inside the same window makes the average meaningless. - No money is at risk in the demo. It replays a fixed synthetic equity path and never calls OrderSend or its MQL5 equivalent. - No thread concerns: state is a plain struct plus a caller-owned array, with no internal statics.

Script · MT4 · v1.0 · Free

About Equity Curve Trading Filter

Equity Curve Trading Filter is a script for MetaTrader 4. It has 2 settings, such as Window size and Max drawdown percent. MQL source code included.

Files in the download: EquityCurveFilter.mqh, EquityCurveFilter.txt, EquityCurveFilterDemo.mq4.

Settings

SettingDefaultWhat it does
Window size5Moving average window, in trades
Max drawdown percent8.0Drawdown limit from equity peak, percent

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

MQL4 & MQL5 scripts · PolyMaria