Loading…

Declarative Rule Runner

Every parameter a strategy exposes as an input still leaves its actual decision logic locked inside compiled code. This EA moves the decision logic itself into a text file, read and parsed fresh on every new bar, so a trader can change what triggers a trade by editing a line of text rather than opening MetaEditor. The rule language is deliberately small: each line is one rule, of the form ACTION IF term (AND term)*, where ACTION is BUY, SELL or CLOSE, and each term compares an indicator token (CLOSE, OPEN, HIGH, LOW, BID, ASK, or MA/RSI/ATR with a glued-on period like MA20 or RSI14) against either a literal number or another indicator token, using >, <, >=, <= or ==. Rules are evaluated top to bottom on each new bar and the first one that matches fires - later rules are not evaluated that bar. This "first match wins" order is a deliberate, documented semantic, not an oversight, and lets a rule file express priority (e.g. an exit rule placed above the entry rules) without a separate priority field. Important note on the grammar: this catalogue's Libraries\TradingRuleDsl\ folder was checked for an existing shared rule grammar to reuse, since a second, incompatible grammar in the same catalogue would be confusing. At the time this project was written that folder existed but contained no header file yet, so this EA implements its own small grammar rather than depending on something that did not exist. If a TradingRuleDsl.mqh is published later, its syntax will not necessarily match this EA's - check both before assuming interchangeability. Notes and limitations - The grammar has no OR, no parentheses, and no nested logic - only a flat AND-joined list of comparisons per rule. Anything more expressive needs several BUY/SELL rules stacked with "first match wins" ordering instead of one complex rule. - A malformed line is skipped and logged, not treated as a fatal error - the rest of the file still loads and runs. - Indicator tokens always resolve on the attached chart's own symbol and timeframe; the grammar has no cross-symbol or cross-timeframe syntax. - If the rule file cannot be read or contains zero valid rules, the EA stays attached and idle (no trades) rather than failing to load.

Expert advisor · MT4 · v1.0 · Free

About Declarative Rule Runner

Declarative Rule Runner is an expert advisor (trading robot) for MetaTrader 4 based on RSI, Moving Average and ATR. It has 7 settings, such as Rule file name, Lots and Magic number. MQL source code included.

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

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

Settings

SettingDefaultWhat it does
Rule file namedeclarative_rules.txtRule file in MQL4\Files\; see .txt for grammar
Lots0.10Fixed lot size for orders this EA opens
Magic number48300Magic number stamped on orders this EA opens
Slippage points30Maximum acceptable slippage, in points
Stop loss pips30Stop loss distance in pips, applied to every new order; 0 = none
Take profit pips60Take profit distance in pips, applied to every new order; 0 = none
Reload each bartrueRe-read and re-parse the rule file on every new bar (lets edits take effect live)

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 → Experts.
  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 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: RSI · Moving Average · ATR · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria