modify_pending

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

This script is designed to automate a simple adjustment for your open trading positions. Specifically, it searches through your active market list to identify and modify the first "pending" order it encounters.

Unlike active trades (where you are already in the market), pending orders are instructions to enter a trade at a specific price in the future. This tool looks for those types of orders and applies a consistent, minor price adjustment to them automatically.

How the logic works:

  • Scanning Your Orders: When you run the script, it starts by scanning your entire list of open trades one by one.
  • Identifying Pending Trades: The script filters out any orders that are already active (like currently running Buy or Sell positions). It is looking specifically for "pending" orders—the ones waiting for the market to reach a certain level.
  • Locating the First Match: As soon as it finds the very first pending order in your list, it takes action and then stops. It will not modify multiple orders; it only handles the first one it sees.
  • The Price Adjustment: Once it identifies that first pending order, it automatically lowers the entry price. Specifically, it moves the trigger price down by a set amount (calculated based on the smallest price movement possible for that specific currency or asset).
  • Preserving Other Details: While the script changes the entry price, it leaves all other settings—such as your expiration time and your stop-loss or take-profit levels—exactly as they were originally set.
  • Confirmation & Feedback: After attempting the modification, the script provides a status update. It will confirm if the change was successful or provide an error notification if something prevented the adjustment from happening.
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
18 Views
0 Downloads
0 Favorites
modify_pending
//+------------------------------------------------------------------+
//|                                               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;
   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();
            result=OrderModify(OrderTicket(),price,0,0,expiration,CLR_NONE);
            if(result!=TRUE) Print("LastError = ", GetLastError());
            //---- print modified order (it still selected after modify)
            else OrderPrint();
            break;
           }
        }
      else { Print( "Error when order select ", GetLastError()); break; }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments