Let’s look at how to determine a lot size using the account balance in this video, as well as how to round the result up or down to fit. So let’s look at how to use MQL4 to accomplish that. Please use the F4 key or click this button in MetaTrader to do that. The MetaEditor should then appear. In this case, we choose File, New Expert Advisor from template, and then provide a name. I’ve previously completed this. Simple Lot Size Rounding is the name of my file, which is already pre-programmed. Ontick will be our first function to deal with. We want to first determine the account balance there. The position size is calculated depending on the account balance using the Account Info Double, Account Balance function. In this instance, we divide the gross balance value by 100,000. Additionally, we construct two variables—one rounded up and one rounded down—for the rounded numbers. With the aid of the corresponding function, which we ourselves program, we can calculate that.
The determined lot size and the value for the decimal rounding are passed as parameters to the first function, which is called Round up, and the second, Round down. This should be rounded to the nearest whole number. We can output the final results in a more structured manner by using Normalize Double. Despite the fact that we have given two decimal places here, we can see that the first digit of our results is truncated. We then display the entire thing onto the chart using the Comment function. On to the actual functions now. We pass our input value to round up. That is both our rounding value and the position size that we previously passed. For the decimal places, let’s add the second parameter. We multiply the rounded value by the function’s output in order to obtain the result. Once you press F1, you may access the help and notice that an integer value has been returned. We also pass the input value and the rounded value to the MathCeil function for further calculation. Then we return our outcome to the function using Return. Similar principles apply to the second function for rounding the value.
But in this case, MathFloor is used rather than MathCeil. And in this case, we also return the result to our main function. And so, for a 0.25 lot determined lot size, this yields the rounded up value of 0.3 and the rounded down value of 0.2. You can alter this in accordance with the type of account you have and so pass the proper values so that a position can also be opened correctly. Not all account types can deal with microlot sizes that are staggered to the second decimal place. By the way, another premium customer had suggested this video topic. Additionally, if you’re a premium customer and have an idea for a video like this, please email me. If not, the premium course is available on our website. Additionally, you learned how to round lot sizes up or down with ease in this video so that they meet your account type. And you wrote these few MQL4 lines here to program that yourself.