Help! - How to make trailing stop loss take into consideration of order commission and order swap?

 

I get negative profit when running trailing stop loss because the code does not account for the commission and swap,

I tried the followings which don't work

need help, thanks!


void LongTrailingStop()
{
int lcnt;
int ltotal = OrdersTotal();
double BuyProfit;

for(lcnt=ltotal-1; lcnt >= 0; lcnt--)
{
OrderSelect(lcnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>(Point*TrailingStop))
{
if(OrderStopLoss()<Bid-(Point*TrailingStop))
{
BuyProfit = (OrderProfit() + OrderCommission() + OrderSwap());
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Point*TrailingStop+BuyProfit),OrderTakeProfit(),0,Green);
return(0);
}
}
}

}
}
}
}