Minimum lot size

 

I have this money managment code that works fine when minimum lots aloud by broker is 0.01. but I can't figure out how to set it to minimum lot size = 10.0 .I know I have to change the last diget of the code from 2 with two diget after the decimal to another number to make it to 10.0  but I don't now what number.


Can someone please help?


double Lots = NormalizeDouble(AccountInfoDouble(ACCOUNT_BALANCE)*Risk/HitNumber/(SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE)),2);

 

Forum on trading, automated trading systems and testing trading strategies

Market Registration of EA Unable to Validate

Fernando Carreiro, 2022.08.30 14:20

For your screenshot with an Error 131 and it also has a link on "How to fix it". So follow up on it and fix your EA accordingly.

In regards to volume, you have to check the contract specification of the symbol and limit your volume to the minimum, maximum and step that is allowed for the symbol.

// Variables for symbol volume conditions
   double
      dbLotsMinimum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN  ),
      dbLotsMaximum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX  ),
      dbLotsStep    = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP );
       
// Adjust volume for allowable conditions
   dbLots = fmin(  dbLotsMaximum,                           // Prevent too greater volume
            fmax(  dbLotsMinimum,                           // Prevent too smaller volume
            round( dbLots / dbLotsStep ) * dbLotsStep ) );  // Align to step value
 

Forum on trading, automated trading systems and testing trading strategies

SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) sometimes zero

Fernando Carreiro, 2022.08.23 17:41

You can! These are the steps I take. I supply the function with a lot size equal to the “Max Lot Size” allowed for the symbol in question, then calculate the ratio needed to achieve the fractional risk that I wish to apply, to get the correct volume for the order. I then align that with the “Lot Step” and finally check it against both the maximum and minimum allowed lots for the symbol.

The reason I use the “maximum” lots instead of just “1.0” lots as a reference value is because there is no guarantee that the value of 1.0 is within the minimum and maximum values allowed. Given that using 1.0, or the maximum, gives equivalent results anyway (by using the ratio method), I choose to use the “max lots” as the reference point which also offers the most precision for the calculation.

Something like this ...

// This code will not compile. It is only a example reference

if( OrderCalcProfit( eOrderType, _Symbol, dbLotsMax, dbPriceOpen, dbPriceStopLoss, dbProfit ) )
{
   dbOrderLots = fmin( fmax( round( dbRiskMax * dbLotsMax / ( -dbProfit * dbLotsStep ) )
               * dbLotsStep, dbLotsMin ), dbLotsMax ); 
      
   // the rest of the code ...
};
 
That dosen't answer my question, the number 2 at the end of the code states that the minimum lot size that can be used is 0.01 lots. A number 1 at the end states that the minimum lot size is 0.1. A number 0 states that minimum lot size aloud is 1.0. That is where I get stuck, what number do I use to have a minimum lot size of 10.0 ?
 
Ian Macmillan #: That dosen't answer my question, the number 2 at the end of the code states that the minimum lot size that can be used is 0.01 lots. A number 1 at the end states that the minimum lot size is 0.1. A number 0 states that minimum lot size aloud is 1.0. That is where I get stuck, what number do I use to have a minimum lot size of 10.0 ?

Yes, I did answer your question. Unfortunately you have made incorrect assumptions. Do you see me use NormaliseDouble() in my code?

The answer is—no! That is because using NormaliseDouble() is not the correct way to set the volume. I have shown you the correct way in my first post #1.

In my second post #2, I have shown you the correct way to calculate the volume based on the risk of the stop loss.

Reason: