Limit the number of trades after one trade out of two has been closed

 

I am a beginner in coding. I can make two function to open two trades. However, I want to make it so that first trade is open, then a second trade would come in. And if the second trade is closed while the first trade is still open, it would not open a second trade again until the first trade has been closed. 

Are there anyway of making this happen? It now just keep closing and open a second trade again and again.

Help.....