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 · MT5 · v1.0 · Free

About Trade Frequency Limiter

Trade Frequency Limiter is an expert advisor (trading robot) for MetaTrader 5. 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.ex5, TradeFrequencyLimiter.mq5, TradeFrequencyLimiter.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Max per symbol per hour5Cap on trades opened, this symbol, in the trailing hour
Max per symbol per day15Cap on trades opened, this symbol, in the trailing 24 hours
Max total per hour15Cap on trades opened, all matching symbols, in the trailing hour
Max total per day40Cap on trades 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 5 open File → Open Data Folder, then go to MQL5 → Experts.
  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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Trailing Stop & Break-even · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria