EA-49615 · Utility

Get_Last_Nth_Close_Trade

This EA scans all closed trade deals in the account history, filters them by optional symbol and magic number, sorts them by close time, and displays the Nth most recent closed trade's details on the chart via Comment(). It is a read-only utility that does not open or manage any positions.

Open the interactive view (equity curve, symbol switch)

Key facts

CategoryUtility
RiskSafe
Rating★★☆☆☆
TypeUtility tool
TimeframesM1, M5, M15, H1, H4, D1
IndicatorsNone
Authorhttps://tradingbotmaker.com/

Backtest results (H1, about 1 year)

Not backtested yet — this EA could not be converted automatically.

Strategy analysis

This EA is not a trading strategy but a historical trade query utility. It iterates through MT5's HistoryDeals to retrieve closed trade information, filtering for exit deals using DEAL_ENTRY_OUT and matching corresponding entry prices and times using DEAL_ENTRY_IN. It supports optional filtering by symbol and magic number through two boolean switches: ENABLE_SYMBOL_FILTER and ENABLE_MAGIC_NUMBER. Sorting is done via bubble sort in descending order by close time, then the trade at the user-specified TRADE_INDEX is extracted and displayed. There is no position sizing or money management since the EA is purely an information display tool. The logic is clear but has performance concerns, such as scanning the entire deal history on every tick and using an O(n²) bubble sort algorithm.

Strengths

  • Supports flexible filtering by symbol and magic number, suitable for multi-strategy scenarios
  • Well-designed struct that comprehensively records key closed trade details including open price, close price, SL, TP, and profit
  • Reverse-matches entry deals via DEAL_ENTRY_IN to ensure complete open price and open time data

Weaknesses

  • Performs full history scan and sort on every tick, causing serious performance issues when trade history is large
  • Uses O(n²) bubble sort algorithm, extremely inefficient for large numbers of historical trades
  • The global struct orderHistoryDetails only stores a single record and cannot retain multiple query results, plus OnTick executes queries unconditionally without throttling
  • The second history loop matching entry information lacks a break optimization, continuing to iterate after finding a match

Possible improvements

  • Add new bar detection or a timer mechanism to avoid recalculating on every tick, significantly improving performance
  • Replace bubble sort with standard library sorting or leverage the inherent ordering of HistorySelect to avoid sorting altogether
  • Break out of the inner loop immediately after finding the matching entry deal for each position_ticket to reduce unnecessary iterations

Risk assessment

Overall risk: Safe

  • This EA is a read-only utility that executes no trades, posing no financial risk
  • Frequent history scanning on high-volume accounts may cause terminal lag or excessive CPU usage

Evaluation scores

Code quality2.0
Strategy logic1.0
Risk management5.0
Robustness2.0
Innovation1.0
Documentation2.0
Overall2.2

Parameters

ParameterDefaultDescription
ENABLE_MAGIC_NUMBERfalseWhether to enable magic number filter
ENABLE_SYMBOL_FILTERfalseWhether to enable symbol filter
MAGICNUMBER1234Magic number for filtering
TRADE_INDEX2Closed trade index to query (from latest)

Similar Utility EAs

Backtests are historical simulations and do not guarantee future results. Not financial advice.

Get the weekly Arena report

One email a week: ranking changes, new signals and new research. No spam; unsubscribe any time.