CustomRatesUpdate

Kullanıcı-tanımlı bir sembolün veri geçmişindeki eksik verileri ekler ve mevcut verileri MqlRates tipli diziden kopyalayarak değiştirir.

int  CustomRatesUpdate(
   const string     symbol,             // kullanıcı-tanımlı sembolün ismi
   const MqlRates&  rates[],            // kullanıcı-tanımlı sembol için kullanılacak veri dizisi
   uint             count=WHOLE_ARRAY   // kullanılacak rates[] dizisi elemanlarının sayısı
   );

Parametreler

symbol

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

rates[]

[in]  M1 için MqlRates tipli geçmiş veri dizisi.

count=WHOLE_ARRAY

[in]  Güncelleme için kullanılacak rates[] dizisi elemanlarının sayısı. WHOLE_ARRAY, tüm rates[] dizisi elemanlarının kullanılması gerektiği anlamına gelir.

Geri Dönüş Değeri

Güncellenen veri sayısı veya hata durumunda '-1'.

Not

Kullanıcı-tanımlı sembolün rates[] dizisinde hiç çubuk verisi yoksa, eklenir.  Çubuk verisi mevcutsa, değiştirilir. Mevcut fiyat geçmişindeki diğer tüm veriler değiştirilmeden bırakılır. rates[] dizisindeki veriler OHLC fiyatlarına göre doğru olmalıdır ve çubuk açılış zamanları M1 zaman dilimine karşılık gelmelidir.

 

Örnek:

//+------------------------------------------------------------------+
//|                                            CustomRatesUpdate.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   DATARATES_COUNT        4                 // günlüğe gönderilen çubuk 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ün çubuk sayısını al ve günlüğe yazdır
   int bars_origin=Bars(CUSTOM_SYMBOL_ORIGINPERIOD_M1);
   PrintFormat("The symbol '%s' from which the custom '%s' was created has %d bars of minute history."CUSTOM_SYMBOL_ORIGINCUSTOM_SYMBOL_NAMEbars_origin);
      
//--- özel sembolün çubuk sayısını al ve günlüğe yazdır
   int bars_custom=Bars(CUSTOM_SYMBOL_NAMEPERIOD_M1);
   PrintFormat("Custom symbol '%s' created from symbol '%s' has %d bars of minute history"CUSTOM_SYMBOL_NAMECUSTOM_SYMBOL_ORIGINbars_custom);
      
//--- standart sembol dakika zaman dilimindeki tüm çubukların verilerini MqlRates dizisine al
   MqlRates rates[]={};
   ResetLastError();
   if(CopyRates(CUSTOM_SYMBOL_ORIGINPERIOD_M10bars_originrates)!=bars_origin)
     {
      PrintFormat("CopyRates(%s, PERIOD_M1, 0, %d) failed. Error %d"CUSTOM_SYMBOL_ORIGINbars_originGetLastError());
      return;
     }
 
//--- kopyalanan verileri özel sembolün dakika geçmişine ayarla
   ResetLastError();
   int updated=CustomRatesUpdate(CUSTOM_SYMBOL_NAMErates);
   if(updated<0)
     {
      PrintFormat("CustomRatesUpdate(%s) failed. Error %d"CUSTOM_SYMBOL_NAMEGetLastError());
      return;
     }
 
//--- geçmişi ekledikten sonra özel sembolün çubuk sayısını al ve günlüğe yazdır
   bars_custom=Bars(CUSTOM_SYMBOL_NAMEPERIOD_M1);
   PrintFormat("\nAfter CustomRatesUpdate(), the custom symbol '%s' has %d bars of minute history"CUSTOM_SYMBOL_NAMEbars_custom);
 
//--- özel sembolün dakika zaman dilimindeki tüm çubukların verilerini MqlRates dizisine al
   ResetLastError();
   if(CopyRates(CUSTOM_SYMBOL_NAMEPERIOD_M10bars_customrates)!=bars_custom)
     {
      PrintFormat("CopyRates(%s, PERIOD_M1, 0, %d) failed. Error %d"CUSTOM_SYMBOL_NAMEbars_customGetLastError());
      return;
     }
 
//--- özel sembol dakika geçmişinin son dört çubuğunu günlüğe yazdır
   int digits=(int)SymbolInfoInteger(CUSTOM_SYMBOL_NAMESYMBOL_DIGITS);
   PrintFormat("Last %d bars of the custom symbol's minute history:"DATARATES_COUNT);
   ArrayPrint(ratesdigitsNULLbars_custom-DATARATES_COUNTDATARATES_COUNT);
   
//--- MqlRates dizisindeki verileri 1.0/SymbolName denklemi kullanılarak hesaplanan verilerle değiştir
   for(int i=0i<bars_customi++)
     {
      rates[i].open  =(rates[i].open !=0  ? 1.0 / rates[i].open  : rates[i].open);
      rates[i].high  =(rates[i].high !=0  ? 1.0 / rates[i].high  : rates[i].high);
      rates[i].low   =(rates[i].low  !=0  ? 1.0 / rates[i].low   : rates[i].low);
      rates[i].close =(rates[i].close!=0  ? 1.0 / rates[i].close : rates[i].close);
     }
 
//--- değiştirilen verileri özel sembolün dakika geçmişine ayarla
   ResetLastError();
   updated=CustomRatesUpdate(CUSTOM_SYMBOL_NAMErates);
   if(updated<0)
     {
      PrintFormat("CustomRatesUpdate(%s) failed. Error %d"CUSTOM_SYMBOL_NAMEGetLastError());
      return;
     }
 
//--- özel sembolün dakika zaman dilimindeki tüm çubukların verilerini tekrar MqlRates dizisine al
   ResetLastError();
   if(CopyRates(CUSTOM_SYMBOL_NAMEPERIOD_M10bars_customrates)!=bars_custom)
     {
      PrintFormat("CopyRates(%s, PERIOD_M1, 0, %d) failed. Error %d"CUSTOM_SYMBOL_NAMEbars_customGetLastError());
      return;
     }
 
//--- güncellenmiş özel sembol dakika geçmişinin son dört çubuğunu günlüğe yazdır
   Print("\nLast %d bars after changing the custom symbol calculation formula:"DATARATES_COUNT);
   ArrayPrint(ratesdigitsNULLbars_custom-DATARATES_COUNTDATARATES_COUNT);
   
//--- 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ç:
   The symbol 'EURUSDfrom which the custom 'EURUSD.Cwas created has 250488 bars of minute history.
   Custom symbol 'EURUSD.Ccreated from symbol 'EURUSDhas 0 bars of minute history
   
   After CustomRatesUpdate(), the custom symbol 'EURUSD.Chas 250488 bars of minute history
   Last 4 bars of the custom symbol's minute history:
                    [time]  [open]  [high]   [low] [close] [tick_volume] [spread] [real_volume]
   [02024.06.18 11:14:00 1.07235 1.07239 1.07232 1.07239            24        0             0
   [12024.06.18 11:15:00 1.07238 1.07239 1.07232 1.07235            44        0             0
   [22024.06.18 11:16:00 1.07234 1.07238 1.07227 1.07234            37        0             0
   [32024.06.18 11:17:00 1.07234 1.07234 1.07217 1.07225            41        0             0
   
   Last 4 bars after changing the custom symbol calculation formula:
                    [time]  [open]  [high]   [low] [close] [tick_volume] [spread] [real_volume]
   [02024.06.18 11:14:00 0.93253 0.93250 0.93256 0.93250            24        0             0
   [12024.06.18 11:15:00 0.93251 0.93250 0.93256 0.93253            44        0             0
   [22024.06.18 11:16:00 0.93254 0.93251 0.93260 0.93254            37        0             0
   [32024.06.18 11:17:00 0.93254 0.93254 0.93269 0.93262            41        0             0
   */
  }
//+------------------------------------------------------------------+
//| Ö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);
  }

 

Ayrıca bakınız

CustomRatesReplace, CustomRatesDelete, CopyRates