//+------------------------------------------------------------------+
//|          Free and OpenSource code under MIT License              |
//|              (https://opensource.org/licenses/MIT)               |
//|                 Copyright 2018 penyuperwira                      |
//|          (https://www.forexfactory.com/penyuperwira)             |
//|                  updated : 30.09.2018                            |
//+------------------------------------------------------------------+

#property copyright "Clear TP / SL"
#property show_inputs
//extern int    MagicNumber=274693;
extern string info="Clear TP / SL";
#include <stdlib.mqh>
double pip;
int digits;
double Credit;
double Balance;
double GetoLots;
extern bool    ClearBuy=true;
extern bool    ClearSell=true;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
   double SL,TP,SL2,TP2;
   int i,Total;
   Total=OrdersTotal();
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   if(Total>0)
     {
      SL=0;//buy trade
      TP=0;
      SL2=0;//sell trade
      TP2=0;
      for(i=Total-1; i>=0; i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
           {
            if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && ClearBuy)
              {
               int ticket4=OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,OrderExpiration(),CLR_NONE);
              }
            if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && ClearSell)
              {
               int ticket5=OrderModify(OrderTicket(),OrderOpenPrice(),SL2,TP2,OrderExpiration(),CLR_NONE);
              }
           }
        }
     }
   return(0);
  }
//end