Help Closing an Open Trade with a condition

 

Please any Help is appreciated I am new to to MQL in General and I have been trying to figure out this problem. After opening a trade It does not close with my condition and I do not why?

 if(total<1){

   if(dayOpen > dayClose && prevDayOpen > prevDayClose)

   {

     SellTrade();

   }

   

    else if(dayOpen < dayClose && prevDayOpen < prevDayClose)

   {

      BuyTrade();

   }

   else //Otherwise Exit

   {

       if(dayLow < prevDayLow && dayOpen > dayClose && OrderType()==OP_BUY)

   {

      OrderSelect(0,SELECT_BY_POS);

      OrderClose(OrderTicket(), OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,clrGold);

   }

   

   if(dayHigh > prevDayHigh && dayOpen < dayClose && OrderType()==OP_SELL)

   {

      OrderSelect(0,SELECT_BY_POS);

       OrderClose(OrderTicket(), OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,clrGold);

   }

   }

   }

 
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.

Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
 if(total<1){
    if(dayOpen > dayClose && prevDayOpen > prevDayClose){ SellTrade(); }

    else if(dayOpen < dayClose && prevDayOpen < prevDayClose){ BuyTrade(); }

    else //Otherwise Exit <<<<<<<< This else applies to not opening. It is not called once an order is open (total >= 1)
    {

       if(dayLow < prevDayLow && dayOpen > dayClose && OrderType()==OP_BUY){ << Select and order before getting its type.
          OrderSelect(0,SELECT_BY_POS);
          OrderClose(OrderTicket(), OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,clrGold);
   }
Reason: