Author: Copyright � 2014, cmillion@narod.ru
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
0 Views
0 Downloads
0 Favorites
trall
//+------------------------------------------------------------------+
//|                                                 TrailingStop.mq4 |
//|                              Copyright © 2014, Khlystov Vladimir |
//|                                         http://cmillion.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, cmillion@narod.ru"
#property link      "http://cmillion.narod.ru"
//--------------------------------------------------------------------
input int     StopLoss     = 50;     //ñòîïëîññ
input int     TakeProflt   = 100;     //æåëàåìàÿ ïðèáûëü).
input int     TrailingStop = 10;     //êàê ïðèáûëü îðäåðà äîñòèãàåò ýòîãî çíà÷åíèÿ â ïóíêòàõ, Stop Loss ïåðåíîñèòñÿ íà íà öåíó îòêðûòèÿ îðäåðà è äàëåå òðàëèòñÿ ïî ïðîôèòó. 
input int     StepTrall    = 10;     //Øàã Òðàëà.
//--------------------------------------------------------------------
int start()                                  
{      
   double OSL,OTP,OOP,StLo,SL,TP;
   int tip;
   for (int i=0; i<OrdersTotal(); i++)
   {    
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      { 
         if (OrderSymbol()==Symbol())
         { 
            tip = OrderType(); 
            OSL = NormalizeDouble(OrderStopLoss(),Digits);
            OTP = NormalizeDouble(OrderTakeProfit(),Digits);
            OOP = NormalizeDouble(OrderOpenPrice(),Digits);
            SL=OSL;TP=OTP;
            if (tip==OP_BUY)             
            {  
               if (OSL==0 &&StopLoss!=0)
               {
                  SL = NormalizeDouble(OOP - StopLoss   * Point,Digits);
               } 
               if (OTP==0 && TakeProflt!=0)
               {
                  TP = NormalizeDouble(OOP + TakeProflt * Point,Digits);
               } 
               if (TrailingStop!=0)
               {
                  StLo = NormalizeDouble(Bid - TrailingStop*Point,Digits); 
                  if (StLo >= OOP && StLo >= OSL+StepTrall*Point) SL = StLo;
               }
               if (SL != OSL || TP != OTP)
               {  
                  if (!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Print("Error OrderModify ",GetLastError());
               }
            }                                         
            if (tip==OP_SELL)        
            {
               if (OSL==0 && StopLoss!=0)
               {
                  SL = NormalizeDouble(OOP + StopLoss   * Point,Digits);
               }
               if (OTP==0 && TakeProflt!=0)
               {
                  TP = NormalizeDouble(OOP - TakeProflt * Point,Digits);
               }
               if (TrailingStop!=0)
               {
                  StLo = NormalizeDouble(Ask + TrailingStop*Point,Digits); 
                  if (StLo <= OOP && (StLo <= OSL-StepTrall*Point || OSL==0)) SL = StLo;
               }
               if (SL != OSL || TP != OTP)
               {  
                  if (!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Print("Error OrderModify ",GetLastError());
               }
            } 
         }
      }
   } 
   if (IsTesting() && OrdersTotal()==0)
   {
      double Lot=0.1;
      OrderSend(Symbol(),OP_BUY,Lot,NormalizeDouble(Ask,Digits),30,0,0,"òåñò",0);
      OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),30,0,0,"òåñò",0);
      return(0);
   }
   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 ---