stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Delete Orphan Pending Trades
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4031
Page 1 of 1
Author:  gringoh [ Tue Jan 06, 2015 3:07 pm ]
Post subject:  Delete Orphan Pending Trades

Hi Coders,

I am struggling on this code. Initially I thought it would be an easy one but at the end…

This code is monitoring multiple pairs and is supposed to delete orphan pending trades if:

- Open buy or sell trades = 0
- Pending trades is > 0 and < at a specified value

My issue is that once the EA will find a trade with this conditions it will delete all the pending orders and not only the selected symbol pending orders or it will delete immediately all the pending orders…

Any help would be appreciated.

Many thanks.

Cheers,
G

Code: Select all

string         Pair[29]               = {"AUDCAD", "AUDCHF", "AUDJPY", "AUDNZD", "AUDUSD", "CADCHF", "CADJPY", "CHFJPY", "EURAUD", "EURCAD", "EURCHF", "EURGBP", "EURJPY", "EURNZD", "EURUSD", "GBPAUD", "GBPCAD",
                                       "GBPCHF", "GBPJPY", "GBPNZD", "GBPUSD", "NZDCAD", "NZDCHF", "NZDJPY", "NZDUSD", "USDCAD", "USDCHF", "USDJPY", "XAUUSD"};

//-----------------------------------------------------------------------------
// function: Delete_Invalid_Pending()
// Description: Delete_Invalid_Pending
//-----------------------------------------------------------------------------
void Delete_Invalid_Pending() {

   for (int i = 0; i < 28; i++) {

         //Orders variables
            int OpenTrades=0;
            int OpenPendings=0;
            int minpending=5;
            bool result=false;

         //Loop Preparation
            int PositionIndex; //  <-- this variable is the index used for the loop
            int TotalNumberOfOrders; //  <-- this variable will hold the number of orders currently in the Trade pool
            TotalNumberOfOrders = OrdersTotal(); // <-- we store the number of Orders in the variable

      if (OrdersTotal() == 0) return;

      for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  //  <-- for loop to loop through all Orders . .   COUNT DOWN TO ZERO !
      {

         if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue;   // <-- if the OrderSelect fails advance the loop to the next PositionIndex
         if (OrderMagicNumber() != MagicNumber) continue;  // <-- does the Order's Magic Number match our EA's magic number ? 
         if (OrderSymbol() != Pair[i]) continue; // <-- does the Order's Symbol match the Symbol our EA is working on ? 

         if ( (OrderType() == OP_BUY) || (OrderType() == OP_SELL) ) OpenTrades++; //Count Open trades
         if ( (OrderType() > OP_SELL) ) OpenPendings++; //Count Open Pending trades


         //Delete invalid pending trades
            if ( (OpenPendings > 0) && (OpenTrades == 0) && (OpenPendings < minpending) )
            {
               result = OrderDelete(OrderTicket());
            }

      }//End for
   }//End for
} // End Delete_Invalid_Pending
Author:  gringoh [ Tue Jan 06, 2015 6:47 pm ]
Post subject:  Delete Orphan Pending Trades

I finally managed to solve the problem... after a long time but it's done. (code will be included in the next version of my dashboard).

I will delete this post later.

Cheers,
G
All times are UTC Page 1 of 1