Prevent new entry after every close candle if condition is met

Thanks in advance.
I have this prob how can i prevent my ea from entering a trade after every new candle .what i mean is i have this strategy to enter a trade when candle 1 closes below or above the moving average. I dont want to use the orderstotal function . When the candle closes a trade is send .When another candle closes another trade is send beause the condition is still met. please how can i prevent this
Pls mql4

You need to find a way to check if an order is already placed. One way to do this is to use magic numbers.

In simple terms, the following code snippet will tell your Expert Advisor that if there are any open trades with a particular MagicNumber, that it is to NOT continue on with opening another trade

Simply copy and paste this code into your EA and you will not have this problem anymore.

When a buy order is opened with a certain magic number, no more buy orders will open. If you want to make it so that no sell orders open either, when a buy order is open and vice versa, simply apply both halts to both opening conditions.

int orderAlreadyOpened = 0;
if(OrdersTotal()>0){
  for(i=1; i<=OrdersTotal(); i++)          // Checking to make sure there are no open orders. Keep this set to zero unless you want the advisor to open more than one buy at a time or more than one sell at a time.
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {
          // if this magicnumber matches the magic number you originally assigned set
          // orderAlreadyOpened to 1
          if(OrderMagicNumber()==MagicNumber1) {orderAlreadyOpened = 1;} 
        }
     }
}

// now before opening another trade, first check if orderAlreadyOpened is 0 or now