You are probably running this in the strategy tester using open prices only.
I had a look at the sample EA and it is quite a poor example
for(int i=1; i>=OrdersTotal(); i++) // Loop through orders if (OrderSelect(i-1,SELECT_BY_POS)==true) // If there is the next one
This loop is only effective of there is only 1 open order
if (Total==0 && Opn_B==true) // if (Total==0 && Opn_S==true) //
Total wasn't changed in the code after closing the opposite order, so a new order cannot be opened until the next tick when Total will equal 0
Try
if (OrdersTotal()==0 && Opn_B==true) // if (OrdersTotal()==0 && Opn_S==true) //
and it should open the new order in the same tick
GumRai,
Thank you very much for taking the time to give me a hand - Yes I had dismissed role of 'Total'. A newbie error...
What you are saying makes sense, I'll go and try it now.
Thanks again for your help, saved me a lot of figuring out!
Paddy.

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
Hi Guys,
First time poster, hope you might be able to help me with this one...
I have been working on a simple EA that will perform trading actions based on an indicator crossing point. My starting point was the first simple EA example in the MQL4 online book, found here https://book.mql4.com/samples/expert.
Essentially I have noticed that when my indicator crossover happens, as per the screenshot below, my 'Close' action completes at the end of that tick (in this case between 9:30 and 10:00). But I must wait for a new tick to open the opposite action, (in this case open sell. at 10:30). I would like to be able to close buy and open sell at 10:00. Should this be possible? I've been wondering whether my 'start' iteration might take too long...
I hope that I've used appropriate language to describe my problem! I am coming from back-testing my thesis in Matlab, now looking at what might happen in the real world.
Any help would be greatly appreciated, code is below (Copied from the book as a learning exercise). Thanks!