Order Modify All TakeProfit and StopLoss (Price)

OrderModify_All_TP_n_SL(Price)


The script modifies all orders (market and pending) on the symbol with specified Take Profit and Stop Loss. If the take profit or(and) stop loss is incorrect, then the value is not changed.

Parameters :
  • Take Profit (price)
  • Stop Loss (price)


Code :
//+------------------------------------------------------------------+
//|                               OrderModify_All_TP_n_SL(Price).mq4 |
//|                                      Copyright 2018, MetaEditor. |
//|                             https://www.meta-editor.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaEditor."
#property link      "https://www.meta-editor.blogspot.com"
#property version   "1.00"
#property description   "The script modifies all orders (market and pending) on the symbol Take Profit and Stop Loss."
#property description   "https://www.meta-editor.blogspot.com"
#property script_show_inputs
#property strict

input double TakeProfit=0; //Take Profit (price)
input double StopLoss=0;   //Stop Loss (price)

double tp,sl;
int i,i2,Ticket;

void OnStart()
  {
   if(OrdersTotal()>0)
     {
      for(i=OrdersTotal()-1; i>=0; i--)
        {
         i2=false; while(i2==false && !IsStopped())i2=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

         tp=NormalizeDouble(TakeProfit,_Digits);
         sl=NormalizeDouble(StopLoss,_Digits);

         if(OrderSymbol()==Symbol())
           {
            Ticket=OrderTicket();
            if(tp<=0) tp=OrderTakeProfit();
            if(sl<=0) sl=OrderStopLoss();
            if(OrderType()==OP_SELL || OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP)
              {
               if(tp>OrderOpenPrice()) tp=OrderTakeProfit();
               if(sl<OrderOpenPrice()) sl=OrderStopLoss();
               Ord_Modify();
              }
            if(OrderType()==OP_BUY || OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP)
              {
               if(tp<OrderOpenPrice()) tp=OrderTakeProfit();
               if(sl>OrderOpenPrice()) sl=OrderStopLoss();
               Ord_Modify();
              }
           }
        }
     }
   return;
  }
  
  
void Ord_Modify()
  {
   ResetLastError();
   if(OrderCloseTime()==0)
     {
      i2=false;
      while(!i2 && !IsStopped())
        {
         i2=OrderModify(Ticket,OrderOpenPrice(),sl,tp,0,clrNONE);
         if(i2==false)
           {
            Print("Error modifying orders, error # "+IntegerToString(GetLastError()));
            while(!RefreshRates() && !IsStopped())
               Sleep(100);
           }
        }
     }
  }

Download : OrderModify_All_TP_n_SL(Price).mq4
 
Comments
0 Comments

0 komentar:

Posting Komentar