Files
EA_with_Python/docs/MyProject/HITPositionManagerEA_spec_en.md
T
2026-06-14 22:02:17 +09:00

4.8 KiB

HITPositionManagerEA Specification

1. Overview

HITPositionManagerEA.mq5 is the filled-position manager for positions created by HITEntryEA.mq5. It never creates new orders or pending orders. It is a retail hedging account EA and fails initialization on non-hedging accounts.

The managed set is limited to positions whose POSITION_SYMBOL equals _Symbol and whose POSITION_MAGIC equals input_managed_magic_number. Multiple tickets, split entries, and simultaneous buy/sell positions are managed independently.

2. Indicators

  • No standard or custom indicators are used.
  • SLTP management uses the current tick, each position's open price, SL, TP, open time, and symbol stop/freeze levels.
  • High-volatility stop tightening uses M1/M3/M5/M10/M15 open prices and the current market price.

3. Parameters

  • input_managed_magic_number = 10001: Magic number of positions to manage. It should match the entry EA's input_entry_magic_number.
  • input_slippage_points = 10: Allowed deviation for closes and SL modifications.
  • input_position_close_after_h1_bars = 12: Time-based close threshold in H1 bars. 0 disables it.
  • input_sltp_manager_enabled = false: Master switch for SLTP management.
  • input_sltp_show_panel = true: Shows the SLTP control panel.
  • input_sltp_use_breakeven = false: Standard breakeven.
  • input_sltp_breakeven_trigger_pips = 30.0: Profit threshold for standard breakeven.
  • input_sltp_breakeven_buffer_pips = 3.0: Profit-side entry buffer used by standard breakeven.
  • input_sltp_use_elapsed_breakeven = false: Elapsed-time breakeven.
  • input_sltp_elapsed_breakeven_hours = 4.0: Holding time required before elapsed-time breakeven is allowed.
  • input_sltp_elapsed_breakeven_buffer_pips = 3.0: Profit-side entry buffer used by elapsed-time breakeven.
  • input_sltp_use_active_trailing = false: Active trailing.
  • input_sltp_active_breakeven_pips = 30.0: Profit threshold that starts active trailing.
  • input_sltp_active_stop_loss_offset_pips = 5.0: Initial locked profit offset from entry.
  • input_sltp_active_step_trigger_pips = 10.0: Additional profit interval required for each SL step.
  • input_sltp_active_step_move_pips = 5.0: SL movement added per completed step.
  • input_sltp_use_tp_progress_stop = false: TP-progress stop.
  • input_sltp_tp_progress_trigger_percent = 70.0: TP progress required before the SL lock is applied.
  • input_sltp_tp_progress_sl_lock_percent = 30.0: Entry-to-TP distance percentage locked by SL.
  • input_sltp_use_high_volatility_limit = false: High-volatility stop tightening.

4. Entry And Exit Conditions

  • There are no entry conditions because this EA does not create orders.
  • On every tick, the EA first evaluates ticket-based time exits and then applies SLTP management.
  • Time exits close target tickets when POSITION_TIME is older than input_position_close_after_h1_bars * PeriodSeconds(PERIOD_H1) by using CTrade::PositionClose(ticket).
  • SLTP management applies only candidates that improve the current SL in the profit-protection direction, preserving the current TP with CTrade::PositionModify(ticket, new_sl, current_tp).
  • High-volatility stop tightening only accepts candidates that are at or beyond breakeven: at or above entry for BUY positions and at or below entry for SELL positions.

5. Risk Management

  • All position processing uses PositionGetTicket(i) followed by PositionSelectByTicket(ticket).
  • Only positions matching _Symbol and input_managed_magic_number are touched.
  • Different magic numbers, different symbols, and manual-position equivalents are ignored.
  • Logs include ticket, symbol, magic, position type, trade retcode, and GetLastError().
  • Standard breakeven and active trailing cannot be enabled together; settings validation rejects that conflict.
  • When input_sltp_manager_enabled=false, contradictory detailed SLTP settings do not stop the EA; time exits continue to run. Detailed settings are validated when SLTP management is enabled.

6. Unit Test Scope

  • The production manager EA contains no test-only order creation.
  • In the Strategy Tester, HITPositionManagerTestHarness.mq5 seeds test BUY/SELL positions and a different-magic control position, then calls the same production manager classes.
  • Test coverage targets same-symbol/same-magic multi-ticket handling, simultaneous buy/sell positions, magic mismatch exclusion, time exits, and SL updates.

7. Changelog

  • 2026-06-14: Allowed the EA to continue time-exit management when SLTP master is off even if detailed SLTP settings conflict. Added breakeven protection to high-volatility stop tightening so loss-side SL candidates are discarded.
  • 2026-06-13: Synchronized SLTP input defaults with HIT-EA_refactor_ver6.mq5 and documented each default value.
  • 2026-06-07: Split position-management responsibilities from HIT-EA_refactor_ver6.mq5 and defined a hedging-account, ticket-based manager EA.