Your "OpenOrder" needs to be a static variable. Static variables and Global [ scope ] variables saves their value between ticks. local variables do-not. The problem is you'll have to remember to re-set these variables back to false when there's no-longer an order. Most people would just count the number of open-orders.
Some example below. The function version would be considered the most reliable.
/*Example using Static Variables.*/ void start(){ static bool OpenOrder; //static variable Inside the start function if(OpenOrder==false){ if(OrderSend(...)>-1){OpenOrder=true;} } if(OpenOrder==true){ if(OrderClose(...)){OpenOrder=false;} } } /*Example using Global [scope] Variables.*/ bool OpenOrder; //Global variable Outside the start function void start(){ if(OpenOrder==false){ if(OrderSend(...)>-1){OpenOrder=true;} } if(OpenOrder==true){ if(OrderClose(...)==true){OpenOrder=false;} } } /*Example using function to count your orders.*/ void start(){ if(MyOrderCount()==0){OrderSend(...);} if(MyOrderCount() >0){OrderClose(...);} }
Your "OpenOrder" needs to be a static variable. Static variables and Global [ scope ] variables saves their value between ticks. local variables do-not. The problem is you'll have to remember to re-set these variables back to false then there's no-longer an order. Most people would just count the number of open-orders.
Some example below. The function version would be considered the most reliable.
Thank you! That saved me. I will try coding the order counting function in and posting it here.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
I'm new to MQL4 and have been working on my very first EA, which is Ichimoku based. The robot seems to open the trade at the proper signal, but then keeps opening trades all the way down the bar. The trades are not closed until the very end of the testing period.
I have tried setting a boolean operator (OpenOrder) to make the EA trade only when OpenOrder==False, but for the life of me cannot figure out what is going wrong and where. I have a feeling I'm missing something obvious.
As for closing the order, I'm not exactly sure what's going wrong.
If anyone could nudge me a little closer to parsimony I would be eternally grateful.