
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
Primarily something that I don't understand is how the backtest works with the account balance. In my code, every time a buy order is sent I use the "AccountInfoDouble(ACCOUNT_MARGIN_FREE)" function to obtain the free margin available at that moment and calculate the corresponding volume and thus avoid problems of lack of money or a large volume in the purchase. At the same time I make sure to close the order before opening another so that there are no open orders that could be taking part of the free margin. As a way of controlling, I print the current balance value, free margin, price, volume, etc. every time a purchase is made. And what I am seeing is that during the backtest the value of free margin, equity and balance are drastically decreased as if the test deliberately leveraged the order by 10 at a time where there are losses with high percentages, even when the tester options are not enabling leverage. What is worse, when running the same EA with different initial deposits, I see that from a certain value onwards the algorithm goes from making almost 60 trades as it should to making only 1. For example, if the balance is 4000 you make 60 trades but if the balance is 3000 you make only 1, this limit is around the value in currency of the maximum volume allowed by the broker but I am not sure if it is related to this.
I would like to know first why the backtest has this behavior and what things can be improved in the code to avoid it, that is, if there are hidden variables that cannot be seen or better ways to work with the available balance or if there are a number of internal variables that cannot be seen. come but they affect the behavior and therefore beyond the information in the account we have to work with them. For example, I have noticed that if I print the result of "ACCOUNT_MARGIN_FREE" I get a different value than funcionAccountInfoDouble(ACCOUNT_MARGIN_FREE), it is as if there were a free margin value different from what we see in the account, this makes me suspect that beyond the volume I put into the purchase there may be hidden leverage or other variables that are having unexpected effects on the test. I leave you the code: