help in implementation of hedge code

 
First apologize for my bad English.

I am new in MQL4 programming and also in the forum and searched and found nothing like what I want. First, my code sends two orders , in opposite directions, and I need a code to open a new order so that one of them is closed.
The order must always be opposed to pendende order. So always have an open BUY and SELL order. When SELL order closing , opens a BUY and vice versa.
If anyone can help me describing the code I'll be very grateful. Sorry for the ignorance , I am beginner in programming. Thanks!
#property copyright "Jefferson Souza"

#define MAGIC  1234
#define IDENT  "EA_Hedge_Test"

extern double  lots           = 1;
extern double  stop_loss      = 80;   // (8 pips) optimise 50-2000
extern double  take_profit    = 750;  // (75 pips) optimise 50-2000
extern double  numeromagico   =1234;

int            last_bar=0;
int i;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
     {
      if(last_bar == Bars) return(0);
      last_bar=Bars;
      if(OrdersTotal()==0)
        {
         OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask-stop_loss*Point,Bid+take_profit*Point,IDENT,MAGIC,0,Blue);
         OrderSend(Symbol(),OP_SELL,lots,Bid,3,Bid+stop_loss*Point,Ask-take_profit*Point,IDENT,MAGIC,0,Red);
        }
      return (0);
     }
  }

   int verifica()
  {

   int Total=OrdersTotal(),
   NumOrdensBuy = 0,
   NumOrdensSell = 0;

   for(i=0;i<Total;i++);
     { 
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
     
      if((OrderSymbol()==Symbol()) && // é deste par de moedas
         (OrderMagicNumber()==numeromagico))
        { 

         if(OrderType()==OP_BUY);
           {
            if(max_orders>OrdersTotal() && OrdersTotal()==OrderTakeProfit()==OP_BUY);
              {
               if(OrderTakeProfit()==OP_BUY);

               else
                  OrderSend(Symbol(),OP_SELL,lots,Bid,3,Bid+stop_loss*Point,Ask-take_profit*Point,IDENT,MAGIC,0,Red);
              };



            if(OrderType()==OP_BUY);
              {
               if(max_orders>OrdersTotal() && OrdersTotal()==OrderTakeProfit()==OP_SELL);
                 {
                  if(OrderTakeProfit()==OP_SELL);

                  else
                     OrderSend(Symbol(),OP_BUY,lots,Bid,3,Bid+stop_loss*Point,Ask-take_profit*Point,IDENT,MAGIC,0,Red);
                 };



               if(OrderType()==OP_BUY);
                 {
                  if(max_orders>OrdersTotal() && OrdersTotal()==OrderTakeProfit()==OP_SELL);
                    {
                     if(OrderTakeProfit()==OP_BUY);

                     else
                        OrderSend(Symbol(),OP_BUY,lots,Bid,3,Bid+stop_loss*Point,Ask-take_profit*Point,IDENT,MAGIC,0,Red);
                    };



                  if(OrderType()==OP_SELL);
                    {
                     if(max_orders>OrdersTotal() && OrdersTotal()==OrderTakeProfit()==OP_BUY)
                       {
                        if(OrderTakeProfit()==OP_SELL);

                        else
                           OrderSend(Symbol(),OP_SELL,lots,Ask,3,Ask-stop_loss*Point,Bid+take_profit*Point,IDENT,MAGIC,0,Blue);
                       }
                    }

                  return (verifica());
                 };
              }
           }
        }
     }
  }
Reason: