cm_sl_nl_tp

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
cm_sl_nl_tp
//+------------------------------------------------------------------+
//|                               Copyright © 2014, Õëûñòîâ Âëàäèìèð |
//|                                                cmillion@narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, http://cmillion.narod.ru"
#property link      "cmillion@narod.ru"
#property description "Ñîâåòíèê âûñòàâëÿåò âñåì îðäåðàì ñòîïëîññ òåéêïðîôèò è ïåðåâîäèò èõ â áåçóáûòîê"
//--------------------------------------------------------------------*/
extern int     Stoploss             = 100,           //ñòîïëîññ
               Takeprofit           = 50,            //òåéêïðîôèò
               NoLoss               = 10,            //ïåðåâîä â áåçóáûòîê, åñëè 0, òî íåò ïåðåâîäà â áåçóáûòîê
               MinProfitNoLoss      = 1;             //ìèíèìàëüíàÿ ïðèáûëü ïðè ïåðåâîäå âáåçóáûòîê
//-------------------------------------------------------------------- 
int init() 
{ 
   DrawLABEL("Stoploss",StringConcatenate("Stoploss ",Stoploss),5,15,Gray);
   DrawLABEL("Takeprofit",StringConcatenate("Takeprofit ",Takeprofit),5,35,Gray);
   DrawLABEL("NoLoss",StringConcatenate("NoLoss ",NoLoss," + ",MinProfitNoLoss),5,55,Gray);
   return(0);
}
//-------------------------------------------------------------------
int deinit()
{
   ObjectDelete("Stoploss");
   ObjectDelete("Takeprofit");
   ObjectDelete("NoLoss");
   return(0);
}
//--------------------------------------------------------------------
int start()
{
   if (!IsTradeAllowed()) return(0);
   int STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);
   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>=STOPLEVEL && Stoploss!=0)
               {
                  SL = NormalizeDouble(OOP - Stoploss   * Point,Digits);
               } 
               if (OTP==0 && Takeprofit>=STOPLEVEL && Takeprofit!=0)
               {
                  TP = NormalizeDouble(OOP + Takeprofit * Point,Digits);
               } 
               if (OSL<OOP && NoLoss!=0 && NoLoss>=STOPLEVEL)
               {
                  StLo = NormalizeDouble(OOP+MinProfitNoLoss*Point,Digits); 
                  if (StLo > OSL && StLo <= NormalizeDouble(Bid - NoLoss * Point,Digits)) 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>=STOPLEVEL && Stoploss!=0)
               {
                  SL = NormalizeDouble(OOP + Stoploss   * Point,Digits);
               }
               if (OTP==0 && Takeprofit>=STOPLEVEL && Takeprofit!=0)
               {
                  TP = NormalizeDouble(OOP - Takeprofit * Point,Digits);
               }
               if ((OSL>OOP || OSL==0) && NoLoss!=0 && NoLoss>=STOPLEVEL)
               {
                  StLo = NormalizeDouble(OOP-MinProfitNoLoss*Point,Digits); 
                  if ((StLo < OSL || OSL==0) && StLo >= NormalizeDouble(Ask + NoLoss * Point,Digits)) SL = StLo;
               }
               if (SL != OSL || TP != OTP)
               {  
                  if (!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Print("Error OrderModify ",GetLastError());
               }
            } 
         }
      }
   } 
return(0);
}
//--------------------------------------------------------------------
void DrawLABEL(string name, string Name, int X, int Y, color clr)
{
   if (ObjectFind(name)==-1)
   {
      ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
      ObjectSet(name, OBJPROP_CORNER, 1);
      ObjectSet(name, OBJPROP_XDISTANCE, X);
      ObjectSet(name, OBJPROP_YDISTANCE, Y);
   }
   ObjectSetText(name,Name,12,"Arial",clr);
}
//--------------------------------------------------------------------

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