Trailing Stop v_tdavid

Download script
Author: transport_david , David W Honeywell
Trailing Stop v_tdavid

This automated script is designed to manage your open trading positions by dynamically adjusting your "stop loss" levels as the market moves in your favor. The primary goal of this tool is to lock in profits and minimize potential losses during a live trade without requiring you to manually intervene.

How the Logic Works

The script continuously monitors your active trades on a specific currency pair or asset. It follows a systematic process to ensure your risk management remains proactive:

  • Profit Verification: Before taking any action, the script first checks if a trade is currently in a profitable state (i.e., the current price has moved favorably compared to your entry price).
  • Distance Monitoring: Once a trade becomes profitable, the script measures the distance between your entry point and the current market price.
  • Dynamic Adjustment: If the profit exceeds a specific pre-defined threshold (the "Trailing Stop" value), the script automatically moves your stop loss level forward. It places the new stop loss at a set distance behind the current market price.
  • Continuous Tracking: As the market continues to move in your favor, the script will repeatedly update and "trail" the stop loss higher (in an uptrend) or lower (in a downtrend). This ensures that if the market suddenly reverses, you exit the position with a portion of your gains already secured.

Key Benefits for Traders

By utilizing this logic, the tool automates the defensive side of trading. It essentially acts as a safety net that "follows" the price; if the price moves significantly in your direction, the script protects those gains by ensuring the exit point moves with it. This reduces the emotional stress of watching a winning trade turn into a loss due to a sudden market correction.

Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
15 Views
0 Downloads
0 Favorites
Trailing Stop v_tdavid
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                       Trailing Stop v_tdavid.mq4 |
//|                              transport_david , David W Honeywell |
//|                                        transport.david@gmail.com |
//+------------------------------------------------------------------+
#property copyright "transport_david , David W Honeywell"
#property link      "transport.david@gmail.com"

extern int MagicNumber  = 123;
extern int TrailingStop =  15;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   
   int cnt,total=OrdersTotal();
   
   for(cnt = total-1; cnt >= 0; cnt--)
    {
     RefreshRates();
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
     if ((OrderSymbol() == Symbol()) && (OrderProfit() > 0.00)   ) //&& (OrderMagicNumber() == MagicNumber))
      {
       if ((TrailingStop > 0) && (MathAbs(OrderClosePrice() - OrderOpenPrice()) > TrailingStop*Point))
        {
          OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice()-TrailingStop*Point,OrderTakeProfit(),0,White);
        }
      }
    }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments