Difficulties of translation :) - page 5

 
fxsaberif there is #include <Trade/Trade.mqh>, insert this line AFTER
If after - all ok )
 
Alexey Volchanskiy:

Question - how do I know the commission of a position in MQL5?

I did it in MQL4 like this

There is no commission in MQL5.

I looked in the order properties, and there is no commission as well. What should I do?

It is somewhere in the properties of a symbol
 
Alexey Volchanskiy:

Question - how do I know the commission of a position in MQL5?

I did it in MQL4 like this

There is no commission in MQL5.

I looked in the order properties, and there is no commission as well. What should I do?

You should look in the deal properties. HistoryDealGetDouble(ticket, DEAL_COMMISSION);
 
Alexey Volchanskiy:

Question - how do I know the commission of a position in MQL5?

I did it in MQL4 like this

There is no commission in MQL5.

I looked in the order properties, and there is no commission as well. What should I do?

The library will return the correct value when calling

OrderCommission()

The source code shows the following

   static ulong GetPositionDealIn(const ulong HistoryTicket=0)
     {
      ulong Ticket=0;

      if((HistoryTicket==0) ? ::HistorySelectByPosition(::PositionGetInteger(POSITION_TICKET)) : ::HistorySelectByPosition(HistoryTicket))
        {
         const int Total=::HistoryDealsTotal();

         for(int i=0; i<Total; i++)
           {
            const ulong TicketDeal=::HistoryDealGetTicket(i);

            if(TicketDeal>0)
               if((ENUM_DEAL_ENTRY)::HistoryDealGetInteger(TicketDeal,DEAL_ENTRY)==DEAL_ENTRY_IN)
                 {
                  Ticket=TicketDeal;

                  break;
                 }
           }
        }

      return(Ticket);
     }

   static double GetPositionCommission(void)
     {
      double Commission=::PositionGetDouble(POSITION_COMMISSION);

      // На случай, если POSITION_COMMISSION не работает
      if(Commission==0)
        {
         const ulong Ticket=MT4ORDERS::GetPositionDealIn();

         if(Ticket>0)
           {
            const double LotsIn=::HistoryDealGetDouble(Ticket,DEAL_VOLUME);

            if(LotsIn>0)
               Commission=::HistoryDealGetDouble(Ticket,DEAL_COMMISSION)*::PositionGetDouble(POSITION_VOLUME)/LotsIn;
           }
        }

      return(Commission);
     }
 

How about this... There is no POSITION_COMISSION property in the documentation, only DEAL_COMISSION in the transaction properties.

Thanks, I'll know another inaccuracy in the documentation.

 
Then how is the commission taken into account? It is not added to the profit of the position? Does it affect the balance immediately after the position is opened?
 
Dmitry Fedoseev:
Then how is the commission taken into account? It is not added to the profit of the position? Immediately after a trade to open a position, does it affect the balance?
Yes.
 
fxsaber:

The library will return the correct value when called

In the source code it's like this

Do you have the defines commented out at the end there, is that how it should be? One more thing. I will be making a video reel on my blog at YouTube translating from MQL4 to MQL5. Do you mind if I translate your library too? The link to kodobase, of course.

/*
#define OrderClose  MT4ORDERS::MT4OrderClose
#define OrderModify MT4ORDERS::MT4OrderModify // нельзя, например: CTrade::OrderModify
#define OrderDelete MT4ORDERS::MT4OrderDelete // нельзя, например: CTrade::OrderDelete

#define OrdersHistoryTotal MT4ORDERS::MT4OrdersHistoryTotal

#define OrderTicket      MT4ORDERS::MT4OrderTicket
#define OrderType        MT4ORDERS::MT4OrderType // нельзя, например: CHistoryOrderInfo::OrderType
#define OrderLots        MT4ORDERS::MT4OrderLots
#define OrderSymbol      MT4ORDERS::MT4OrderSymbol
#define OrderComment     MT4ORDERS::MT4OrderComment
#define OrderOpenPrice   MT4ORDERS::MT4OrderOpenPrice
#define OrderOpenTime    MT4ORDERS::MT4OrderOpenTime
#define OrderStopLoss    MT4ORDERS::MT4OrderStopLoss
#define OrderTakeProfit  MT4ORDERS::MT4OrderTakeProfit
#define OrderClosePrice  MT4ORDERS::MT4OrderClosePrice
#define OrderCloseTime   MT4ORDERS::MT4OrderCloseTime
#define OrderExpiration  MT4ORDERS::MT4OrderExpiration
#define OrderMagicNumber MT4ORDERS::MT4OrderMagicNumber
#define OrderProfit      MT4ORDERS::MT4OrderProfit
#define OrderCommission  MT4ORDERS::MT4OrderCommission
#define OrderSwap        MT4ORDERS::MT4OrderSwap
#define OrderPrint       MT4ORDERS::MT4OrderPrint
*/
 
Alexey Viktorov:

How about this... There is no POSITION_COMISSION property in documentation, only in DEAL_COMISSION transaction properties.

Thanks, I'll know another inaccuracy in the documentation.

And there is no such property in documentation, but it compiles ) Here is everything that is in the terminal's help.

POSITION_VOLUME

Position volume

double

POSITION_PRICE_OPEN

Position price

double

POSITION_SL

Stop loss level for open position

double

POSITION_TP

Take Profit level for open position

double

POSITION_PRICE_CURRENT

Current price for the symbol

double

POSITION_SWAP

Accumulated swap

double

POSITION_PROFIT

Current profit

double

 
Alexey Viktorov:
Look in the properties of the transaction. HistoryDealGetDouble(ticket, DEAL_COMMISSION);
So, the commission can be found out only after the position is closed? But it is taken at opening, at least on ECN accounts in alp and robot. This is not good.
Reason: