Delete pending order after a previous order go a profit.

 
I ask you then this thing, in short, I want that when a particular order is closed because it reached its Take Profit, another specific pending order is closed.
An example, if I buy in the market to 0.6400 and put Take Profit at 0.6500, well this is the first order (1).
Well the same time I place a pending order, in 6400, ok this is the second order (2).

My question is very simple how can I eliminate the second order (2), when the first (1) has reached the Take Profit?


I tried several times but have never managed to get what I wanted, one below is an example.

I hope someone help me possas.


 
void TechnicalAnalysis8()
{
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        
        if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1 && Ask - OrderOpenPrice() > BuyTakeprofit3*PipValue*Point)
    {
        DeletePendingOrder9();
       
    }
}

void DeletePendingOrder9()
{
    
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_SELLSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 2)
        {
            bool ret = OrderDelete(OrderTicket(), Red);
            
            if (ret == false)
            {
                Print("OrderDelete() error - ", ErrorDescription(GetLastError()));
            }
        }
    }
    
}
Reason: