Is this the correct code for calculating a lot size?

 

Is this the correct code for calculating a lot size?

double Lots = (AccountEquity() * RiskPercentage * 0.01 ) / ( MarketInfo( Symbol(), MODE_LOTSIZE ) / AccountLeverage() );

With this code I get different results between the strategy tester and a live demo account.

When running with an opening balance of $10000, the tester with a risk of 0.5% gives lots of 0.10 but under the demo account the lots end up being 0.05.

I’ve printed the lot size returned from MODE_LOTSIZE and the leverage returned from AccountLeverage() and they are both the same between the tester and the demo account.

Does anybody know what the difference could be?

Regards

Terry

 
  • The maximal volume of the transaction - 5 lots
  • The maximal total amount of the open and pending orders - 3
  • So, an expert can open maximum 15 lots position, using 3 times ordersend(5 lots)?

    Is this correct?

     
    Yes, it is correct. See https://www.mql5.com/en/users/Rich
     
    Rosh:
    Yes, it is correct. See https://www.mql5.com/en/users/Rich


    Thanks, now that I know my calculation is correct can anybody explain the difference between the strategy tester and a live demo account? You would think that when the opening balance, leverage and lot size are the same you would get the same results. What’s even stranger is that doubling the risk on the demo account doesn’t double the lot size. With a risk of 0.5% I get a lots size of 0.05 (the tester gives 0.1 lots), but when I double it to 1% I get 0.7 lots. Can anyone explain?

    Regards

    Terry

     

    What kind of money? EUR or GBP JPY......?

    maybe they are different AccountLeverage()

     
    DxdCn:

    What kind of money? EUR or GBP JPY......?

    maybe they are different AccountLeverage()


    EURUSD

    I've printed the leverage to the screen and there the same (200); and the lot size is the also the same(100000).

     
    Print all variables and then check them.
     
    DxdCn:
    Print all variables and then check them.


    That's what I'm doing at the moment. Just waiting for it to place a trade.

     
    Zaphod:
    DxdCn:
    Print all variables and then check them.


    That's what I'm doing at the moment. Just waiting for it to place a trade.


    Curiouser and curiouser after putting the code in to print the variables it now works.

    I think it might be a code generation error. I suspect the compiler is not generating and FWAIT instruction somewhere.

    I think I’ll just leave the journal print in the code.

     

    use codes: and then publish them here for other one to check them!

    --------------------------------------------

    double Lots = (AccountEquity() * RiskPercentage * 0.01 ) / ( MarketInfo( Symbol(), MODE_LOTSIZE ) / AccountLeverage() );

    Print("lot=",Lots , "Aeq=",AccountEquity()," ris=", RiskPercentage ," lt=", MarketInfo( Symbol(), MODE_LOTSIZE ) ," lev=",AccountLeverage() );

    --------------------------------------------------

    I use such code to get lots:

    lot=NormalizeDouble(AccountBalance()*RiskPercentage /MarketInfo(Symbol(), MODE_MARGINREQUIRED), 1);

    Reason: