fifo script

 
I have an ea that opens too many buys or sells on the same currency pair. I cannot find any script online that will prevent metatrader from opening a new order when for example their is already a buy on the pair or a sell on the pair. i want to prevent it from opening 2 buys or sells, like when one buy or sell is going wait for it to finish.
Reason: