BreakEven_5_TrailingStop

Author: Copyright 2016, MetaQuotes Software Corp.
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
0 Views
0 Downloads
0 Favorites
BreakEven_5_TrailingStop
//+------------------------------------------------------------------+
//|                                     BreakEven & TrailingStop.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                   https://M2P_Design@hotmail.com |
//+------------------------------------------------------------------+
#property library
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://M2P_Design@hotmail.com"
#property version   "1.00"
#property strict

input double        Magic = 280456;
input double    Breakeven = 30;
input double Trailingstop = 50;
//+------------------------------------------------------------------+
//| My BreakEven                                                     |
//+------------------------------------------------------------------+
void BreakEven()
  {
   double MyPoint=Point;
   if(Digits==3 || Digits==5) MyPoint=Point*10;

   for(int i=OrdersTotal()-1; i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol())
            if(OrderMagicNumber()==Magic)
               if(OrderType()==OP_BUY)
                 {
                  if(Bid-OrderOpenPrice()>Breakeven*MyPoint)
                     if(OrderOpenPrice()>OrderStopLoss())
                        int BBM=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,clrNONE);
                 }

      else if(OrderType()==OP_SELL)
        {
         if(OrderOpenPrice()-Ask>Breakeven*MyPoint)
            if(OrderOpenPrice()<OrderStopLoss())
               int BSM=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,clrNONE);
        }
     }
  }
//+------------------------------------------------------------------+
//| My TrailingStop                                                  |
//+------------------------------------------------------------------+
void TrailingStop()
  {
   double MyPoint=Point;
   if(Digits==3 || Digits==5) MyPoint=Point*10;

   for(int i=OrdersTotal()-1; i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol())
            if(OrderMagicNumber()==Magic)
               if(OrderType()==OP_BUY)
                 {
                  if(Bid-OrderOpenPrice()>Trailingstop*MyPoint)
                     if(OrderStopLoss()<Bid-Trailingstop*MyPoint)
                        int TBM=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Trailingstop*MyPoint),OrderTakeProfit(),0,clrNONE);
                 }

      else if(OrderType()==OP_SELL)
        {
         if(OrderOpenPrice()-Ask>Trailingstop*MyPoint)
            if(OrderStopLoss()>Ask+Trailingstop*MyPoint)
               int TSM=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(Trailingstop*MyPoint),OrderTakeProfit(),0,clrNONE);
        }
     }
  }
//+------------------------------------------------------------------+

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