Orders Execution
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 Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---