Modify_pending_v1

Download script
Author: Copyright � 2004, MetaQuotes Software Corp.
Modify_pending_v1

This script is designed to automate a specific adjustment to your trading portfolio within the MetaTrader platform. Its primary purpose is to identify and automatically shift the entry price of the first "pending" order it finds in your active trades.

How the Logic Works

1. Scanning Your Active Trades When you run this script, it begins by scanning through all of your currently open positions and pending orders. It looks at every active trade to see what type of order it is.

2. Filtering for Pending Orders The script is programmed to ignore "market" orders (trades that are already live in the market, such as active Buys or Sells). Instead, it specifically searches for "pending" orders—these are trades you have placed that are waiting for the price to reach a certain level before being executed.

3. Identifying the Target The script processes these orders one by one. As soon as it encounters the very first pending order in your list, it selects it for modification and then stops looking at any other orders. This ensures that only one trade is affected per execution of the script.

4. Executing the Price Adjustment Once the first pending order is identified, the script performs a precise calculation:

  • It takes the current entry price you set for that order.
  • It subtracts a small, fixed amount from that price (specifically, it moves the price 10 "points" lower).
  • It then automatically updates the order on the server with this new, lower price while keeping all other settings—such as the expiration date and volume—exactly as they were.

5. Verification and Reporting After attempting to make the change, the script checks to see if the platform successfully accepted the modification. If it succeeds, it provides a confirmation message; if something prevents the change (such as a price limit or connection issue), it records an error message for you to review in your trade logs.

Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
19 Views
0 Downloads
0 Favorites
Modify_pending_v1
//+------------------------------------------------------------------+
//|                                               modify_pending.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property show_confirm

//+------------------------------------------------------------------+
//| script "modify first pending order"                              |
//+------------------------------------------------------------------+
int start()
  {
   bool   result;
   double price,point;
   int    cmd,total,nTicket;
   int    expiration;
//----
   total=OrdersTotal();
   point=MarketInfo(Symbol(),MODE_POINT);
//----
   for(int i=0; i<total; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         cmd=OrderType();
         //---- pending orders only are considered
         if(cmd!=OP_BUY && cmd!=OP_SELL)
           {
            //---- print selected order
            OrderPrint();
            //---- modify first pending order
            price=OrderOpenPrice()-10*point;
            expiration=OrderExpiration();
            nTicket=OrderTicket();
            result=OrderModify(nTicket,price,0,0,expiration,CLR_NONE);
            if(result!=TRUE) Print("LastError = ", GetLastError());
            //---- print modified order (it still selected after modify)
            else if(OrderSelect(nTicket,SELECT_BY_TICKET)) OrderPrint();
            break;
           }
        }
      else { Print( "Error when order select ", GetLastError()); break; }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments