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);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders

It Closes Orders by itself
It automatically opens orders when conditions are reached

Other Features: