거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Telegram에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
스크립트

Risk Drift Audit: the Real Risk of Every Past Trade - MetaTrader 5용 스크립트

조회수:
105
평가:
(1)
게시됨:
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

A strategy is tested at a risk, say 1% per trade, and then run with a fixed lot. From that moment the risk is no longer 1%. The loss at the stop loss is lot × stop distance, and the balance it is measured against changes after every trade. With an ATR stop, the stop distance also follows the market's volatility. The terminal shows lots, not risk, so the drift goes unnoticed until one loss is much bigger than expected.

Risk of each of 1,044 trades of a fixed 0.02-lot gold EA, 2023 to 2026

This script rebuilds, from the account's deal history, the risk of every trade:

  • the balance just before the entry, replayed from all deals (deposits, profits, swaps, commissions, fees) and checked against the account balance at the end;
  • the stop loss at entry: from the entry deal, else from the order that opened the trade. If the trade had no stop at entry, the stop loss at the close is used and the trade is marked "close", because that stop may have been added or moved later;
  • the loss at that stop in the account currency (OrderCalcProfit), and its percentage of the balance.

It then compares each Expert Advisor (magic number and symbol) with itself: the median risk of its first trades (the tested risk, unless you enter it) against its last trades, the largest risk, how many trades were above a multiple of the tested risk, trades without a stop loss, and the lot that would carry the tested risk at today's balance with the last trade's stop distance.

Example: what a fixed lot did on gold. A fixed 0.02-lot breakout EA with a 2 × ATR stop, XAUUSD H1, 2023 to October 2026, $10,000 (Strategy Tester):

Year Median risk per trade Median stop distance Median balance
2023 0.18% $8.7 $9,645
2024 0.24% $11.4 $9,516
2025 0.45% $20.3 $9,066
2026 0.88% $38.6 $8,827

The lot never changed and the balance hardly moved, yet the risk per trade grew five times, because the stop distance grew with gold's price and volatility. The largest single risk was 5.77% of the balance (31 times the starting risk), in the volatile days of early February 2026. 453 of the 1,044 trades were above twice the starting risk.

How it was checked. A test EA recorded, at every entry, its balance and lots × contract size × stop distance. The script's numbers matched all 1,044 trades: balance before entry exact, risk within one cent (OrderCalcProfit rounds to cents), and the stop-loss source right for every trade, including 104 trades that opened without a stop and set it on the next tick.

Output

  • Journal: one line per magic number and symbol, then the five largest risks.
  • Common\Files\RiskDrift.csv: one line per trade (balance before, stop, risk in money and %, multiple of the tested risk, result, R multiple).
  • Chart: the risk of the last trades as bars, green up to 1.25 × the tested risk, orange up to the warning multiple, red above it, grey without a stop loss. Run the script again with "Draw" off to remove the drawing.

Inputs

  • Symbol: empty = all symbols.
  • Magic number: -1 = all, 0 = manual trades.
  • Trades opened from / until.
  • Tested risk per trade, %: 0 = the median of each EA's first trades.
  • Number of first / last trades for the medians: default 20.
  • Warning multiple: default 2.
  • Write the CSV, draw on the chart, number of trades drawn.

In the Strategy Tester. RiskDrift.mqh also works inside an Expert Advisor, so a backtest can report how its own risk drifted:

#include "RiskDrift.mqh"
double OnTester()
  {
   CRiskDrift rd;
   if(rd.Load(_Symbol, -1, 0, D'2100.01.01'))
     {
      rd.SetTested(0.0, 20);
      rd.Report(2.0);
     }
   return 0.0;
  }

Limits

  • Risk is measured at the stop loss of the entry. Commission is not included.
  • For symbols whose profit currency is not the account currency, the conversion uses current rates.
  • Netting accounts: volume added to an open position and reversal deals are not measured (the journal counts them).
  • Balance, not equity: floating profit or loss of other open positions is not included.

The script only reads the history. It never places, modifies or closes an order.

Previous Day High, Low and Close Levels Previous Day High, Low and Close Levels

Draws the previous day High, Low and Close as horizontal levels on the chart, with optional history for several past days, extension of today's levels to the right and price labels.

Position Tool - TradingView-style Long/Short position calculator Position Tool - TradingView-style Long/Short position calculator

TradingView-style Long/Short position tool for MT5: drag the Entry, Stop and Target lines and get lot size, risk, reward, R:R and margin instantly.

Spread and Daily ATR Risk Meter HUD Spread and Daily ATR Risk Meter HUD

Compact zero-buffer MetaTrader 5 on-chart HUD displaying live Spread in points and pips, Daily ATR(14) range consumption percentage, broker Stops/Freeze levels, and 1R lot size.

Round-Number / Psychological Level Magnet Round-Number / Psychological Level Magnet

Auto-scaled round-number grid for any symbol — big figures and half levels drawn to the right spacing whether you're on EURUSD, USDJPY, XAUUSD or an index, plus a live "distance to nearest magnet" readout.