Hi,
Thanks for the help. I'm aware that the margin will increase. But it was weird that the initial margin was very different from times to times. Example: I have 95000 USD free in a demo account. Since i'm trading 22% of it, I use 20900 USD as margin for a long position, which corresponds to X lots. A day later, the EA reverses the position. It closes the long position with something around 10 USD profit only and opens a short position of X lots, but this time, something around 41800USD are used as margin. In both trades a pip had the same value but the margin locked for the trade was almost two times bigger. Have you seen this problem before?
![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
Greetings,
I was trying to program an EA that moves 22% of my free margin for every trade it opens. Only one position is open at a time and the only positions opened are those from the EA.
The code I used for finding out the size of the trade was this one:
And the this function gets called right before I open a new poisiton. For example:
The problem is: Most of the times the locked margin is just what i expected (22%). But there are times that the locked margin is almost the double of what I expected. Any ideas of why it happens? My bet is there is something wrong with the timing of the communication with the server, but I don't know what it is.