Break even script

 
Hello everyone.

I have coded quite a lot of things in mql4 and I am struggling to grasp simple concepts in mql5.

I am looking for a script that will simply move or create all stop losses @ user's input choice.

For instance I have 5 open trades that are all 10 pips in profit. I then use the script to create a stop loss that's .2 pips past my entry in profit creating a break even scenario if price were to come back.  

Any help if you have a script that can do this to share or other code that can help me accomplish this goal would be great.  

The closest I got was a script from another person that creates the stop loss / tp to where the current BID / ASK price is not my position placement.  

//+------------------------------------------------------------------+
//|                                                 Modify SL TP.mq5 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, fxMeter"
#property link      "https://www.mql5.com/en/users/fxmeter"
#property version   "1.00"

#property script_show_inputs
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh> 
CPositionInfo  posi;    
CTrade         trade; 
CSymbolInfo    symb;
input double InpStoploss=0.0; //StopLoss Pips
input double InpTakeProfit=0.0;//TakeProfit Pips
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
double stoploss=0.0;
double takeprofit=0.0;
ulong  slippage=3;
int    pt=1;

   symb.Name(Symbol());   
   if(!symb.RefreshRates())return;
   if(symb.Digits()==5 || symb.Digits()==3) pt=10;

   stoploss=InpStoploss*pt;   
   slippage    = slippage * pt;
   takeprofit  = InpTakeProfit * pt;
   trade.SetDeviationInPoints(slippage);  
   
   //---
   double curBid = symb.Bid();   
   double slbuy=0.0,slsell=0.0,tpbuy=0.0,tpsell=0.0;
   if(stoploss>0)
   {
    slbuy =   curBid  - stoploss*symb.Point();
    slsell =  curBid + stoploss*symb.Point();
   }
   
   if(takeprofit>0)
   { 
    tpbuy =   curBid  + takeprofit*symb.Point();    
    tpsell =  curBid - takeprofit*symb.Point();
   }
   
   ModifySLTP(slbuy,tpbuy,slsell,tpsell);
   
  }
//+------------------------------------------------------------------+  
void ModifySLTP(double slPriceBuy,double tpPriceBuy,double slPriceSell,double tpPriceSell)
{
//---     
      double sl=0.0 ,tp=0.0;      
      bool bslbuy = false,btpbuy = false, bslsell = false, btpsell = false;
      if(slPriceBuy>0)bslbuy=true;
      if(tpPriceBuy>0)btpbuy=true;
      if(slPriceSell>0)bslsell=true;
      if(tpPriceSell>0)btpsell=true;
      
      if(!bslbuy && !btpbuy && !bslsell && !btpsell )
      {
          Print(__FUNCTION__,",No SL/TP need to be modified");
          return;
      }
      
      
      for(int i=PositionsTotal()-1;i>=0;i--)
      {
         if(posi.SelectByIndex(i))
         {
            if(posi.Symbol()==Symbol() )
            {                
               if(posi.PositionType()==POSITION_TYPE_BUY)
                 {
                     if(bslbuy)sl=slPriceBuy;else sl = posi.StopLoss();  
                     if(btpbuy)tp=tpPriceBuy;else tp = posi.TakeProfit();               
                     trade.PositionModify(posi.Ticket(),NormalizeDouble(sl,Digits()),NormalizeDouble(tp,Digits()));
                 }

               if(posi.PositionType()==POSITION_TYPE_SELL)
                 {
                     if(bslsell)sl=slPriceSell;else sl = posi.StopLoss();
                     if(btpsell)tp=tpPriceSell;else tp = posi.TakeProfit(); 
                     trade.PositionModify(posi.Ticket(),NormalizeDouble(sl,Digits()),NormalizeDouble(tp,Digits()));
                 }
              }
             }
          } 
//---
}

 
PAPDoug:
I have coded quite a lot of things in mql4 and I am struggling to grasp simple concepts in mql5.
I am looking for a script that will simply move or create all stop losses @ user's input choice.
input uint InpStoploss = 0;   //StopLoss Pips
input uint InpTakeProfit = 0; //TakeProfit Pips

#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006

void OnStart()
{
  for (int i = OrdersTotal() - 1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS) && (OrderType() <= OP_SELL))
    {
      const double point = OrderType() ? -SymbolInfoDouble(OrderSymbol(), SYMBOL_POINT) : SymbolInfoDouble(OrderSymbol(), SYMBOL_POINT);
      
      OrderModify(OrderTicket(), OrderOpenPrice(), InpStoploss ? OrderOpenPrice() - InpStoploss * point : 0,
                                                   InpTakeProfit ? OrderOpenPrice() + InpTakeProfit * point : 0, 0);
    }    
}
 
fxsaber:

Thank you!  Will I be able to do fractions of Pips with this ?  instead of 1 be able to do decimals like .2 ?

 
PAPDoug:

Thank you!  Will I be able to do fractions of Pips with this ?  instead of 1 be able to do decimals like .2 ?

One pip is the minimum price change. Therefore, items can only be integers.

For example, EURUSD 1pip = 0.00001.