Get_Last_Nth_Open_Trade
This EA scans all open positions and displays the details of the Nth trade from the sorted list on the chart. It supports optional filtering by magic number and symbol, sorts positions by ticket number in descending order, and prints trade information via the Comment() function.
Open the interactive view (equity curve, symbol switch)Key facts
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 position inquiry utility. Its core functionality iterates through all current open positions, filtering them based on user-configured magic number and symbol filters, and stores matching positions into a struct array. It then sorts all positions by ticket number in descending order using a bubble sort algorithm, and finally extracts the trade at the user-specified index (TRADE_INDEX) from the sorted array to display its details on the chart. The tool does not execute any opening, closing, or modification operations — it is purely for monitoring and displaying position status. The sorting algorithm uses a simple bubble sort which is inefficient but does not affect functional correctness. There is no entry or exit logic since no trades are placed.
Strengths
- Supports flexible filtering by magic number and trading symbol
- Uses structured storage for trade details, easy to extend and integrate
- Displays position information intuitively on chart via Comment()
Weaknesses
- Bubble sort is inefficient and performs poorly with many positions
- Missing boundary checks — TRADE_INDEX out of range causes array out-of-bounds errors
- Performs full scan and sort on every tick with no throttling, causing unnecessary resource consumption
- MAGICNUMBER is not declared as an input variable, making it unmodifiable from the parameter panel
Possible improvements
- Change MAGICNUMBER to an input variable so it can be configured from the parameter panel
- Add boundary checks to prevent array out-of-bounds errors, and implement a timer or new bar check to reduce execution frequency
Risk assessment
Overall risk: Safe
- Array out-of-bounds risk: TRADE_INDEX exceeding the filtered position count causes array access violation
- Full scan on every tick may waste CPU resources under high-frequency market conditions
Evaluation scores
Parameters
| Parameter | Default | Description |
|---|---|---|
ENABLE_MAGIC_NUMBER | false | Whether to enable magic number filter |
ENABLE_SYMBOL_FILTER | false | Whether to enable symbol filter |
MAGICNUMBER | 1234 | Magic number for filtering |
TRADE_INDEX | 2 | Closed trade index to query (from latest) |
Similar Utility EAs
Backtests are historical simulations and do not guarantee future results. Not financial advice.