AutoSet TP and SL

Author: Copyright 2019, Catalin Zachiu
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
AutoSet TP and SL
//+------------------------------------------------------------------+
//|                                            AutoSet TP and SL.mq4 |
//|                                   Copyright 2019, Catalin Zachiu |
//|                      https://www.mql5.com/en/users/catalinzachiu |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, Catalin Zachiu"
#property link      "https://www.mql5.com/en/users/catalinzachiu"
#property version   "1.00"
#property strict
 #property show_inputs

input double Set_TP_At = 0;
input double Set_SL_At = 0;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
      int total = OrdersTotal();
  for(int b=total-1;b>=0;b--)
  {
     if(OrderSelect(b, SELECT_BY_POS)==false) break;
     if(OrderCloseTime()!=0 || OrderSymbol()!=Symbol()) continue;
     
     if(OrderType()==OP_BUY)
       if(Set_TP_At>0 && Set_TP_At>Ask)
         if(OrderTakeProfit()>=0)
                 {
                 if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Set_TP_At,0,clrNONE))
                        Print("Take Profit Updated TO New Level ",OrderTicket());
                     
                    }
                  
         if(Set_SL_At>0 && Set_SL_At<Bid)
         if(OrderStopLoss()>=0)
                 {
                 if(!OrderModify(OrderTicket(),OrderOpenPrice(),Set_SL_At,OrderTakeProfit(),0,clrNONE))
                        Print("Stop Loss Updated TO New Level ",OrderTicket());
                     
                    }
                    
      if(OrderType()==OP_SELL)
       if(Set_TP_At>0 && Set_TP_At<Bid)
         if(OrderTakeProfit()>=0)
                 {
                 if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Set_TP_At,0,clrNONE))
                        Print("Take Profit Updated TO New Level ",OrderTicket());
                     
                    }
                  
         if(Set_SL_At>0 && Set_SL_At>Ask)
         if(OrderStopLoss()>=0)
                 {
                 if(!OrderModify(OrderTicket(),OrderOpenPrice(),Set_SL_At,OrderTakeProfit(),0,clrNONE))
                        Print("Stop Loss Updated TO New Level ",OrderTicket());
                     
                    }
  }
//---
   
  }
//+------------------------------------------------------------------+

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