In the attached EA, there are only 3 lines containing KL:
input double KL = 2; // увеличение лота
How come when KL is given a value like 1, 2 or 3, the EA works fine; but if KL is given a value like 1.3, 1.5, etc. the EA become abnormal? What can I change so that the EA works still with KL set to 1.3, 1.5, etc?
Many thanks for your enlightenment.
It's because the lots function fails to return the correctly rounded value. It should instead do this.
double step = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
return step * floor(lot / step);
Dear Expert Nicholishen,
Thank you so much for your advice! I will put your correction lines into the EA and report the result soon!
Dear Mr. Nicholishen,
I tested your correction.
When I set KL to 1.5, I expect
position 1 lot: 0.01
position 2 lot: 0.02 (0.01x1.5)
position 3 lot: 0.02 (0.02x1.5)
position 4 lot: 0.03 (0.02x1.5)
position 5 lot: 0.05 (0.03x1.5)
position 6 lot: 0.08 (0.05x1.5)
position 7 lot: 0.11 (0.08x1.5)
Your correction makes all position lots to be 0.01. The lots do not increase by KL. Could you kindly further advise me?
Thank you for your advice. I am no programmer and I don't know how to turn your advice to mt5 language to solve my problem. Could you please advise me the way nicholishen does?
That's because the floor function in this formula rounds down to the nearest lot-step. Rounding down to step ensures that you will not exceed your calculated risk. This is only really an issue when working with micro lots... if you want to round to the nearest lot-step change floor to round.
Thanks for pointing out the ways.
Very grateful to you for your guidance! After I change "floor" in your lines to "round", the EA behaves as expected now.
Deeply appreciate your teaching and helping!