EA sends orders every seconds

Good morning you all,
I wrote an Expert Advisor that opens order when all the condition I put meets. Analyzing that, I noticed a problem. When the condition meets it opens order, but if the order do not open because the free margin of my account it's too low (the reason of that is because I have others position opens) the EA try to open the order every seconds untill it open the order successfully.

This is a problem because when it open the order successfully, it's already passed 2 hours or more since the condition meets.

I want to modify it, if the condition meets and the ea fails to open order, it doesn't try to open it more times.

I need it works like this: if the condition meets and it open order successfully it's all good and if it fails it doesn't need to try to open it every seconds. Can someone please tell me how can I modify it?

William Roeder
William Roeder  

You are looking at a signal. Act on a change of signal.
          MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12