How can I convert the commission to pips/doubles to use it in my risk-management-code?

 

Hello forum,

I have my entry and my stop-loss and I want to calculate the lot size according to my risk-management. It works fine and this is how I do it:

double pipRisk = MathAbs(orderOpenPrice-orderStoploss);
double lotSize  = AccountBalance()*0.01 / pipRisk / (MarketInfo(_Symbol, MODE_TICKVALUE)/MarketInfo(_Symbol, MODE_TICKSIZE));
lotSize  = MathRound(lotSize/MarketInfo(_Symbol, MODE_LOTSTEP))*MarketInfo(_Symbol, MODE_LOTSTEP);

Now I want to include the commissions into this calculation. My broker charges $7 for a full roundturn. I wanted to convert the commission into pips and add them to the variable "pipRisk".

Because I have a Euro-based account I think I have to convert the commission into Euro first:

double commissionEURPerLot = 7/MarketInfo("EURUSD", MODE_BID);

But now I am lost... I have no idea how to include the commission into my risk-calculation. Can anyone help me?

 
Marbo:

Hello forum,

I have my entry and my stop-loss and I want to calculate the lot size according to my risk-management. It works fine and this is how I do it:

Now I want to include the commissions into this calculation. My broker charges $7 for a full roundturn. I wanted to convert the commission into pips and add them to the variable "pipRisk".

Because I have a Euro-based account I think I have to convert the commission into Euro first:

But now I am lost... I have no idea how to include the commission into my risk-calculation. Can anyone help me?

try OrderCommission()

 
Ahmet Metin Yilmaz:

try OrderCommission()

https://docs.mql4.com/trading/ordercommission

OrderCommission - Trade Functions - MQL4 Reference
OrderCommission - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderCommission - Trade Functions - MQL4 Reference
 

Hello Ahmet,

I can only use OrderCommission() if I have an existing order. But I need to calculate the lotsize including the commission before I place a trade.

I tried something like this but I don't really understand what I am doing here...

double commissionUSDPerLot = 7;
double commissionEURPerLot = commissionUSDPerLot/MarketInfo("EURUSD", MODE_BID);
double commissionPerLotInPips = (commissionEURPerLot/MarketInfo(_Symbol, MODE_TICKVALUE))*MathPow(10, -(_Digits-1));
 
How to get commission fee before open order?
How to get commission fee before open order?
  • 2014.06.09
  • www.mql5.com
Hi there, I'd like to know any MQL4/5 function to get commission fee before open order. Thanks in advance...
 

basicly if your broker commission is 7 ( round turn ) your commission will be equal to 0,7 spread per 0,01 lot

I think =) 

 
Ahmet Metin Yilmaz:

basicly if your broker commission is 7 ( round turn ) your commission will be equal to 0,7 spread per 0,01 lot

I think =) 

Imagine if you want to trade GBP/NZD and you have a EUR-account. A roundturn of 100,000 GBP/NZD costs $7. But how do you integrate the commission-costs in USD into GBP/NZD when you have a EUR-account?

I guess you have to convert the $7 into NZD first and then convert the NZD amount somehow to the spread.

I think this is really complex. Or maybe it's easy but I don't know how to do...?!

 
Marbo:

Imagine if you want to trade GBP/NZD and you have a EUR-account. A roundturn of 100,000 GBP/NZD costs $7. But how do you integrate the commission-costs in USD into GBP/NZD when you have a EUR-account?

I guess you have to convert the $7 into NZD first and then convert the NZD amount somehow to the spread.

I think this is really complex. Or maybe it's easy but I don't know how to do...?!


lots=AccountBalance()*(riskPercent/100.0)/(commisionInMoney+slInPoints*MarketInfo(Symbol(),MODE_TICKVALUE));
Given that your broker has properly set Tick value.
 
Marcin Madrzak:


Given that your broker has properly set Tick value.

What do you mean with commissionInMoney? Which amount and which currency? I only know the general commission which is $7 per roundturn.

 
Marbo:

What do you mean with commissionInMoney? Which amount and which currency? I only know the general commission which is $7 per roundturn.

Commission round turn / lot in account currency. In your case commissionInMoney = 7.0

 
Marcin Madrzak:

Commission round turn / lot in account currency. In your case commissionInMoney = 7.0

Because I have a EUR account I changed it to:

lots=AccountBalance()*0.01/(7/MarketInfo("EURUSD", MODE_BID)+slInPoints*MarketInfo(Symbol(),MODE_TICKVALUE));

But unfortunately that doesn't work correct. The calculated lotsize is too high for the 1% risk.

Reason: