//+------------------------------------------------------------------+ //| 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: