tp-sl_removing

Author: Copyright � 2016 (Mike eXplosion)
tp-sl_removing

This script is designed for MetaTrader users who want to quickly clear the exit parameters of their active trades. Its primary purpose is to remove both Take Profit (TP) and Stop Loss (SL) levels from all currently open positions in a single action.

How it works:

  1. Active Trade Detection: When you run the script, it first performs a scan of your trading account to identify any active "Buy" or "Sell" positions. It counts how many of each type are currently live on the market.

  2. Validation: The script checks to see if there are actually any open trades to manage. If the account is empty (no active positions), the script identifies that there is nothing to do and finishes its task automatically without making any changes.

  3. Automatic Modification: If active positions are detected, the script proceeds to "clean" them. It systematically goes through every open trade and updates the order details. Specifically, it resets the Take Profit and Stop Loss values to zero.

  4. The Result: Once completed, your trades remain open in the market, but they will no longer have any automatic exit prices attached to them. This allows you to manage your positions manually or wait for a specific price point without the risk of being closed out by a pre-set limit.

Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
6 Views
0 Downloads
0 Favorites
tp-sl_removing
//+------------------------------------------------------------------+
//|                                                   TP-SL Removing |
//|                                Copyright © 2016 (Mike eXplosion) |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2016 (Mike eXplosion)"
#property link      "https://www.mql5.com/en/users/mike_explosion"
#property version   "1.0"

#property strict

#property description "Elimina TakeProfit y StopLoss de todas las posiciones."
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CalculateCurrentOrders()
  {
   int buys=0,sells=0;

   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderType()==OP_BUY)
        {
         buys++;
        }
      if(OrderType()==OP_SELL)
        {
         sells++;
        }
     }

   if(buys>0) return(buys);
   else       return(-sells);

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ClearSLnTP()
  {
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      bool res=OrderModify(OrderTicket(),OrderOpenPrice(),0,0,0,Blue);

     }
   return false;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   if(CalculateCurrentOrders()!=0)
      ClearSLnTP();
  }
//+------------------------------------------------------------------+

Comments