ReEnterOrders





//+------------------------------------------------------------------+
//|                                                ReEnterOrders.mq4 |
//|                                     Copyright © 2007, Amr Zoheir |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Amr Zoheir"
#property link      "http://www.metaquotes.net"

extern int slippage= 3;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
  
  
bool checkOpenOrders(string pSymbol, int pType)
{

   int i;
   for (i = 0; i <= OrdersTotal(); i++)
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);            
      int oType= OrderType();
      if ( oType == OP_BUY ) oType= OP_BUYLIMIT;
      if ( oType == OP_SELL ) oType= OP_SELLLIMIT;                      
      if ( (OrderSymbol() == pSymbol) && (oType == pType) )
      {
         return (true);
      }
   }
   return ( false);

}  
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----

   int i=0;
   int hstTotal=OrdersHistoryTotal();

   for(i=hstTotal-1;i>0;i--)
   { 
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
     {
        Print("Access to history failed with error (",GetLastError(),")");
        break;
     }
     else 
     {      
       double oProfit= OrderProfit();
       if ( oProfit > 0 )
       { 
         string oSym= OrderSymbol();       
         int oType= OrderType();                               
         if ( oType == OP_BUY ) oType= OP_BUYLIMIT;
         if ( oType == OP_SELL ) oType= OP_SELLLIMIT;                         

         bool orderExist= checkOpenOrders(oSym, oType);

         if (orderExist== false){ 
            if ( oType == OP_BUYLIMIT && Bid < NormalizeDouble(OrderOpenPrice(),MarketInfo(oSym,MODE_DIGITS)))
               oType= OP_BUYSTOP;
            if ( oType == OP_SELLLIMIT && Ask> NormalizeDouble(OrderOpenPrice(),MarketInfo(oSym,MODE_DIGITS)))
               oType= OP_SELLSTOP;
                                                
            OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);            
            OrderSend( oSym, oType, OrderLots(), NormalizeDouble(OrderOpenPrice(),MarketInfo(oSym,MODE_DIGITS)), slippage, NormalizeDouble(OrderStopLoss(),MarketInfo(oSym,MODE_DIGITS)), NormalizeDouble(OrderTakeProfit(),MarketInfo(oSym,MODE_DIGITS)), "Re:"+OrderComment(),OrderMagicNumber(),OrderExpiration(),Green);
            return(0);
         }
         
       }
     
     }
    }

//----
   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders

Checks for the total of closed orders
It automatically opens orders when conditions are reached

Other Features:

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2009-12-01 to 2010-01-17 Profit Factor:0.00 Total Net Profit:0.00

BackTest : USDCAD on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2009-08-01 to 2009-10-01 Profit Factor:0.00 Total Net Profit:0.00

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-04-01 to 2010-04-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-05-01 to 2010-05-31 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-06-01 to 2010-06-30 Profit Factor:0.00 Total Net Profit:0.00

Request Backtest for ReEnterOrders


From : (yyyy/mm/dd) To: (yyyy/mm/dd)

Pair: Period: