CustomTicksDelete

Kullanıcı-tanımlı sembolün belirtilen aralıktaki geçmiş verilerini siler.

int  CustomTicksDelete(
   const string     symbol,            // sembol ismi
   long             from_msc,          // başlangıç tarihi
   long             to_msc             // bitiş tarihi
   );

Parametreler

symbol

[in]  Kullanıcı-tanımlı sembolün ismi

from_msc

[in]  Değiştirilmek istenilen veri aralığının başlangıç zamanı. Zaman 01.01.1970'den itibaren milisaniyeler biçiminde olmalıdır.

to_msc

[in]  Değiştirilmek istenilen veri aralığının son zamanı. Zaman 01.01.1970'den itibaren milisaniyeler biçiminde olmalıdır.

Dönüş Değeri

Silinene tik verilerinin sayısı veya hata durumunda '-1'.

 

Örnek:

//+------------------------------------------------------------------+
//|                                            CustomTicksDelete.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#define   CUSTOM_SYMBOL_NAME     Symbol()+".C"     // özel sembol adı
#define   CUSTOM_SYMBOL_PATH     "Forex"           // sembolün oluşturulacağı grubun adı
#define   CUSTOM_SYMBOL_ORIGIN   Symbol()          // özel sembolün temel alınacağı sembolün adı
 
#define   DATATICKS_TO_COPY      UINT_MAX          // kopyalanan tik sayısı
#define   DATATICKS_TO_DELETE    10                // silinen tik sayısı
#define   DATATICKS_TO_PRINT     20                // günlüğe gönderilen tik sayısı
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- özel sembol oluştururken hata kodunu al
   int create=CreateCustomSymbol(CUSTOM_SYMBOL_NAMECUSTOM_SYMBOL_PATHCUSTOM_SYMBOL_ORIGIN);
   
//--- hata kodu 0 değilse (başarılı sembol oluşturma) ve 5304 değilse (sembol zaten oluşturulmuş) - bırak
   if(create!=0 && create!=5304)
      return;
 
//--- standart sembol tik verilerini MqlTick dizisine al
   MqlTick array[]={};
   if(!GetTicksToArray(CUSTOM_SYMBOL_ORIGINDATATICKS_TO_COPYarray))
      return;
   
//--- standart sembolün ilk ve son alınan tiklerinin zamanını yazdır
   int total=(int)array.Size();
   PrintFormat("First tick time: %s.%03u, Last tick time: %s.%03u",
               TimeToString(array[0].time,TIME_DATE|TIME_MINUTES|TIME_SECONDS), array[0].time_msc%1000,
               TimeToString(array[total-1].timeTIME_DATE|TIME_MINUTES|TIME_SECONDS), array[total-1].time_msc%1000);
               
//--- standart sembolün son DATATICKS_TO_PRINT tikini günlüğe yazdır
   PrintFormat("\nThe last %d ticks for the standard symbol '%s':"DATATICKS_TO_PRINTCUSTOM_SYMBOL_ORIGIN);
   for(int i=total-DATATICKS_TO_PRINTi<totali++)
     {
      if(i<0)
         continue;
      PrintFormat("  %dth Tick: %s"iGetTickDescription(array[i]));
     }
   
//--- Piyasa Gözlemi penceresine özel bir sembol ekle
   ResetLastError();
   if(!SymbolSelect(CUSTOM_SYMBOL_NAMEtrue))
     {
      Print("SymbolSelect() failed. Error "GetLastError());
      return;
     }
     
//--- tik dizisi verilerini özel sembol fiyat geçmişine ekle
   Print("...");
   uint start=GetTickCount();
   PrintFormat("Start of adding %u ticks to the history of the custom symbol '%s'"array.Size(), CUSTOM_SYMBOL_NAME);
   int added=CustomTicksAdd(CUSTOM_SYMBOL_NAMEarray);
   PrintFormat("Added %u ticks to the history of the custom symbol '%s' in %u ms"addedCUSTOM_SYMBOL_NAMEGetTickCount()-start);
   
//--- MqlTick dizisine yeni eklenen özel sembol tik verilerini al
   Print("...");
   if(!GetTicksToArray(CUSTOM_SYMBOL_NAMEarray.Size(), array))
      return;
   
//--- özel sembolün ilk ve son alınan tiklerinin zamanını yazdır
   total=(int)array.Size();
   PrintFormat("First tick time: %s.%03u, Last tick time: %s.%03u",
               TimeToString(array[0].timeTIME_DATE|TIME_MINUTES|TIME_SECONDS), array[0].time_msc%1000,
               TimeToString(array[total-1].timeTIME_DATE|TIME_MINUTES|TIME_SECONDS), array[total-1].time_msc%1000);
               
//--- özel sembolün son DATATICKS_TO_PRINT tikini günlüğe yazdır
   PrintFormat("\nThe last %d ticks for the custom symbol '%s':"DATATICKS_TO_PRINTCUSTOM_SYMBOL_NAME);
   for(int i=total-DATATICKS_TO_PRINTi<totali++)
     {
      if(i<0)
         continue;
      PrintFormat("  %dth Tick: %s"iGetTickDescription(array[i]));
     }
 
//--- geçmişten tik aralığını silmeye başlayacağımız milisaniye cinsinden tik zamanını al
   long time_from=array[total-DATATICKS_TO_DELETE-1].time_msc;
     
//--- özel sembolün DATATICKS_TO_DELETE son tik aralığını sil
   Print("...");
   start=GetTickCount();
   PrintFormat("Start deleting %u ticks in the history of the custom symbol '%s'"DATATICKS_TO_DELETECUSTOM_SYMBOL_NAME);
   int deleted=CustomTicksDelete(CUSTOM_SYMBOL_NAMEtime_fromarray[total-2].time_msc);
   PrintFormat("Deleted %u ticks in the history of the custom symbol '%s' in %u ms"deletedCUSTOM_SYMBOL_NAMEGetTickCount()-start);
   
//--- yeni değiştirilmiş özel sembol tik verilerini MqlTick dizisine al
   Print("...");
   if(!GetTicksToArray(CUSTOM_SYMBOL_NAMEarray.Size(), array))
      return;
   
//--- kaldırılmış tik aralığına sahip özel sembolün ilk ve son tiklerinin zamanını yazdır
   total=(int)array.Size();
   PrintFormat("Time of the first tick from the changed history: %s.%03u, Time of the last tick from the changed history: %s.%03u",
               TimeToString(array[0].timeTIME_DATE|TIME_MINUTES|TIME_SECONDS), array[0].time_msc%1000,
               TimeToString(array[total-1].timeTIME_DATE|TIME_MINUTES|TIME_SECONDS), array[total-1].time_msc%1000);
               
//--- özel sembolün son DATATICKS_TO_PRINT tikini günlüğe yazdır
   PrintFormat("\nThe last %d ticks of custom symbol '%s' with modified history:"DATATICKS_TO_PRINTCUSTOM_SYMBOL_NAME);
   for(int i=total-DATATICKS_TO_PRINTi<totali++)
     {
      if(i<0)
         continue;
      PrintFormat("  %dth Tick: %s"iGetTickDescription(array[i]));
     }
 
//--- grafikte yorum olarak kod sonlandırma tuşları hakkında bir ipucu görüntüle
   Comment(StringFormat("Press 'Esc' to exit or 'Del' to delete the '%s' symbol and exit"CUSTOM_SYMBOL_NAME));
//--- sonsuz bir döngüde çıkmak için Esc veya Del tuşlarına basılmasını bekle
   while(!IsStopped() && TerminalInfoInteger(TERMINAL_KEYSTATE_ESCAPE)==0)
     {
      Sleep(16);
      //--- Del tuşuna basıldığında, oluşturulan özel sembol ve verilerini sil
      if(TerminalInfoInteger(TERMINAL_KEYSTATE_DELETE)<0)
        {
         //--- çubuk verilerini sil
         int deleted=CustomRatesDelete(CUSTOM_SYMBOL_NAME0LONG_MAX);
         if(deleted>0)
            PrintFormat("%d history bars of the custom symbol '%s' were successfully deleted"deletedCUSTOM_SYMBOL_NAME);
         
         //--- tik verilerini sil
         deleted=CustomTicksDelete(CUSTOM_SYMBOL_NAME0LONG_MAX);
         if(deleted>0)
            PrintFormat("%d history ticks of the custom symbol '%s' were successfully deleted"deletedCUSTOM_SYMBOL_NAME);
         
         //--- sembolü sil
         if(DeleteCustomSymbol(CUSTOM_SYMBOL_NAME))
            PrintFormat("Custom symbol '%s' deleted successfully"CUSTOM_SYMBOL_NAME);
         break;
        }
     }
//--- çıkmadan önce grafiği temizle
   Comment("");
   /*
   sonuç:
   Requested 4294967295 ticks to get tick history for the symbol 'EURUSD'
   The tick history for the 'EURUSDsymbol is received in the amount of 351199027 ticks in 55875 ms
   First tick time2011.12.19 00:00:08.000Last tick time2024.06.21 10:10:40.392
   
   The last 20 ticks for the standard symbol 'EURUSD':
     351199007th Tick2024.06.21 10:10:23.045 Bid=1.07032 (Info tick)
     351199008th Tick2024.06.21 10:10:24.045 Ask=1.07031 Bid=1.07031 (Info tick)
     351199009th Tick2024.06.21 10:10:24.545 Ask=1.07032 (Info tick)
     351199010th Tick2024.06.21 10:10:25.146 Bid=1.07032 (Info tick)
     351199011th Tick2024.06.21 10:10:25.649 Ask=1.07037 Bid=1.07037 (Info tick)
     351199012th Tick2024.06.21 10:10:27.050 Ask=1.07036 Bid=1.07036 (Info tick)
     351199013th Tick2024.06.21 10:10:28.153 Ask=1.07039 Bid=1.07039 (Info tick)
     351199014th Tick2024.06.21 10:10:29.157 Ask=1.07037 Bid=1.07037 (Info tick)
     351199015th Tick2024.06.21 10:10:29.658 Ask=1.07036 Bid=1.07036 (Info tick)
     351199016th Tick2024.06.21 10:10:30.258 Bid=1.07036 (Info tick)
     351199017th Tick2024.06.21 10:10:30.872 Ask=1.07035 Bid=1.07035 (Info tick)
     351199018th Tick2024.06.21 10:10:31.358 Ask=1.07036 (Info tick)
     351199019th Tick2024.06.21 10:10:31.859 Ask=1.07037 Bid=1.07037 (Info tick)
     351199020th Tick2024.06.21 10:10:32.377 Ask=1.07039 Bid=1.07039 (Info tick)
     351199021th Tick2024.06.21 10:10:32.962 Ask=1.0704 Bid=1.0704 (Info tick)
     351199022th Tick2024.06.21 10:10:33.961 Ask=1.07039 Bid=1.07039 (Info tick)
     351199023th Tick2024.06.21 10:10:34.667 Ask=1.0704 (Info tick)
     351199024th Tick2024.06.21 10:10:35.170 Bid=1.0704 (Info tick)
     351199025th Tick2024.06.21 10:10:38.266 Ask=1.07041 Bid=1.07041 (Info tick)
     351199026th Tick2024.06.21 10:10:40.392 Ask=1.07042 Bid=1.07042 (Info tick)
   ...
   Start of adding 351199027 ticks to the history of the custom symbol 'EURUSD.C'
   Added 351199027 ticks to the history of the custom symbol 'EURUSD.Cin 261594 ms
   ...
   Requested 351199027 ticks to get tick history for the symbol 'EURUSD.C'
   The tick history for the 'EURUSD.Csymbol is received in the amount of 351199027 ticks in 137156 ms
   First tick time2011.12.19 00:00:08.000Last tick time2024.06.21 10:10:40.392
   
   The last 20 ticks for the custom symbol 'EURUSD.C':
     351199007th Tick2024.06.21 10:10:23.045 Ask=1.07032 Bid=1.07032 (Info tick)
     351199008th Tick2024.06.21 10:10:24.045 Ask=1.07031 Bid=1.07031 (Info tick)
     351199009th Tick2024.06.21 10:10:24.545 Ask=1.07032 Bid=1.07032 (Info tick)
     351199010th Tick2024.06.21 10:10:25.146 Ask=1.07032 Bid=1.07032 (Info tick)
     351199011th Tick2024.06.21 10:10:25.649 Ask=1.07037 Bid=1.07037 (Info tick)
     351199012th Tick2024.06.21 10:10:27.050 Ask=1.07036 Bid=1.07036 (Info tick)
     351199013th Tick2024.06.21 10:10:28.153 Ask=1.07039 Bid=1.07039 (Info tick)
     351199014th Tick2024.06.21 10:10:29.157 Ask=1.07037 Bid=1.07037 (Info tick)
     351199015th Tick2024.06.21 10:10:29.658 Ask=1.07036 Bid=1.07036 (Info tick)
     351199016th Tick2024.06.21 10:10:30.258 Ask=1.07036 Bid=1.07036 (Info tick)
     351199017th Tick2024.06.21 10:10:30.872 Ask=1.07035 Bid=1.07035 (Info tick)
     351199018th Tick2024.06.21 10:10:31.358 Ask=1.07036 Bid=1.07036 (Info tick)
     351199019th Tick2024.06.21 10:10:31.859 Ask=1.07037 Bid=1.07037 (Info tick)
     351199020th Tick2024.06.21 10:10:32.377 Ask=1.07039 Bid=1.07039 (Info tick)
     351199021th Tick2024.06.21 10:10:32.962 Ask=1.0704 Bid=1.0704 (Info tick)
     351199022th Tick2024.06.21 10:10:33.961 Ask=1.07039 Bid=1.07039 (Info tick)
     351199023th Tick2024.06.21 10:10:34.667 Ask=1.0704 Bid=1.0704 (Info tick)
     351199024th Tick2024.06.21 10:10:35.170 Ask=1.0704 Bid=1.0704 (Info tick)
     351199025th Tick2024.06.21 10:10:38.266 Ask=1.07041 Bid=1.07041 (Info tick)
     351199026th Tick2024.06.21 10:10:40.392 Ask=1.07042 Bid=1.07042 (Info tick)
   ...
   Start deleting 10 ticks in the history of the custom symbol 'EURUSD.C'
   Deleted 10 ticks in the history of the custom symbol 'EURUSD.Cin 188 ms
   ...
   Requested 351199027 ticks to get tick history for the symbol 'EURUSD.C'
   The tick history for the 'EURUSD.Csymbol is received in the amount of 351199017 ticks in 138312 ms
   Time of the first tick from the changed history2011.12.19 00:00:08.000Time of the last tick from the changed history2024.06.21 10:10:40.392
   
   The last 20 ticks of custom symbol 'EURUSD.Cwith modified history:
     351198997th Tick2024.06.21 10:10:14.935 Ask=1.07036 Bid=1.07036 (Info tick)
     351198998th Tick2024.06.21 10:10:15.533 Ask=1.07035 Bid=1.07035 (Info tick)
     351198999th Tick2024.06.21 10:10:17.736 Ask=1.07036 Bid=1.07036 (Info tick)
     351199000th Tick2024.06.21 10:10:18.540 Ask=1.07037 Bid=1.07037 (Info tick)
     351199001th Tick2024.06.21 10:10:19.046 Ask=1.07038 Bid=1.07038 (Info tick)
     351199002th Tick2024.06.21 10:10:19.542 Ask=1.07036 Bid=1.07036 (Info tick)
     351199003th Tick2024.06.21 10:10:20.041 Ask=1.07035 Bid=1.07035 (Info tick)
     351199004th Tick2024.06.21 10:10:21.041 Ask=1.07035 Bid=1.07035 (Info tick)
     351199005th Tick2024.06.21 10:10:21.544 Ask=1.07032 Bid=1.07032 (Info tick)
     351199006th Tick2024.06.21 10:10:22.344 Ask=1.07032 Bid=1.07032 (Info tick)
     351199007th Tick2024.06.21 10:10:23.045 Ask=1.07032 Bid=1.07032 (Info tick)
     351199008th Tick2024.06.21 10:10:24.045 Ask=1.07031 Bid=1.07031 (Info tick)
     351199009th Tick2024.06.21 10:10:24.545 Ask=1.07032 Bid=1.07032 (Info tick)
     351199010th Tick2024.06.21 10:10:25.146 Ask=1.07032 Bid=1.07032 (Info tick)
     351199011th Tick2024.06.21 10:10:25.649 Ask=1.07037 Bid=1.07037 (Info tick)
     351199012th Tick2024.06.21 10:10:27.050 Ask=1.07036 Bid=1.07036 (Info tick)
     351199013th Tick2024.06.21 10:10:28.153 Ask=1.07039 Bid=1.07039 (Info tick)
     351199014th Tick2024.06.21 10:10:29.157 Ask=1.07037 Bid=1.07037 (Info tick)
     351199015th Tick2024.06.21 10:10:29.658 Ask=1.07036 Bid=1.07036 (Info tick)
     351199016th Tick2024.06.21 10:10:40.392 Ask=1.07042 Bid=1.07042 (Info tick)
   */
  }
//+------------------------------------------------------------------+
//| Özel sembol oluştur, bir hata kodu geri döndür                   |
//+------------------------------------------------------------------+
int CreateCustomSymbol(const string symbol_nameconst string symbol_pathconst string symbol_origin=NULL)
  {
//--- özel sembolün temel alınacağı sembolün adını tanımla
   string origin=(symbol_origin==NULL ? Symbol() : symbol_origin);
   
//--- özel bir sembol oluşturulamadıysa ve bu hata 5304 değilse, bunu günlükte raporla
   ResetLastError();
   int error=0;
   if(!CustomSymbolCreate(symbol_namesymbol_pathorigin))
     {
      error=GetLastError();
      if(error!=5304)
         PrintFormat("CustomSymbolCreate(%s, %s, %s) failed. Error %d"symbol_namesymbol_pathoriginerror);
     }
//--- başarılı
   return(error);
  }
//+------------------------------------------------------------------+
//| Özel sembol kaldır                                               |
//+------------------------------------------------------------------+
bool DeleteCustomSymbol(const string symbol_name)
  {
//--- sembolü Piyasa Gözlemi penceresinden gizle
   ResetLastError();
   if(!SymbolSelect(symbol_namefalse))
     {
      PrintFormat("SymbolSelect(%s, false) failed. Error %d"GetLastError());
      return(false);
     }
      
//--- özel sembol silinemediyse, bunu günlükte raporla ve 'false' geri döndür
   ResetLastError();
   if(!CustomSymbolDelete(symbol_name))
     {
      PrintFormat("CustomSymbolDelete(%s) failed. Error %d"symbol_nameGetLastError());
      return(false);
     }
//--- başarılı
   return(true);
  }
//+------------------------------------------------------------------+
//| Diziye belirtilen sayıda tik al                                  |
//+------------------------------------------------------------------+
bool GetTicksToArray(const string symbolconst uint countMqlTick &array[])
  {
//--- geçmiş verilerin yüklenmeye başladığını bildir
   PrintFormat("Requested %u ticks to get tick history for the symbol '%s'"countsymbol);
   
//--- tikleri almak için 3 deneme yap
   int attempts=0;
   while(attempts<3)
     {
      //--- tikleri almadan önce başlangıç zamanını ölç
      uint start=GetTickCount();
      
      //--- 1970.01.01 00:00.001'den bu yana tik geçmişini iste (parametre from=1 ms)
      int received=CopyTicks(symbolarrayCOPY_TICKS_ALL1count);
      if(received!=-1)
        {
         //--- tik sayısı ve harcanan zaman hakkında bilgi görüntüle
         PrintFormat("The tick history for the '%s' symbol is received in the amount of %u ticks in %d ms"symbolreceivedGetTickCount()-start);
         
         //--- tik geçmişi senkronize edilmişse, hata kodu sıfıra eşittir - 'true' geri döner
         if(GetLastError()==0)
            return(true);
 
         PrintFormat("%s: Ticks are not synchronized yet, %d ticks received for %d ms. Error=%d"
                     symbolreceivedGetTickCount()-startGetLastError());
        }
      //--- denemeleri say
      attempts++; 
      //--- tik veritabanının senkronizasyonunun bitmesini beklemek için bir saniyelik duraklama
      Sleep(1000);
     }
//--- 3 denemede tiklerin kopyalanması başarısız oldu
   return(false);
  }
//+------------------------------------------------------------------+ 
//| Bir tikin dizge açıklamasını geri döndür                         |
//+------------------------------------------------------------------+ 
string GetTickDescription(MqlTick &tick
  { 
   string desc=StringFormat("%s.%03u "TimeToString(tick.timeTIME_DATE|TIME_MINUTES|TIME_SECONDS),tick.time_msc%1000);
   
//--- tik bayraklarını kontrol et
   bool buy_tick   = ((tick.flags &TICK_FLAG_BUY)   == TICK_FLAG_BUY); 
   bool sell_tick  = ((tick.flags &TICK_FLAG_SELL)  == TICK_FLAG_SELL); 
   bool ask_tick   = ((tick.flags &TICK_FLAG_ASK)   == TICK_FLAG_ASK); 
   bool bid_tick   = ((tick.flags &TICK_FLAG_BID)   == TICK_FLAG_BID); 
   bool last_tick  = ((tick.flags &TICK_FLAG_LAST)  == TICK_FLAG_LAST); 
   bool volume_tick= ((tick.flags &TICK_FLAG_VOLUME)== TICK_FLAG_VOLUME); 
   
//--- önce işlem bayrakları için tiki kontrol et (CustomTicksAdd() için yoktur)
   if(buy_tick || sell_tick
     { 
      //--- bir işlem tiki için bir çıktı oluştur
      desc += (buy_tick ? StringFormat("Buy Tick: Last=%G Volume=%d "tick.lasttick.volume)  : ""); 
      desc += (sell_tickStringFormat("Sell Tick: Last=%G Volume=%d ",tick.lasttick.volume) : ""); 
      desc += (ask_tick ? StringFormat("Ask=%G "tick.ask) : ""); 
      desc += (bid_tick ? StringFormat("Bid=%G "tick.ask) : ""); 
      desc += "(Trade tick)"
     } 
   else 
     { 
      //--- bir bilgi tiki için biraz farklı bir çıktı oluştur
      desc += (ask_tick   ? StringFormat("Ask=%G ",  tick.ask)    : ""); 
      desc += (bid_tick   ? StringFormat("Bid=%G ",  tick.ask)    : ""); 
      desc += (last_tick  ? StringFormat("Last=%G "tick.last)   : ""); 
      desc += (volume_tickStringFormat("Volume=%d ",tick.volume): ""); 
      desc += "(Info tick)"
     } 
//--- tik açıklamasını geri döndür
   return(desc); 
  } 

 

Ayrıca bakınız

CustomRatesDelete, CustomRatesUpdate, CustomTicksReplace, CopyTicks, CopyTicksRange