Trailing Stop

This EA can be used alongside other EAs to manage order closures, with specific functions detailed in the "Terminology" section below. For example, in MT4, open two EURUSD charts: load an EA for placing orders on one chart and this EA on the other. When the order-placing EA generates a profitable order, this EA manages the trailing stop to lock in profits.

The "Order Magic Number" parameter of this EA defaults to 0, meaning it operates on all orders for the symbol. If a number greater than 0 is entered, the EA will only manage orders placed by an EA with the same "Order Magic Number."

Terminology

Order Magic Number: When multiple order-placing EAs are loaded for the same symbol, each EA must have a unique number in its "Order Magic Number" parameter to distinguish its orders. This prevents logical errors by allowing EAs to identify and manage their respective orders.

Points: 1 point corresponds to the last decimal place of the symbol's price. For a 5-decimal price, 1 point is 0.00001; for a 4-decimal price, 1 point is 0.0001.

Trailing Stop:

  • Parameters: Parameter A [Profit Points to Start], Parameter B [Retracement Points to Close]
  • Function: When an order’s profit reaches or exceeds the points specified in Parameter A, this function continuously monitors the distance between the stop loss price and the current price. If the distance exceeds the points specified in Parameter B, the stop loss is automatically adjusted to the current price minus the points specified in Parameter B.
  • Example: Parameter A = 100, Parameter B = 50. For a BUY order opened at 1.00001, if the price rises to 1.00101 (a profit of 100 points, meeting Parameter A), the stop loss is moved to 1.00051 (current price minus 50 points, Parameter B). If the price rises further to 1.00111, the stop loss adjusts to 1.00061.
  • Note: For BUY orders, the stop loss is only adjusted upward; for SELL orders, it is only adjusted downward.
  • Disable: Set Parameter B [Retracement Points to Close] to 0 to disable this function.
  • Requirement: Parameter B must exceed the MT4 platform’s minimum required distance between the current price and stop loss, or the setting will fail.

Manual Adjustment of Retracement Distance: If enabled, after an order meets the trailing stop condition and the user manually adjusts the stop loss, the EA records the new stop loss distance and uses it for further trailing stop adjustments. If this option is enabled, this instruction should be placed before the order-placing module to clear stored order status information when no orders are open.

Partial Closure: In MT4, if an order is partially closed, the remaining portion is treated as a new order by this EA.