modify_stop_loss

Author: Copyright � 2004, MetaQuotes Software Corp.
modify_stop_loss
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
modify_stop_loss
//+------------------------------------------------------------------+
//|                                         modify_profit_target.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property show_inputs

extern string Trade_Type = "Close Trade Type (0=Buying 1=Selling)";
extern int trade_type_selection = OP_BUY; //default is to close buy trades
extern string New_Target = "New target (in pips - relative to open price)";
extern int new_stop_loss = 20;

//#include <WinUser32.mqh>

//+------------------------------------------------------------------+
//| script "modify first market order"                               |
//+------------------------------------------------------------------+
int start()
  {
   bool   result;
   double profit_target, stop_loss;
   int    cmd,total,error;
   double gd_point;

//----
   total=OrdersTotal();
   gd_point = SetPoint();
//----
   for(int i=0; i<total; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         //---- print selected order
         OrderPrint();
         cmd=OrderType();
         //---- buy or sell orders are considered
         if((cmd==trade_type_selection)&& (OrderSymbol()==Symbol()))
           {
            //---- modify market order
            while(true)
              {
               if(cmd==OP_BUY) stop_loss=OrderOpenPrice()-new_stop_loss*gd_point;
               else            stop_loss=OrderOpenPrice()+new_stop_loss*gd_point;
               profit_target = OrderTakeProfit(); //save current profit targert
               result=OrderModify(OrderTicket(),0,stop_loss,OrderTakeProfit(),0,CLR_NONE);
               if(result!=TRUE) { error=GetLastError(); Print("LastError = ",error); }
               else error=0;
               if(error==135) RefreshRates();
               else break;
              }
             //---- print modified order (it still selected after modify)
             OrderPrint();
             //break;
           }
        }
      else { Print( "Error when order select ", GetLastError()); break; }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

double SetPoint() {
   double ld_point;
   if (Digits < 4) ld_point = 0.01;
   else ld_point = 0.0001;
   return (ld_point);
}

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