Add Swap fees and commissionin on open orders EA

To add comments, please log in or register
Agiofin
14
Agiofin  

I have discovered that my EA does something weird, to explain, most days of the week once it closes it all my trades my balance woul dbe more than my balance when the day started, I found out that the days it was less is because of swap fees.

I tried finding a solution for this but there is very little on the topic.

My code states that if it reaches 10 profit it should close all my trades.

It works fine unless there s swap fees, it closes but when I look I see for a day I lost few $ due to Swap fees and commission.

Is there a way to code it so that AccountProfit will add into it all the swap fees and commission and add $10.

Even If I should declare another variable to add it in, I cannot seem to find anything in MQL4 that is a variable that gives you the commission and swap fees added.

If you can point me to the right location for some help I would be grateful.
Im new to programming it so please excuse myself.


 if (AccountProfit()>10){
                    
            tradestatus = "CLOSING ALL TRADES NOW !!!";
           
            CloseAll();           
                    
}else{
                                 
            tradestatus = "TRADING ... WAIT FOR POSITIVE BALANCE TO CLOSE";
                       
}

Matthew Colter
1322
Matthew Colter  
Sum up all the fees for your open orders and subtract it from the profit.
Matthew Colter
1322
Matthew Colter  

//+------------------------------------------------------------------+
//|Gets the current net profit of open positions on the given        |
//|currency pair.                                                    |
//+------------------------------------------------------------------+
double PairProfit(string symbol)
  {
   double sum=0;
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==symbol && (OrderType()==OP_BUY || OrderType()==OP_SELL))
        {
         sum=sum+OrderProfit()+OrderSwap()+OrderCommission();
        }
     }
   return sum;
  }


Something like that. Probably should do some error checking for valid values.

To add comments, please log in or register