ReEnterOrders

Author: Copyright � 2007, Amr Zoheir
Orders Execution
Checks for the total of open ordersChecks for the total of closed ordersIt automatically opens orders when conditions are reached
0 Views
0 Downloads
0 Favorites
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);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---