Loading…

Graceful Degradation Framework

A typical EA calls Alert() and return()s the moment something unexpected happens: not enough bar history yet, a file that will not open, a chart object limit hit. That is often the wrong response - none of those things actually prevent the EA from trading, they only prevent one feature built on top of trading from working perfectly. This template tracks four features independently, each with its own FEATURE_HEALTH state (HEALTH_OK / HEALTH_DEGRADED / HEALTH_DISABLED), and downgrades only the feature that actually failed. History-based volatility sizing (ATR-scaled stops) falls back to a fixed conservative stop distance in points when fewer than InpMinBarsForAtr bars are available - correct behaviour on a freshly-attached chart or an illiquid symbol still syncing history, rather than reading a meaningless ATR off a three-bar window. File-based trade logging disables itself after a run of consecutive write failures rather than retrying forever and spamming the log with the same disk/permissions error every tick; trading keeps going without a paper trail. The chart-object status panel is purely cosmetic and is shed on the first ObjectCreate/ObjectSetString failure, never allowed to interfere with anything that touches money. Only after repeated consecutive OrderSend failures does the framework disable NEW entries - and even then it keeps managing whatever is already open, since an EA that stops watching its own live positions the moment it hits trouble is worse than one that stops opening new ones. Every feature also recovers back to HEALTH_OK automatically once its condition clears (history catches up, the file becomes writable again), so a transient outage does not permanently disable something that would work again on the very next check. Notes and limitations The moving-average signal is a minimal vehicle for the degradation wiring, not a tuned strategy. Degradation state lives in memory only and resets to HEALTH_OK on every restart - a template demonstrating warm-restart continuity of this kind of state is a separate, complementary submission (Warm Restart Continuity Framework); combining the two patterns is a natural next step for a production EA. The status panel intentionally has no theme/colour options - keep it minimal, since its entire job here is to show health state, not to look polished.

Expert advisor · MT4 · v1.0 · Free

About Graceful Degradation Framework

Graceful Degradation Framework is an expert advisor (trading robot) for MetaTrader 4 based on Moving Average and ATR. It has 8 settings, such as Trade symbol, Lots and Magic. MQL source code included.

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

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

Settings

SettingDefaultWhat it does
Trade symbolSymbol to trade, blank = current chart symbol
Lots0.01Lot size for the demo entries
Magic48601Magic number for this EA's own orders
Atr period14ATR period used for volatility-scaled stops (needs history)
Min bars for atr60Minimum bars required before ATR-based sizing is trusted
Log file nameGracefulDegradationFramework.csvFile under MQL4\Files\
File retry failures3Consecutive file-write failures before logging is disabled
Consecutive order fails5Consecutive failed OrderSend calls before new entries are disabled

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: Alerts · Moving Average · ATR · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria