Angora Risk Guardian

Angora Risk Guardian · Technical Specification (v1.21)

Platform: MetaTrader 5 / MQL5. Type: Expert Advisor (utility). No external server; the only network traffic is optional Telegram notifications. Scope: account-wide (all symbols, all Magic Numbers). One instance runs per account.

1. Core definitions

Term Definition
Server time TimeTradeServer() . All day calculations use broker server time, not the local PC clock.
Trading day From Trading day start hour (input, default 00:00) in server time to the same hour on the next day. Example: if a prop firm uses CET midnight and the server is GMT+3, enter 1.
Day rollover The EA rolls the day over the first time its 500 ms timer sees the new day start. Daily breach/warning flags are reset, the previous day's P/L is written to the CSV, and the start-of-day values are saved.
Net equity ACCOUNT_EQUITY − ACCOUNT_CREDIT . Broker credit/bonus is excluded from risk calculations.
Capital flow DEAL_TYPE_BALANCE deals (deposits/withdrawals). Not counted as P/L. CREDIT and BONUS types are ignored.
Realized P/L Sum of profit + swap + commission + fee of all of today's trade deals (entry commissions included).
Floating P/L Sum of POSITION_PROFIT + POSITION_SWAP of open positions. Closing commission not yet charged is not included.

2. Daily loss

The start-of-day balance is always reconstructed exactly from history: StartOfDayBalance = CurrentBalance − TodayRealizedPL − TodayCapitalFlow . This keeps it correct even if the EA is started mid-day or the terminal is restarted.

Reference mode (input):

  • Start-of-day balance (default): the value above. Floating loss on a position held over midnight counts toward the new day's loss.
  • Start-of-day equity : net equity measured at the moment of day rollover. If the EA was not running at that moment it cannot be measured; the start-of-day balance is used instead, the panel shows "(estimated)" and REF_ESTIMATED is written to the CSV.
  • Higher of the two : the rule used by many prop firms.

Daily P/L = NetEquity − (Reference + TodayCapitalFlow) . Floating losses are included. Daily loss = max(0, −DailyPL) . Limit = min(Reference × Limit%, FixedAmountLimit) ; a limit set to zero is disabled.

A daily breach is latched until the end of the day: even if equity recovers, the day stays in breach.

3. Maximum drawdown

  • From peak balance (trailing) : the peak rises only with closed trades (balance); the rule of many 1-step challenges.
  • From peak equity (trailing) (default): Peak = highest net equity seen (floating included, persisted). DD = Peak − NetEquity , the limit is a percentage of the peak.
  • From initial balance (static) : DD = InitialBalance − NetEquity . The initial balance is an input; if 0, the balance at first run is stored.
  • Deposits/withdrawals (if seen while the EA is running) shift the peak and the initial balance by the same amount.
  • A DD breach is latched and never resets automatically; reset it by re-attaching with Reset DD breach and peak = true .

4. Exposure and risk tracking

  • Position risk (to SL) = FloatingPL − PL at SL (via OrderCalcProfit ; the terminal handles contract/tick value and account currency conversion). Risk is 0 for an SL locked in profit.
  • Pending order risk = loss from order price to SL (limit price for Stop Limit orders).
  • Positions/orders without SL are counted and their risk is flagged as "unlimited risk".
  • If all SLs are hit: the resulting net equity and its ratio to the daily limit are shown (pending orders are not included; shown separately).
  • Per Magic: open positions, lots, floating P/L, SL risk, pending orders; over the last N days (input, default 30): number of closing deals, win rate and net P/L. A closed trade's Magic is taken from its entry deal (so an EA position closed manually or by SL is still attributed to the EA). Magic 0 = "Manual". Win rate is counted per closing deal (partial closes count separately).

5. Alerts

  • One warning when the loss reaches Warning level percent of the limit (default 80%), and one breachnotification at 100%. Once per day (for DD, until the breach is reset).
  • Channels (each can be turned on/off): popup Alert window, sound file ( PlaySound ), MT5 mobile push ( SendNotification ), Telegram.
  • Panel colors: green normal, orange warning, red breach.
  • Connection loss, reconnection and Algo Trading being off are also notified.

6. Protection on limit breach

MQL5 cannot block a manual trade in advance and cannot switch off the Algo Trading button without a DLL. "Blocking" therefore means: every position opened after a breach is closed as soon as it opens, and new pending orders are deleted. The user chooses this knowingly; it costs spread/commission.

Modes (input):

  • Alerts only : no action is taken.
  • Block new trades (close immediately) (default): positions opened after the breach time are closed (including pending orders placed before the breach that trigger afterwards). Optionally all pending orders are deleted (on by default).
  • Close all + block : all positions are closed, all pending orders are deleted, and anything afterwards is blocked.

Enforcement has two layers: immediate via OnTradeTransaction , and a 500 ms timer as backup (failed closes are retried at 1 s intervals). On netting accounts, volume added to an existing position after a breach is reversed with an opposite order; if the position flips (INOUT) it is closed completely.

7. Disconnects and limitations (important)

Protection works only while the terminal is running, connected to the broker and Algo Trading is allowed. The following are not assumed:

  • Without a connection no close order can be sent. The panel shows a red "No broker connection: protection is not working" banner, DISCONNECT is written to the CSV, and protection retries automatically once the connection is back.
  • Nothing runs while the terminal is closed. Real protection requires a broker-side SL on every position, which is why the tool flags positions without SL separately.
  • Positions opened while the EA was not running are counted as opened before the breach in Block new trades mode and are not closed (only Close all mode catches them). On netting, volume added while the EA was not running is not caught.
  • Deposits/withdrawals made while the EA was not running are not reflected in the peak/initial balance (daily calculations are unaffected because they are read from history).
  • Peak equity is sampled every 500 ms; shorter spikes can be missed.
  • A VPS is recommended.

8. Persistent state

Terminal Global Variables with key prefix ARG_<account>_ : day start, start-of-day equity (and whether it was measured), daily breach/warning and their time, peak, static DD base, DD breach, panel position and pin state, day lock. A second chart instance on the same account is refused (temporary lock variable).

9. CSV report

MQL5/Files/AngoraRiskGuardian/ARG_<account>_<YYYY.MM>.csv , delimiter ; , decimal . . Columns: server_time; local_time; account; event; symbol; ticket; magic; volume; price; pl; balance; net_equity; daily_pl; daily_limit_used_%; dd; dd_limit_used_%; message. Events: START, STOP, DEAL, CAPITAL_FLOW, AUTO_SL, TILT_STREAK, TILT_BLOCK, TILT_WARN, LOT_LIMIT, NEWS (within TILT_BLOCK), TARGET, PROFIT_LOCK, PANEL_ORDER, PANEL_REFUSED, DAY_SUMMARY, DAY_ROLLOVER, REF_ESTIMATED, WARN_DAILY, BREACH_DAILY, WARN_DD, BREACH_DD, DD_RESET, ENFORCE_CLOSE, ENFORCE_REDUCE, ENFORCE_DELETE, ENFORCE_FAIL, TRADE_DISABLED, DISCONNECT, RECONNECT .

10. User interface

On-chart panel: dragged by its title bar, position locked with [pin] ; the position is persisted. The layout scales automatically with screen DPI (fonts grow with DPI while object coordinates do not); if needed, adjust it manually with the Panel scale input. Sections: status band, Account, Daily loss (fill bar), Maximum drawdown (bar), Open risk, System, Profit lock, News, Currency/asset exposure, New order, Discipline, Accounts, By Magic table (right-aligned columns). Content: status, server time/day start, connection, balance/equity/floating, reference, daily P/L and limit usage, DD, position/order counts, SL risks, no-SL warning, all-SLs-hit scenario, protection mode and the Magic table.

11. License and data

  • v1 is sold via the MQL5 Market with a one-time license; the Market applies its own licensing/activation protection, so the code has no separate license server.
  • If off-Market sales are needed (v1.x), a signed key bound to the account number and verified offline can be added.
  • No account data leaves the terminal, except Telegram messages the user explicitly enables. Outputs are the local CSV file and the local multi-account snapshot files.
  • Paid tier candidates (after demand is validated): server-based multi-account view across computers, per-Magic/per-symbol limits, weekly/monthly limits, HTML report summaries.

12. Test matrix

Area Scenarios
Account mode Hedging, Netting (adding, partial close, reversal)
Symbols Forex 5/3 digits, JPY, metals, index CFDs, crypto; account currency ≠ profit currency; lot step 0.01/0.1/1; min lot
Filling Brokers with FOK / IOC / Return policies
Time Server GMT+2/+3, DST change, Trading day start hour ≠ 0, weekend
Daily Mid-day start, terminal restart, position held over midnight (3 reference modes), intraday deposit/withdrawal
Breach Manual trade, other EA's trade, pending order placed before the breach triggering afterwards, close attempt while the market is closed (retry)
Connection Network drop/restore, breach occurring while disconnected, Algo Trading off
Multiple instances Attaching to a second chart on the same account (must be refused)
Strategy Tester Limit and close behavior in visual mode

13. v1.1 additions

Presets

If the Rule set input is anything other than Custom, the daily/max DD limits and reference modes come from the preset (money-based limits are turned off). The trading day start hour stays a user input because it depends on the server time zone. For static DD, Initial balance must be set to the account size.

Preset Daily Reference Max DD DD base
2-step challenge 5% higher of balance/equity 10% static initial balance
1-step challenge 4% start-of-day balance 6% peak balance (trailing)
Instant funding 3% higher of balance/equity 6% peak equity (trailing)
Strict personal 2% start-of-day balance 6% peak equity (trailing)

Firm-specific named presets will be added after each firm's current rules are verified.

Auto SL

A position without SL gets one after the Grace period (default 5 s, to let other EAs set their own SL). Distance: risk equal to a % of net equity (scaled from the loss of 100 points via OrderCalcProfit ) or a fixed number of points. If price has already passed the target SL, the nearest level the broker allows is used and noted in the CSV. An existing TP is kept. Not applied to pending orders (v1.1).

Discipline guard

Calculated from today's trade history and reset at day rollover. Trades sent by the tool itself (magic 20261010) are not counted.

  • Max trades per day: number of entry (IN/INOUT) deals in the day.
  • Losses in a row: streak of closing deals with net < 0; a profitable/breakeven close resets it. When the streak reaches the limit, no new trades for Cooldown minutes (0 = rest of day).
  • Pause after a loss (revenge protection): no new trades for N minutes after the last losing close.
  • Max lot per trade: excess volume is closed immediately (position reduced). If Reverse new trades that break a rule = false , only an alert is given. Discipline rules are enforced immediately via OnTradeTransaction ; the timer backup exists only for limit breaches.

14. v1.2 additions

News filter

MT5's built-in economic calendar ( CalendarValueHistory , server time) is read every 5 minutes for the next 48 hours. A new trade opened on an affected symbol within the before/after minute window of high-impact (optionally medium-impact) news is reversed. Affected symbol: if the currency list is empty, symbols whose base or profit currency matches the news currency; if the list is filled, news for the listed currencies covers all symbols. Disabled in the Strategy Tester because the calendar is not available there. If the calendar cannot be loaded, the panel warns and retries every minute.

Profit lock

  • Daily target (% of reference or amount): when reached, either close all + lock the day or alert only.
  • Profit protection (trailing): after daily profit passes the starts at % level, the day is locked if max giveback % of the intraday peak profit is lost.
  • On a locked day all positions are closed, pending orders are deleted and any later new trades are reversed. The lock is lifted at day rollover and survives terminal restarts.

Risk calculator and one-click orders

Risk (%) and SL (points) fields in the panel for the chart symbol. Lot = (net equity × risk %) ÷ (loss of 1 lot at SL, OrderCalcProfit ), rounded down to the lot step; max lot and the per-trade lot limit are applied. If even the min lot exceeds the risk, no order is sent. TP = SL × ratio. A pre-check runs before the order: if a limit breach, locked day, discipline or news rule applies, the order is never sent (true prevention for panel orders). Optional confirmation dialog. Panel orders use a configurable magic number and count toward discipline limits.

Currency / asset exposure

Each position's notional value in account currency ( volume × price × tick value ÷ tick size ) is added to its base currency (+) and its profit currency (−); symbols with the same base and profit currency (indices etc.) are shown by symbol name. The top 5 exposures are shown as a multiple of net equity (5x orange, 10x red).

Telegram and end-of-day summary

If a bot token and chat ID are entered, all alerts are also sent to Telegram. WebRequest is used; the user must allow https://api.telegram.org under Tools > Options > Expert Advisors (must be stated in the Market description). Messages are queued and at most one is sent per cycle (3 s timeout), so network slowness never holds up protection for long. At day rollover a summary (P/L, trade count, winning/losing closes, highest limit usage, breach/lock) is sent to Telegram and written to the CSV ( DAY_SUMMARY ). The token is stored only in the terminal inputs.

Multi-account panel

Every instance with the option on writes a small snapshot to the terminals' common folder ( Common/Files/AngoraRiskGuardian/accounts/<account>.txt ) every 5 seconds and reads the others: account, broker, equity, daily P/L, daily limit and DD usage, status. An account not updated for 60 s shows as "offline". Data never leaves the computer. It covers all MT5 installations on the same computer; other computers/VPSs are out of scope (a server-based version should be evaluated separately for the paid tier).


Yazarın diğer ürünleri
Angora Patterns finds, draws and tracks chart patterns for you. It recognises 23 classic chart patterns, 8 harmonic patterns and 13 candlestick patterns, and gives every pattern a breakout level, a target, an invalidation level, a state and a quality score. Chart patterns: Double Top and Bottom, Triple Top and Bottom, Head and Shoulders, Inverse Head and Shoulders, Rounding Top and Bottom, Ascending, Descending and Symmetrical Triangle, Rising and Falling Wedge, Rectangle, Ascending and Descend
Angora Patterns finds, draws and tracks chart patterns for you. It recognises 23 classic chart patterns, 8 harmonic patterns and 13 candlestick patterns, and gives every pattern a breakout level, a target, an invalidation level, a state and a quality score. Chart patterns: Double Top and Bottom, Triple Top and Bottom, Head and Shoulders, Inverse Head and Shoulders, Rounding Top and Bottom, Ascending, Descending and Symmetrical Triangle, Rising and Falling Wedge, Rectangle, Ascending and Descend
Angora Trading System is a mean-reversion Expert Advisor. It waits for price to stretch to the edge of the Bollinger Bands while RSI confirms an overbought or oversold condition, and it trades the move back toward the middle band. An ADX regime filter keeps it out of conditions that do not suit this approach. An optional ATR-based grid adds positions when price moves against the first entry. All legs share one basket stop loss, which is sent with every order. Available for MetaTrader 4 and Met
Filtrele:
Değerlendirme yok
Değerlendirmeye yanıt