I know I should use " DEAL_COMMISSION
" and " DEAL_FEE ", but i don't know how.
I can't find any relationship between DEAL and own POSITION
note: these positions are open (no in history)
I'm thankful of your answers.
In a cycle, go around all positions and summarize profit, swap and commission:
//+------------------------------------------------------------------+//| Profit all positions |//+------------------------------------------------------------------+double ProfitAllPositions(void)
{
double profit=0.0;
for(int i=PositionsTotal()-1; i>=0; i--)
if(m_position.SelectByIndex(i)) // selects the position by index for further access to its propertiesif(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==InpMagic)
profit+=m_position.Commission()+m_position.Swap()+m_position.Profit();
//---return(profit);
}
I know I should use "DEAL_COMMISSION"
and "DEAL_FEE", but i don't know how.
I can't find any relationship between DEAL and own POSITION
note: these positions are open (no in history)
I'm thankful of your answers.
I
found answer of my question in MT5.
Each
closed position, has 2 deal and 1 opposite position.
commission
is calculated in deals. then you need to have deals of each position by POSITION_IDENTIFIER
POSITION_IDENTIFIER
Position
identifier is a unique number assigned to each re-opened position. It does not change throughout its life cycle and
corresponds to the ticket of an order used to open a position.
Position
identifier is specified in each order (ORDER_POSITION_ID) and deal (DEAL_POSITION_ID) used to open, modify, or
close it. Use this property to search for orders and deals related to the position.
When
reversing a position in netting mode (using a single in/out trade), POSITION_IDENTIFIER does not change. However,
POSITION_TICKET is replaced with the ticket of the order that led to the reversal. Position reversal is not provided
in hedging mode.
long
double POSITIONS_TOTAL_PROFIT()
{
double Total_Profit=0;
double deal_commission=0;
double deal_fee=0;
double deal_profit=0;
int total=PositionsTotal();
for(int i=0; i<total; i++)
{
ulong position_ticket=PositionGetTicket(i); // ticket of the positionulong magic=PositionGetInteger(POSITION_MAGIC); // MagicNumber of the positionstring comment=PositionGetString(POSITION_COMMENT); // position commentlong position_ID=PositionGetInteger(POSITION_IDENTIFIER); // Identifier of the positionif(magic==EXPERT_MAGIC || comment==IntegerToString(EXPERT_MAGIC))
{
HistorySelect(0,TimeCurrent());
int deals=HistoryOrdersTotal();
for(int j=deals-1; j>=0; j--)
{
ulong deal_ticket=HistoryDealGetTicket(j);
if(HistoryDealGetInteger(deal_ticket,DEAL_POSITION_ID) == position_ID)
{
deal_profit=HistoryDealGetDouble(deal_ticket, DEAL_PROFIT);
deal_commission=HistoryDealGetDouble(deal_ticket, DEAL_COMMISSION)*2;
deal_fee=HistoryDealGetDouble(deal_ticket, DEAL_FEE);
break;
}
}
Total_Profit += PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP) + deal_profit + deal_commission + deal_fee;
}
}
return(Total_Profit);
}
Each
closed position, has 2 deal and 1 opposite position.
when
position is open yet, it has just 1 deal with half commission. for calculate total commision of a open position, you need to multiply 2
Position ticket. Unique number assigned to each newly opened position. It usually matches the ticket of an order used to open the position except when the ticket is changed as a result of service operations on the server, for example, when charging swaps with position re-opening. To find an order used to open a position, apply the...
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I have 40 open positions now.
10 positions has same magic number.
I want calculate sum profit of these 10 positions; if was more than 70$, then i want close all 10 positions.
It was simple in MT4
But in MT5, it's complicating.
I tried this:
Total_Profit = POSITION_PROFIT + POSITION_COMMISSION + POSITION_SWAP + POSITION_FEE
I can't get POSITION_COMMISSION and POSITION_FEE
I know I should use " DEAL_COMMISSION " and " DEAL_FEE ", but i don't know how.
I can't find any relationship between DEAL and own POSITION
note: these positions are open (no in history)
I'm thankful of your answers.
In a cycle, go around all positions and summarize profit, swap and commission:
In a cycle, go around all positions and summarize profit, swap and commission:
Thank you very much man, for your quick answer.
I have 40 open positions now.
10 positions has same magic number.
I want calculate sum profit of these 10 positions; if was more than 70$, then i want close all 10 positions.
It was simple in MT4
But in MT5, it's complicating.
I tried this:
Total_Profit = POSITION_PROFIT+ POSITION_COMMISSION + POSITION_SWAP+ POSITION_FEE
I can't get POSITION_COMMISSION and POSITION_FEE
I know I should use "DEAL_COMMISSION" and "DEAL_FEE", but i don't know how.
I can't find any relationship between DEAL and own POSITION
note: these positions are open (no in history)
I'm thankful of your answers.
I found answer of my question in MT5.
Each closed position, has 2 deal and 1 opposite position.
commission is calculated in deals. then you need to have deals of each position by POSITION_IDENTIFIER
POSITION_IDENTIFIER
Position identifier is a unique number assigned to each re-opened position. It does not change throughout its life cycle and corresponds to the ticket of an order used to open a position.
Position identifier is specified in each order (ORDER_POSITION_ID) and deal (DEAL_POSITION_ID) used to open, modify, or close it. Use this property to search for orders and deals related to the position.
When reversing a position in netting mode (using a single in/out trade), POSITION_IDENTIFIER does not change. However, POSITION_TICKET is replaced with the ticket of the order that led to the reversal. Position reversal is not provided in hedging mode.
long
Each closed position, has 2 deal and 1 opposite position.
when position is open yet, it has just 1 deal with half commission. for calculate total commision of a open position, you need to multiply 2
Good Luck
This code is better