how to avoid multiple orders?

 
I have one open position and one pending position ... I have enough margin but I dont want pending position to open when I already have one open position running.. I want to use buy stop or sell stop but I dont want to run two orders at same time even when I have enough margin... can you tell me how to disable multiple trading? 
 
Yanan Nara:
I have one open position and one pending position ... I have enough margin but I dont want pending position to open when I already have one open position running.. I want to use buy stop or sell stop but I dont want to run two orders at same time even when I have enough margin... can you tell me how to disable multiple trading? 

Don't place a pending order where it can trigger before the open order hits SL or TP.

 
Well, as much as I know, you need to check your list of open Positions against the list of pending Orders.

Here as a starting point:
PositionsTotal() and OrdersTotal()

https://www.mql5.com/de/docs/trading

The processing should occur in
OnTrade()