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

To add comments, please log in or register
Marbo
367
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:

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?

Ahmet Metin Yilmaz
3436
Ahmet Metin Yilmaz  
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
3436
Ahmet Metin Yilmaz  
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
Marbo
367
Marbo  

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));
Ahmet Metin Yilmaz
3436
Ahmet Metin Yilmaz  
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...
Ahmet Metin Yilmaz
3436
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 =) 

Marbo
367
Marbo  
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...?!

Marcin Madrzak
507
Marcin Madrzak  
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.
Marbo
367
Marbo  
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.

Marcin Madrzak
507
Marcin Madrzak  
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

Marbo
367
Marbo  
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.

12
To add comments, please log in or register