Break Even Mql4

 

Function to bring the stop loss to the opening price or just above the entry


void break_even(int MAGIGMA_n, int break_points, int positive_points, int stop)

 {
 bool Return;
  for(int i = 0; i < OrdersTotal(); i++)
   {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
     {
    
     RefreshRates(); 
      if(OrderMagicNumber() == MAGIGMA_n && OrderSymbol() == _Symbol && OrderType()== OP_BUY)
       {
         if(OrderStopLoss() < OrderOpenPrice())
          {
           if(Ask > OrderOpenPrice()+break_points*_Point)
            {
             Return = OrderModify(OrderTicket(),Ask,(OrderOpenPrice() + positive_points*_Point),OrderTakeProfit(),0,clrNONE);
             
              if(!Return) 
               Print("Error  OrderModify. error code = ",GetLastError()); 
            }
          }
       }
     RefreshRates();  
      if(OrderMagicNumber() == MAGIGMA_n && OrderSymbol() == _Symbol && OrderType()== OP_SELL)
       {
         if(OrderStopLoss() > OrderOpenPrice())
          {
           if(Bid < OrderOpenPrice()-break_points*_Point)
            {
             Return = OrderModify(OrderTicket(),Bid,(OrderOpenPrice() - positive_points*_Point),OrderTakeProfit(),0,clrNONE);
             
              if(!Return) 
               Print("Error  OrderModify. error code = ",GetLastError()); 
            }
          }
       }
     }
   }
   
 }
 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.


  2. eturn = OrderModify(OrderTicket(),Ask,(OrderOpenPrice() + positive_points*_Point),OrderTakeProfit(),0,clrNONE);

    You can not modify the open price of an open order.

 
William Roeder # :
  1. Why did you post your MT 4 question in the MT 5 General section instead of the MQL 4 section (bottom of the Root page )?
    General rules and good practices of the Forum. - General - MQL5 programming forum ? (20 17 )
    Next time, post in the correct location. Moderators will likely move this thread there soon.


  2. You cannot modify the opening price of an open order.


Sorry, I sent it in the wrong place, but it wasn't a question, I just wanted to share a code I made that might help someone else, but thank you very much for your answer.
 

Please post only in English on this part of the forums. Use the automatic translation tool if needed. Use simple language structure when using mechanical translation. (2013)

Or use the Português forum.