ObjectGetTimeByValue

Nesnenin belirtilen fiyat değeri için zaman değerine dönüş yapar.

datetime  ObjectGetTimeByValue(
   long    chart_id,     // çizelge tanımlayıcı
   string  name,         // nesne ismi
   double  value,        // Fiyat
   int     line_id       // Çizgi numarası
   );

Parametreler

chart_id

[in]  Çizelge tanımlayıcısı. 0, mevcut çizelge anlamına gelir.

name

[in]  Nesne ismi.

value

[in]  Fiyat değeri.

line_id

[in]  Çizgi tanımlayıcı.

Dönüş değeri

Belirtilen nesnenin belirtilen fiyat değeri için zaman değerine dönüş yapar.

Not

Fonksiyon, eşzamanlı bir çağrı kullanır; bu, fonksiyonun çağrı öncesinde bu grafik için yerine getirilmiş tüm komutların yürütülmesini beklediği anlamına gelir, bu nedenle bu fonksiyon çok zaman alıcı olabilir. Bu özellik, bir grafikte çok sayıda nesneyle çalışırken dikkate alınmalıdır.

Bir nesne, bir fiyat koordinatında birden fazla değere sahip olabilir, bu yüzden çizgi numarasının da belirtilmesi gerekir. Bu fonksiyon sadece şu nesnelere uygulanır:

  • Trend çizgisi (OBJ_TREND)
  • Açılı trend çizgisi (OBJ_TRENDBYANGLE)
  • Gann çizgisi (OBJ_GANNLINE)
  • Eşit aralıklı kanal (OBJ_CHANNEL) - 2 çizgi
  • Doğrusal regresyon kanalı (OBJ_REGRESSION) - 3 çizgi
  • Standart sapma kanalı (OBJ_STDDEVCHANNEL) - 3 çizgi
  • Oklu çizgi (OBJ_ARROWED_LINE)

 

Örnek:

#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#define   OBJ_NAME   "TestObjectGetTimeByValue" // grafiksel nesne adı
#define   STEP       100                        // fiyat adımı
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- kimlik, sembol
   long   chart_id=ChartID();
   string chart_symbol=ChartSymbol(chart_id);
   
//--- grafik sembolünün puan değerini al
   double point=SymbolInfoDouble(chart_symbolSYMBOL_POINT);
   if(point==0)
     {
      PrintFormat("Failed to get the Point value of the \"%s\" symbol. Error %d"chart_symbolGetLastError());
      return;
     }
     
//--- soldaki görünür çubuğun Yüksek değerinden sağdaki çubuğun Düşük değerine bir eşit uzaklıklı kanal oluştur
   if(!CreateChannel(chart_id))
      return;
   
//--- grafiğin en yüksek ve en düşük fiyatı, grafik sembolü basamağı
   double chart_max=ChartGetDouble(chart_idCHART_PRICE_MAX);
   double chart_min=ChartGetDouble(chart_idCHART_PRICE_MIN);
   int    digits=(int)SymbolInfoInteger(chart_symbolSYMBOL_DIGITS);
 
//--- hesaplanan fiyat grafiğin en düşük fiyat değerinden daha büyükken,
//--- STEP ile grafik fiyatlarında bir döngüye gir ve
//--- eşit uzaklıklı kanalın her çizgisinin hesaplanan fiyat değeri için zaman değerini al.
//--- her çizgi için alınan zamanı günlüğe yazdır
   int index=0;
   double price=chart_max;
   do
     {
      price=chart_max-STEP*index*point;
      datetime time0=ObjectGetTimeByValue(chart_idOBJ_NAMEprice0);
      datetime time1=ObjectGetTimeByValue(chart_idOBJ_NAMEprice1);
      string   time0_str=(time0>0 ? TimeToString(time0) : "No value at this price");
      string   time1_str=(time1>0 ? TimeToString(time1) : "No value at this price");
      string   idx=StringFormat("%02d"index);
      PrintFormat("[%s] For price %.*f the time value at line 0: %s, at line 1: %s"idxdigitspricetime0_strtime1_str);
      index++;
     }
   while(!IsStopped() && price>=chart_min);
   
//--- 5 saniye bekle ve temizle
   Sleep(5000);
   ObjectDelete(chart_idOBJ_NAME);
   ChartRedraw(chart_id);
   /*
   sonuç:
   [00For price 1.26110 the time value at line 0No value at this price,  at line 1No value at this price
   [01For price 1.26010 the time value at line 02024.12.30 17:00at line 1No value at this price
   [02For price 1.25910 the time value at line 02024.12.30 22:30at line 1No value at this price
   [03For price 1.25810 the time value at line 02024.12.31 04:00at line 12024.12.30 16:30
   [04For price 1.25710 the time value at line 02024.12.31 10:00at line 12024.12.30 22:00
   [05For price 1.25610 the time value at line 02024.12.31 15:30at line 12024.12.31 03:30
   [06For price 1.25510 the time value at line 02024.12.31 21:00at line 12024.12.31 09:00
   [07For price 1.25410 the time value at line 02025.01.02 03:30at line 12024.12.31 14:30
   [08For price 1.25310 the time value at line 0No value at this priceat line 12024.12.31 20:30
   [09For price 1.25210 the time value at line 0No value at this priceat line 12025.01.02 03:00
   [10For price 1.25110 the time value at line 0No value at this priceat line 1No value at this price
   [11For price 1.25010 the time value at line 0No value at this priceat line 1No value at this price
   [12For price 1.24910 the time value at line 0No value at this priceat line 1No value at this price
   [13For price 1.24810 the time value at line 0No value at this priceat line 1No value at this price
   */
  }
//+--------------------------------------------------------------------------------------------+
//| Sol çubuğun Yüksek değerinden sağ çubuğun Düşük değerine bir eşit uzaklıklı kanal oluştur |
//+--------------------------------------------------------------------------------------------+
bool CreateChannel(const long chart_id=0)
  {
   long     bar1  =0bar2  =0visible=0;
   datetime time1 =0time2 =0;
   double   price1=0price2=0;
 
//--- solda görünen grafiğin ilk çubuğunu al
   ResetLastError();
   if(!ChartGetInteger(chart_idCHART_FIRST_VISIBLE_BAR0bar1))
     {
      PrintFormat("%s: ChartGetInteger() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
//--- grafikteki görünür çubuk sayısı
   if(!ChartGetInteger(chart_idCHART_VISIBLE_BARS0visible))
     {
      PrintFormat("%s: ChartGetInteger() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
 
//--- elde edilen değerleri ayarla ve sağda görünen ilk çubuğun indeksini hesapla
   bar1-=1;
   visible-=2;
   bar2=bar1-visible;
   
//--- grafik sembolü
   string symbol=ChartSymbol(chart_id);
   
//--- grafiğin solunda görünen ilk çubuğun zamanını al
   ResetLastError();
   datetime time_array[1];
   if(CopyTime(symbolPERIOD_CURRENT, (int)bar11time_array)!=1)
     {
      PrintFormat("%s: CopyTime() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
   time1=time_array[0];
   
//--- grafiğin sağında görünen ilk çubuğun zamanını al
   if(CopyTime(symbolPERIOD_CURRENT, (int)bar21time_array)!=1)
     {
      PrintFormat("%s: CopyTime() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
   time2=time_array[0];
   
//--- grafiğin solunda görünen ilk çubuğun Yüksek fiyatını al
   double price_array[];
   if(CopyHigh(symbolPERIOD_CURRENT, (int)bar11price_array)!=1)
     {
      PrintFormat("%s: CopyHigh() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
   price1=price_array[0];
   
//--- grafiğin sağında görünen ilk çubuğun Düşük fiyatını al
   if(CopyLow(symbolPERIOD_CURRENT, (int)bar21price_array)!=1)
     {
      PrintFormat("%s: CopyLow() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
   price2=price_array[0];
   
//--- grafiğin fiyat aralığını puan cinsinden hesapla
//--- bir eşit uzaklıklı kanal için, ikinci çizginin mesafesi fiyat aralığının 1/3'ü olacaktır
   double range=price1-price2;
   double distance=range*0.3;
   
//--- hesaplanan koordinatlarda bir grafiksel nesne oluştur - eşit uzaklıklı kanal
   if(!ObjectCreate(chart_idOBJ_NAMEOBJ_CHANNEL0time1price1time2price2time1price1-distance))
     {
      PrintFormat("%s: ObjectCreate() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
     
//--- grafiği güncelle ve ‘true’ geri döndür
   ChartRedraw(chart_id);
   return(true);
  }

 

Ayrıca Bakınız

Nesne Tipleri