Loading…

Trade Frequency Limiter

Overtrading rarely announces itself - it looks like conviction in the moment and only shows up as a pattern in hindsight. This EA counts every matching order (open positions plus closed history, by OrderOpenTime()) that falls inside the trailing hour and the trailing 24 hours, both per symbol and across the whole scope, and compares each count against its own configurable cap. Older orders have already "used" their slot in the window and are left alone; enforcement only ever touches currently open positions, and when a cap is breached it closes the NEWEST offender first and rechecks, so a sudden burst of entries is trimmed back down to the limit rather than closing an arbitrary position chosen without regard for order. As with every guard in this catalogue, it cannot reach into another program's OrderSend call and refuse the order before it exists - nothing running alongside another EA in the same terminal can - so it always acts after the fact, on the ticket that already appeared. On every recalculation pass the EA also rewrites a CSV snapshot of the current per-symbol and total counts to the sandbox, turning "did I overtrade this week" from a question that requires digging through history into a report you can open in a spreadsheet. Notes and limitations Counts are windowed from the current time backward, not from each order's own open time, so the reading can shift slightly as time passes between recalculations rather than updating continuously tick by tick - acceptable for a frequency guard, not appropriate for anything requiring exact real-time precision. History is walked in full on each recalculation; on accounts with very large trade history this could add a small, bounded cost at the configured recalculation cadence. It only sees orders visible in this terminal's account.

Expert advisor · MT4 · v1.0 · Free

About Trade Frequency Limiter

Trade Frequency Limiter is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 11 settings, such as Max per symbol per hour, Max per symbol per day and Max total per hour. MQL source code included.

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

Settings

SettingDefaultWhat it does
Max per symbol per hour5Cap on orders opened, this symbol, in the trailing hour
Max per symbol per day15Cap on orders opened, this symbol, in the trailing 24 hours
Max total per hour15Cap on orders opened, all matching symbols, in the trailing hour
Max total per day40Cap on orders opened, all matching symbols, in the trailing 24 hours
Magic filter-1Magic number filter, -1 = every magic number
Recalc seconds15Minimum seconds between recalculation passes
Write reporttrueWrite a CSV snapshot of current counts to the sandbox each recalculation
Report filenameTradeFrequencyLimiter_Report.csvSandbox filename for the CSV snapshot
Dry runfalsetrue = alert only, never closes - use to observe before enforcing
Max retries5Attempts per close before giving up
Retry wait ms500Pause between attempts, milliseconds

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: Trailing Stop & Break-even · Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria