reverse position

Author: Copyright � 2007, Serega Lykov
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
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 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 ---