Questions from Beginners MQL5 MT5 MetaTrader 5 - page 658

 
Vladimir Karputov:
Let's check it out with a simple advisor...
There's no need to check it. The logic is the same as in MQL4: Profit, Commission and Swap are separate entities.
 
fxsaber:
There's no need to check. The logic is the same as in MQL4: Profit, Commission and Swap are separate entities.
Please show me the code, the direct code in mql5 and preferably without any perversions
 
Vladimir Karputov:
Now let's check with a simple EA...

Vladimir, the point is that on the four I do this:

// считаем комиссии и свопы в пипки
     swap=OrderSwap();
     commission=OrderCommission();
     if(swap+commission<0.0) {
      costs=NormalizeDouble(MathAbs(((swap+commission)/(SymbolInfoDouble(_symbol,SYMBOL_TRADE_TICK_VALUE)*ol))*_Point),_Digits);
     } else {
      costs=0.0;
     }
// прибавляем количество пипок
if(((Bid-(br+costs+((BreakevenStep*_Point)*D)))>=op) && typ==0)
{
  OrderModify(...);
}

How do you do it in five?

 
Vitaly Muzichenko:

Vladimir, the point is that on the four I do this:

// считаем комиссии и свопы в пипки
     swap=OrderSwap();
     commission=OrderCommission();
     if(swap+commission<0.0) {
      costs=NormalizeDouble(MathAbs(((swap+commission)/(SymbolInfoDouble(_symbol,SYMBOL_TRADE_TICK_VALUE)*ol))*_Point),_Digits);
     } else {
      costs=0.0;
     }
// прибавляем количество пипок
if(((Bid-(br+costs+((BreakevenStep*_Point)*D)))>=op) && typ==0)
{
  OrderModify(...);
}

How do you do it in five?

Add in the beginning.
#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006
Either rewrite the whole thing heavily.
 
Vitaly Muzichenko:
Please show it by code, here's a direct code in mql5 and preferably without perversions.
This is almost impossible! Pulled from SB, direct code
//+------------------------------------------------------------------+
//| Get the property value "POSITION_COMMISSION"                     |
//+------------------------------------------------------------------+
double CPositionInfo::Commission(void) const
  {
   return(PositionGetDouble(POSITION_COMMISSION));
  }
//+------------------------------------------------------------------+
//| Get the property value "POSITION_SWAP"                           |
//+------------------------------------------------------------------+
double CPositionInfo::Swap(void) const
  {
   return(PositionGetDouble(POSITION_SWAP));
  }
//+------------------------------------------------------------------+
//| Get the property value "POSITION_PROFIT"                         |
//+------------------------------------------------------------------+
double CPositionInfo::Profit(void) const
  {
   return(PositionGetDouble(POSITION_PROFIT));
  }
 
fxsaber:
It's almost impossible! Pulled from SB, direct code
//+------------------------------------------------------------------+
//| Get the property value "POSITION_COMMISSION"                     |
//+------------------------------------------------------------------+
double CPositionInfo::Commission(void) const
  {
   return(PositionGetDouble(POSITION_COMMISSION));
  }
//+------------------------------------------------------------------+
//| Get the property value "POSITION_SWAP"                           |
//+------------------------------------------------------------------+
double CPositionInfo::Swap(void) const
  {
   return(PositionGetDouble(POSITION_SWAP));
  }
//+------------------------------------------------------------------+
//| Get the property value "POSITION_PROFIT"                         |
//+------------------------------------------------------------------+
Forgot to put in the documentation, but does this"POSITION_COMMISSION" work?
 
new-rena:
Forgot to put it in the documentation, but does this"POSITION_COMMISSION" work?
You asked for it without perversions. And if with them, then

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

fxsaber, 2016.07.19 12:40

POSITION_COMMISSION property in the tester (RoboForexEU-MetaTrader 5) always returns zero commission.

//+------------------------------------------------------------------+
//| Get the property value "POSITION_COMMISSION"                     |
//+------------------------------------------------------------------+
double CPositionInfo::Commission(void) const
  {
   return(PositionGetDouble(POSITION_COMMISSION));
  }

Also POSITION_COMMISSION (== 8) is missing in help and meta-editor (highlighting), but is familiar to compiler. The position commission is not difficult to determine using another (working) method. POSITION_COMMISSION property - a rudiment?


That's why it's like this
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);
}
Or

Forum on trading, automated trading systems and strategy testing

Questions from beginners

fxsaber, 2016.10.29 16:23

I'm not imposing the MT4Orders library. But maybe it would be easier to just call the good old OrderCommission?

Still works not only on hedge accounts but also on net accounts.

 
Vladimir Karputov:
Let's check it now with a simple Expert Advisor...

Here:POSITION_PROFIT shows the profit of the position

POSITION_PROFIT

. It does not take into account swap and the like.

 
Vitaly Muzichenko:

Vladimir, the point is that on the four I do this:

// считаем комиссии и свопы в пипки
     swap=OrderSwap();
     commission=OrderCommission();
     if(swap+commission<0.0) {
      costs=NormalizeDouble(MathAbs(((swap+commission)/(SymbolInfoDouble(_symbol,SYMBOL_TRADE_TICK_VALUE)*ol))*_Point),_Digits);
     } else {
      costs=0.0;
     }
// прибавляем количество пипок
if(((Bid-(br+costs+((BreakevenStep*_Point)*D)))>=op) && typ==0)
{
  OrderModify(...);
}

How do I do it in five?

The commission is so unpredictable that it can only be determined in a closed trade. For an open position, you can only find out the current profit (which takes into account neither the impact of swap nor the impact of commissions) and swap. Here is the code:

Put a breakpoint on the line " m_trade.PositionClose(Symbol();" and run the test on history. When the tester stops at the breakpoint, compare the figures in the Profit and Swap columns with the figures that are unwritten in the tester log.

Files:
3.mq5  5 kb
 
Vladimir Karputov:

Here:POSITION_PROFIT shows the profit of the position

. It does not take into account swap and the like.

Ok. We got it.

The solution of fxsaber is good, I have applied it.

Basically, I transferred my MQL4 program to MQL5 almost without any problems.

The details are given above.

Thank you very much!

Reason: