//+------------------------------------------------------------------+
//| 0-A-SL-mBE                                                       |
//| Copyright 2012, File45.                                          |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, File45"
#property link      "http://codebase.mql4.com/en/author/file45"
#property show_inputs

input int BEOS = 1; // BE Offset 

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+

int StopLoss;

double itotal,pp;
     
int start()
{ 
  itotal=OrdersTotal();
   
  for(int cnt=itotal-1;cnt>=0;cnt--) 
  {
    if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
    {
      
      if (OrderSymbol()==Symbol() && OrderType()==OP_BUY)
      {
         ModifyStopLoss(OrderOpenPrice()+BEOS*Point);     
      }
      
      if (OrderSymbol()==Symbol() && OrderType()==OP_SELL)
      {
         ModifyStopLoss(OrderOpenPrice()-BEOS*Point);       
      }  
   
      if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && Bid < OrderOpenPrice()+BEOS*Point)
      {
         Alert("Unable to place SL Break Even - Bid below Order Open Price plus BE Offset " + IntegerToString(BEOS));
      }   
      
      if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && Ask > OrderOpenPrice()-BEOS*Point)
      {
         Alert("Unable to place SL Break Even - Ask above Order Open Price less BE Offset " + IntegerToString(BEOS));
      }   
    }
  }
   return(0);
}

void ModifyStopLoss(double ldStopLoss) 
{
   bool fmSL;
   fmSL=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
}

