
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
You still have Counter--
See GumRai's comment https://www.mql5.com/en/forum/151167/page2#954622
Thanks for your posts.
I used Open instead of Time because once the Open of a bar occurs it is fixed for ever and it will never change. It isn't looking for two consecutive bars - it is the same bar and is asking whether the open of the current bar during which the tick has just taken place is the same as the Open value stored in ThisBarOpen. In addition, I would have thought Open would be more straightforward than Time because it is a simple data lookup whereas Time might have to reference something else and possibly do some sort of calculation.
Re Counter--; I didn't change that because another EA wouldn't be able to close an order because the code checks that both the MagicNumber and Symbol() are the same first.
I certainly take the point about a power cut wiping out the contents of BuyTicket but that hasn't happened during my tests and my code is still running very slowly. Therefore I can't see how that could be the cause either.
My main question at the moment is why it took such a long time to remove the EAs from the windows on the terminal which had open positions and no time at all to remove them from the terminal which had no open positions. Coincidence maybe - but all four windows?
I don't know that this is really relevent to your issue but you limit your trading to 1 buy, 1 sell per EA so why do all this ?
You already have your ticket number here:
if you make that a static int you can close your order explicitly by that ticket number without trawling through the orders pool for it.
Thanks for your posts.
Re Counter--; I didn't change that because another EA wouldn't be able to close an order because the code checks that both the MagicNumber and Symbol() are the same first.
My main question at the moment is why it took such a long time to remove the EAs from the windows on the terminal which had open positions and no time at all to remove them from the terminal which had no open positions. Coincidence maybe - but all four windows?
Do you understand how loops work?
Say you have 3 orders open
At first run through, counter==0, so the order with the index 0 will be selected
At the end of the loop you decrease counter by 1, so counter== -1.
Before the loop executes again, counter is increased by 1 as part of the for function. So counter ==0
So the next run through the loop counter==0 again!! and so on and so on.
You are stuck in an endless loop that just keeps checking order index 0
The only way that it will stop is if there are no open orders because then OrdersTotal - 1 will be -1 and 0 is not <= -1