**arcull:**

commission which I don't yet know where to get from.

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Вопросы от начинающих MQL5 MT5 MetaTrader 5

fxsaber, 2016.10.29 17:09

{

double Commission = ::PositionGetDouble(POSITION_COMMISSION);

// На случай, если POSITION_COMMISSION не работает

if (Commission == 0)

{

const ulong Ticket = 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);

}

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Как узнать размер комиссии не открывая позицию по инструменту?

fxsaber, 2016.11.08 20:30

{

ulong Ticket = 0;

if ((PositionIdentifier == 0) ? ::HistorySelectByPosition(::PositionGetInteger(POSITION_IDENTIFIER)) : ::HistorySelectByPosition(PositionIdentifier))

{

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);

}

Hi there, the title says it all..In my EA (MT5) when the robot is closing position I want to check the profit of current position properly. I know there is a function "PositionGetDouble" but am not sure about how to use it properly. On my ECN account I pay commisions for each position opening cca. $2/lot + each position closing, totaling $4/lot. Besides that there may be positive or negative swap calculated.

So my question is how can I calculate my net profit for a certain position?

double x = PositionGetDouble(POSITION_PROFIT);

double y = PositionGetDouble(POSITION_SWAP);

Is variable "x" my net profit, or should I subtract variable "y" and commission which I don't yet know where to get from.

Please suggest, much thanks in advance for your help.