Author: Copyright 2014, MetaQuotes Software Corp.
Profit factor:
0.00
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
0 Views
0 Downloads
0 Favorites
lentjay
//+------------------------------------------------------------------+
//|                                                      lentjay.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
//--- input parameters
input int      tp=200;
input int      sl=400;
input int      trstop=150;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   int ticket=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,"My order",16384,0,clrGreen);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
 int i;
//1.ïðîâåðÿåì ÷òî òåéêïðîôèò è ñòîïëîñ ñòîÿò
   for( i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
        {
        if(OrderSymbol()!=Symbol()) continue;
        if(OrderTakeProfit()==0 || OrderStopLoss()==0){
            if(OrderType()==OP_BUY ) {
                bool res=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-sl*Point,Digits),NormalizeDouble(OrderOpenPrice()+tp*Point,Digits),0,Blue);
            }
            if(OrderType()==OP_SELL ) {
                bool res=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+sl*Point,Digits),NormalizeDouble(OrderOpenPrice()-tp*Point,Digits),0,Blue);
            }
        }
     }
   }

/////////////////////////////////////////
   for( i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderSymbol()!=Symbol()) continue;
//2.òðàëèì ñòîïëîòñ 
         if(OrderType()==OP_BUY && OrderStopLoss()< Bid-sl*Point-trstop*Point) {
           bool res=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-sl*Point,Digits),OrderTakeProfit(),0,Blue);
         }
         if(OrderType()==OP_SELL && (OrderStopLoss()> Ask+sl*Point+trstop*Point || OrderStopLoss()==0)) {
             bool res=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+sl*Point,Digits),OrderTakeProfit(),0,Blue);
         }
      }
   }
}
//+------------------------------------------------------------------+

Comments