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

 
Marbo:

Because I have a EUR account I changed it to:

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

  1. Is your broker using variable commission on accounts other than USD? Maybe there is fixed commission in EUR for EUR accounts?
  2. Does your broker return correct tick value on EUR account for the symbol you are testing?

 
Marbo: I tried something like this but I don't really understand what I am doing here...
In code (MT4): Risk depends on your initial stop loss, lot size, and the value of the pair.
  1. You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
  2. Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
  3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
              MODE_TICKVALUE is not reliable on non-fx instruments with many brokers.
  4. You must normalize lots properly and check against min and max.
  5. You must also check FreeMargin to avoid stop out
Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5=0.1 Lots maximum.
 

@Marcin Madrzak

My broker charges a fixed $7 per roundturn. They don't have other commissions for EUR accounts. I only see the commission in Euro on my account but it's just always the $7 commission converted into Euro. Therefore I am sure to pay $7 for every roundturn in all currency pairs.

I tested it on different forex-symbols and unfortunately the result was always way too high for my predefined risk.

Edit: You wrote slInPoints. Do you mean this as an example?

double entry = 1.2050;
double stoploss = 1.2020;
double slInPoints = MathAbs(entry-stoploss);


@whroeder1

In my first posting you can see that I use the DeltaPerLot which I saw in one of your codes years ago. So my problem is not to calculate the lotsize in general. My problem is to include the commission which is $7 per roundturn into the calculation. I have an entry and a stoploss. This I use to calculate the lotsize. And that works perfect. It's just about the commission. I don't know how to include it into the calculation. If I could convert it into pips/points, I could just add it to the MathAbs(OrderOpenPrice-OrderStopLoss). But exactly this is my problem.

 

@Marcin Madrzak

If you run this script, you can see that the lotsize is way too high.

- account balance = 1000
- risk = 1%
- stoploss = 30 pips

The lotsize-result is 1.61.

void OnStart()
  {
   double balance = 1000;
   double entry = 1.2050;
   double stoploss = 1.2020;
   double slInPoints = MathAbs(entry-stoploss);
   double lots=balance*0.01/(7/MarketInfo("EURUSD", MODE_BID)+slInPoints*MarketInfo(Symbol(),MODE_TICKVALUE));
   Alert(DoubleToString(lots, 2));
}
 
@Marbo

By SLInPoints I mean SL in points, not SL as price difference. I’m sure you know what is “point”. In your example it will be 300 points (I assume this is 5 digit symbol).
 
Marcin Madrzak:
@Marbo

By SLInPoints I mean SL in points, not SL as price difference. I’m sure you know what is “point”. In your example it will be 300 points (I assume this is 5 digit symbol).

Oh, sorry! I wasn’t sure about ‘points’. But now I know where the error could be. I just have to find out how to convert 0.0030 to 300 and to make sure that it works on 3 digit yen pairs too.

According to @whroeder1 I will include the DeltaPerLot function just to verify that I use the correct ticksize. 

 
Marbo:


@whroeder1

In my first posting you can see that I use the DeltaPerLot which I saw in one of your codes years ago. So my problem is not to calculate the lotsize in general. My problem is to include the commission which is $7 per roundturn into the calculation.

What part of "Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot)" was unclear?

 
whroeder1:

What part of "Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot)" was unclear?

Stupid me... I have overlooked it... Sorry! 

This calculation works perfect now. Thank you!

 
William Roeder #:

What part of "Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot)" was unclear?

Can i hire you to resolve a similar issue ? i want to add commission into my EA. 

Reason: