How about doing a search on MQL5 website? ... https://www.mql5.com/en/docs/standardlibrary/tradeclasses/cpositioninfo/cpositioninfocommission
If you don't like using OOP and the Trading Class, then use "POSITION_COMMISSION" with PositionGetDouble().
If you don't like using OOP and the Trading Class, then use "POSITION_COMMISSION" with PositionGetDouble().
You can't get POSITION_COMMISSION through PositionGetDouble().
How about doing a search on MQL5 website? ... https://www.mql5.com/en/docs/standardlibrary/tradeclasses/cpositioninfo/cpositioninfocommission
This does not work
//+------------------------------------------------------------------+ //| Test.mq5 | //| Copyright 2021, Simón Del Vecchio | //| https://www.mql5.com/es/users/simondelvecchio | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, Simón Del Vecchio" #property link "https://www.mql5.com/es/users/simondelvecchio" #property version "1.00" #include <Trade\Trade.mqh> #include <Trade\PositionInfo.mqh> CTrade Trade; CPositionInfo Position; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { Trade.Buy(0.01, NULL, 0, 0, 0, "Test_1"); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { //The comment works fine but the commission doesn't Position.SelectByIndex(0); Comment("Comment: ", Position.Comment(), " ", "Commission: ", Position.Commission()); } //+------------------------------------------------------------------+
This does not work
it is DEAL_COMMISSION
This does not work
This code works correctly if there is commission in the last opened order.
- 2018.09.05
- www.mql5.com
Function that returns the commission of the position
//+------------------------------------------------------------------+ //| Receives the position ticket and returns the commission | //+------------------------------------------------------------------+ double Comision(ulong TicketPos) { HistorySelect(iTime(NULL, PERIOD_D1, 7), TimeCurrent()); for(int i = 0; i < HistoryDealsTotal(); i++) { ulong TicketDeal = HistoryDealGetTicket(i); if(TicketPos == HistoryDealGetInteger(TicketDeal, DEAL_POSITION_ID)) { return(HistoryDealGetDouble(TicketDeal, DEAL_COMMISSION)); } } return(0); }
Sorry, my fault! Use "DEAL_COMMISSION" with "HistoryDealGetDouble(deal_ticket, DEAL_COMMISSION)";
This does not work
This code works correctly if there is commission in the last opened order.
Tried through this lines and I'm still getting wrong values:
for(int j=0;j<PositionsTotal();j++){ ulong jTicket=PositionGetTicket(j); if(PositionGetString(POSITION_SYMBOL)==SName){ double PV=PositionGetDouble(POSITION_VOLUME); double Swap=PositionGetDouble(POSITION_SWAP); double Com=HistoryDealGetDouble(jTicket,DEAL_COMMISSION); if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){ if(FirstOrderTP==true||LongPos>1){ double Breakeven=NormalizeDouble(LongBEF/PV++,SDigits); Swap++;if(Swap>0){Print("Positions: ",LongPos,", SwapLong: ",Swap);} Com++;if(Com>0){Print("Long positions: ",LongPos,", Commission: ",Com);} } if(Martingale>0){ } } if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL){ if(FirstOrderTP==true||ShortPos>1){ double Breakeven=NormalizeDouble(ShortBEF/PV++,SDigits); Swap++;if(Swap>0){Print("Positions: ",ShortPos,", SwapLong: ",Swap);} Com++;if(Com>0){Print("Short positions: ",ShortPos,", Commission: ",Com);} } if(Martingale>0){ } } //if(StopLoss){CloseFIFO;} } }
2021.08.18 09:49:27.787 Core 1 2016.12.19 12:02:00 Positions: 2, SwapLong: 1.0
2021.08.18 09:49:27.787 Core 1 2016.12.19 12:02:00 Long positions: 2, Commission: 1.0
2021.08.18 09:49:27.787 Core 1 2016.12.19 12:02:20 Positions: 3, SwapLong: 1.0
2021.08.18 09:49:27.787 Core 1 2016.12.19 12:02:20 Long positions: 3, Commission: 1.0
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use