Orders Execution
0
Views
0
Downloads
0
Favorites
reverse position
//+------------------------------------------------------------------+
//| reverse position.mq4 |
//| Copyright © 2007, Serega Lykov |
//| http://www.mtexperts.narod.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Serega Lykov"
#property link "http://www.mtexperts.narod.ru/"
#property show_confirm
#include <stdlib.mqh>
#include <WinUser32.mqh>
//+------------------------------------------------------------------+
//| "reverse first market order if it is first at current currency" |
//+------------------------------------------------------------------+
int start()
{
double price;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol())
{
int dir=OrderType();
double tp=OrderStopLoss();
double sl=OrderTakeProfit();
double lot=OrderLots();
if(dir==OP_BUY)
{
double clprice=Bid;
OrderClose(OrderTicket(),lot,clprice,3,CLR_NONE);
int cmd=OP_SELL;
break;
}
if(dir==OP_SELL)
{
clprice=Ask;
OrderClose(OrderTicket(),lot,clprice,3,CLR_NONE);
cmd=OP_BUY;
break;
}
}
}
int ticket=OrderSend(Symbol(),cmd,lot,clprice,3,sl,tp,"script to reverse",2,0,CLR_NONE);
if(ticket<1)
{
int error=GetLastError();
Print("Error! = ",ErrorDescription(error));
return;
}
//----
OrderPrint();
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
---