Close All Orders and / or Reverse FIFO rules scripts

 

At present time it appears there isn't a script that will close all open positions and or reverse them in compliance with FIFO rules. For accounts running on US soil this makes the existing scripts useless because the script seeks to close positions randomly and without respecting First In First Out order imposed by this rule.

If such scripts do exist please let me know, but I haven't found them. Otherwise, I think they would be a very useful addition to MetaTrader, allowing for fast and nimble trading action under FIFO.

Thanks!

NoIdea

 
NoIdea:

For accounts running on US soil this makes the existing scripts useless [...]

Oanda is the only broker I'm aware of where a simple close-all does not work. There may be others but, equally, there are definitely US brokers (e.g. IBFX US) where a simple close-all does work, i.e. you can loop down from OrdersTotal(), closing the newer orders first.
 
JC:
Oanda is the only broker I'm aware of where a simple close-all does not work. There may be others but, equally, there are definitely US brokers (e.g. IBFX US) where a simple close-all does work, i.e. you can loop down from OrdersTotal(), closing the newer orders first.
what about a script that prevents a new sell on a currency pair if their is already a sell running. or a buy on a currency pair if their is already a buy running? I cant seem to find one anywhere that does that.
 

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Close_AllOrders()
  {
//Close Orders according to FIFO Rule
   for(i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol())
           {
            switch(OrderType())
              {
               case OP_BUY:
                  Result_Close=OrderClose(OrderTicket(),OrderLots(),Bid,0);
                  if(Result_Close) i--;
                  break;
               case OP_SELL:
                  Result_Close=OrderClose(OrderTicket(),OrderLots(),Ask,0);
                  if(Result_Close) i--;
                  break;
              }
           }
     }
/*-------------------------------------------------------------------------------------------------*/
  }
this works for me, hope it is what you are looking for.
Reason: