![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
If you want a stop-loss of the size of one ATR with 1% risk, then...
Hello, i want to let you know that i did find often problem with your lotsize calculation function in the way how you have build it, but the error is not from technical you can say, it is something about zero calcuate error, but the complete EA does stop to work if this happen, i have slove it with one additional if statement, but i have the feeling that to often this statement is true and then no calculations are done, take a look at the following code then you maybe understand better what i mean:
Maybe you have a idea how to optimize it to make some calculations also if some variables have zero value, because currently it looks like to often some of the variables have zero and then no risk lotsize is calculated, i can not really say also which of this variables have often zero value, i find it also little bit complicate how you define your variables writine just one double constructor and then with komma all other values, it would be more usefull to save every value in his own double and then after that you can write a if statement to see which is zero and then create a Alert that is more useful for debugin.
This code is incorrect in 2 aspects regardless of the source of origin
First is explained
here =1/1=> https://www.mql5.com/en/forum/229850/page3#comment_52736349
and
here =1/2=> https://www.mql5.com/en/forum/112782#comment_3091472
Second is explained
here =2/1=> https://www.mql5.com/en/forum/112782#comment_3091475
and
here =2/2=> https://www.mql5.com/en/forum/112782#comment_3091476
Correct code sample
This code is incorrect in 2 aspects regardless of the source of origin
First is explained
here =1/1=> https://www.mql5.com/en/forum/229850/page3#comment_52736349
and
here =1/2=> https://www.mql5.com/en/forum/112782#comment_3091472
Second is explained
here =2/1=> https://www.mql5.com/en/forum/112782#comment_3091475
and
here =2/2=> https://www.mql5.com/en/forum/112782#comment_3091476
Correct code sample
thank you for your code, but the other function which i get from Fernando is working with stoploss your function looks like working with other technic. His function is also calculation correctly, but during trading and using that functions i have see sometimes the error caluate by zero and that have make the EA stop working, it is happening because of the variables they have sometimes no value maybe if the metatrader have not open a chart for that and terminal have no data