how to close ?

 

how to close the ticket,

it just open but no close ... it is for Marketiva ..

if (sendCmd("<TEST CONNECTION>", "send() failed: error " + WSAGetLastError() + " (0)", "Test connection is OK.") < 0) return (-1);
   int l_file_160 = FileOpen("MarketivaSSBS.txt", FILE_CSV|FILE_WRITE, ';');
   if (l_file_160 > 0) {
      FileWrite(l_file_160, Server_Address);
      FileFlush(l_file_160);
      FileClose(l_file_160);
   }
   while (!IsStopped()) {
      Comment(ls_108);
      for (l_pos_16 = 0; OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES); l_pos_16++) {
         if (GetAsyncKeyState(123)) break;
         if (Bridge_All_Symbols || OrderSymbol() == Symbol()) {
            if (OrderOpenTime() - l_datetime_0 > 0) {
               li_100 = existOrderinArray(OrderTicket(), lia_20, l_index_56);
               if (li_100 == -1) {
                  lia_20[l_index_56] = OrderTicket();
                  lia_24[l_index_56] = OrderOpenTime();
                  lia_28[l_index_56] = OrderType();
                  lda_32[l_index_56] = OrderLots();
                  lsa_36[l_index_56] = OrderSymbol();
                  lda_40[l_index_56] = OrderOpenPrice();
                  lda_44[l_index_56] = OrderStopLoss();
                  lda_48[l_index_56] = OrderTakeProfit();
                  lda_52[l_index_56] = OrderClosePrice();
                  l_index_56++;
                  if (l_index_56 > 200) {
                     myPrint("Out of Array range, please contact developer about this error. (1)");
                     break;
                  }
                  switch (lia_28[l_index_56 - 1]) {
                  case 0:
                  case 1:
                     if (sendCmd("1|" + ((lia_20[l_index_56 - 1])) + "|" + ((lia_24[l_index_56 - 1])) + "|" + ((lia_28[l_index_56 - 1])) + "|" + ((lda_32[l_index_56 - 1])) + "|" + ((lsa_36[l_index_56 - 1])) +
                        "|" + ((lda_40[l_index_56 - 1])) + "|" + ((lda_44[l_index_56 - 1])) + "|" + ((lda_48[l_index_56 - 1])) + "|" + ((lda_52[l_index_56 - 1])), "send() failed: error " + WSAGetLastError() + " (1)", "sent a new open order command, order ticket: " + ((lia_20[l_index_56 - 1]))) < 0) return (-1);
                     break;
                  case 2:
                  case 4:
                  case 3:
                  case 5:
                     if (sendCmd("2|" + ((lia_20[l_index_56 - 1])) + "|" + ((lia_24[l_index_56 - 1])) + "|" + ((lia_28[l_index_56 - 1])) + "|" + ((lda_32[l_index_56 - 1])) + "|" + ((lsa_36[l_index_56 - 1])) +
                        "|" + ((lda_40[l_index_56 - 1])) + "|" + ((lda_44[l_index_56 - 1])) + "|" + ((lda_48[l_index_56 - 1])) + "|" + ((lda_52[l_index_56 - 1])), "send() failed: error " + WSAGetLastError() + " (2)", "sent a new pending order command, order ticket: " + ((lia_20[l_index_56 - 1]))) < 0) return (-1);
                  }
               }
               switch (lia_28[li_100]) {
               case 0:
               case 1:
                  if (lda_44[li_100] != OrderStopLoss() || lda_48[li_100] != OrderTakeProfit()) {
                     lda_44[li_100] = OrderStopLoss();
                     lda_48[li_100] = OrderTakeProfit();
                     if (sendCmd("3|" + lia_20[li_100] + "|" + lia_24[li_100] + "|" + lia_28[li_100] + "|" + lda_32[li_100] + "|" + lsa_36[li_100] + "|" + lda_40[li_100] + "|" + lda_44[li_100] +
                        "|" + lda_48[li_100] + "|" + lda_52[li_100], "send() failed: error " + WSAGetLastError() + " (3)", "sent a changed open order command, order ticket: " + lia_20[li_100]) < 0) return (-1);
                  }
                  break;
               case 2:
               case 4:
               case 3:
               case 5:
                  if (lda_44[li_100] != OrderStopLoss() || lda_48[li_100] != OrderTakeProfit() || lda_40[li_100] != OrderOpenPrice()) {
                     lda_40[li_100] = OrderOpenPrice();
                     lda_44[li_100] = OrderStopLoss();
                     lda_48[li_100] = OrderTakeProfit();
                     if (sendCmd("4|" + lia_20[li_100] + "|" + lia_24[li_100] + "|" + lia_28[li_100] + "|" + lda_32[li_100] + "|" + lsa_36[li_100] + "|" + lda_40[li_100] + "|" + lda_44[li_100] +
                        "|" + lda_48[li_100] + "|" + lda_52[li_100], "send() failed: error " + WSAGetLastError() + " (4)", "sent a changed pending order command, order ticket: " + lia_20[li_100]) < 0) return (-1);
                  }
               }
            }
         }
      }
      l_pos_16 = 0;
      li_100 = 0;
      while (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_HISTORY)) {
         if (GetAsyncKeyState(123)) break;
         if (Bridge_All_Symbols || OrderSymbol() == Symbol()) {
            if (OrderOpenTime() - l_datetime_0 > 0) {
               if (existOrderinArray(OrderTicket(), lia_60, l_index_96) == -1) {
                  lia_60[l_index_96] = OrderTicket();
                  lia_64[l_index_96] = OrderOpenTime();
                  lia_68[l_index_96] = OrderType()
                  lda_72[l_index_96] = OrderLots();
                  lsa_76[l_index_96] = OrderSymbol();
                  lda_80[l_index_96] = OrderOpenPrice();
                  lda_84[l_index_96] = OrderStopLoss();
                  lda_88[l_index_96] = OrderTakeProfit();
                  lda_92[l_index_96] = OrderClosePrice();
                  l_index_96++;
                  if (l_index_96 > 200) {
                     Print("Out of Array range, please contact developer about this error. (2)");
                     break;
                  }
                  switch (lia_68[l_index_96 - 1]) {
                  case 0:
                  case 1:
                     if (sendCmd("5|" + ((lia_60[l_index_96 - 1])) + "|" + ((lia_64[l_index_96 - 1])) + "|" + ((lia_68[l_index_96 - 1])) + "|" + ((lda_72[l_index_96 - 1])) + "|" + ((lsa_76[l_index_96 - 1])) +
                        "|" + ((lda_80[l_index_96 - 1])) + "|" + ((lda_84[l_index_96 - 1])) + "|" + ((lda_88[l_index_96 - 1])) + "|" + ((lda_92[l_index_96 - 1])), "send() failed: error " + WSAGetLastError() + " (5)", "sent a closed order without stoploss and exit target command, order ticket: " + ((lia_60[l_index_96 - 1]))) < 0) return (-1);
                     break;
                  case 2:
                  case 4:
                  case 3:
                  case 5:
                     if (sendCmd("6|" + ((lia_60[l_index_96 - 1])) + "|" + ((lia_64[l_index_96 - 1])) + "|" + ((lia_68[l_index_96 - 1])) + "|" + ((lda_72[l_index_96 - 1])) + "|" + ((lsa_76[l_index_96 - 1])) +
                        "|" + ((lda_80[l_index_96 - 1])) + "|" + ((lda_84[l_index_96 - 1])) + "|" + ((lda_88[l_index_96 - 1])) + "|" + ((lda_92[l_index_96 - 1])), "send() failed: error " + WSAGetLastError() + " (6)", "sent a canceled order command, order ticket: " + ((lia_60[l_index_96 - 1]))) < 0) return (-1);
                  }
               }
            }
         }
         l_pos_16++;
      }
      if (GetAsyncKeyState(123)) break;
      Sleep(10);
   }
   return (0);
}