Stop to Break Even Question

 

Hi all you smart people! 

I am working on an EA in MT5 for some basic trade management. My trigger for moving the stop to break even is the current PNL of the position. For example, if my PNL on the trade is $500, move SL to BE. Now, I would like to implement a true break even that takes fees into account. I am struggling to understand how to calculate what price, then to set the SL to to take fees and swap into account. Can anyone help? 

If I can get that figured out, I would like to add an addition X% profit. So the ideal end state of this would be that my "breakeven" price is actually open price + increase for swap/fees + increase for some % of profit. 

 
Please show your attempt if you need help.
 

Ok here's the function I am writing to do trade mgmt. Right now, it's a simple stop -> break even if the current order profit hits a certain amount in USD. 

What I would like to do is to update this function to 1) enable a trailing stop (easy, just an input var), but then 2) to move the SL up in $250 profit capturing increments. I need help with the calculation for #2. In other words, how do I calculate the new SL price that will be $250 profit on the position? I don't have an attempt b/c I keep getting turned around on how to start. 

Here's the current code: 

void PerformTradeManagement(ulong ticket){

   string strPositionType; 
   
   // 0 = Buy, 1 = Sell
   int positionType = PositionGetInteger(POSITION_TYPE);
   if (positionType == 0)
      strPositionType = "Buy";
   else
      strPositionType = "Sell"; 
   //Print ("Start TM for #" + ticket + " - " + symbol + " - Type: " + strPositionType + " Open: " + openPrice + " Bid: " + Bid + " Ask: " + Ask);   
   // move price to BE IF 1) the setting is on 2) PNL hit trigger 3) Current SL and Open arent the same (it's already been moved)
   if(useStopToBE && PositionGetDouble(POSITION_PROFIT) > BreakevenTrigger && !(PositionGetDouble(POSITION_SL) == PositionGetDouble(POSITION_PRICE_OPEN))){
      Print ("Change SL for #" + ticket + " - " + PositionGetString(POSITION_SYMBOL) + " PNL: $" + PositionGetDouble(POSITION_PROFIT) + " - Type: " + strPositionType + ". New SL: " + PositionGetDouble(POSITION_PRICE_OPEN));
      trade.PositionModify(ticket, PositionGetDouble(POSITION_PRICE_OPEN), 0);
   }       
}
Reason: