Author: Copyright 2014, MetaQuotes Software Corp.
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

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 ---