//+------------------------------------------------------------------+
//| DRAW_FILLING.mq5 |
//| Copyright 2000-2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2000-2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property description "DRAW_FILLING stilini betimleyen bir gösterge"
#property description "Ayrı pencerede yer alan iki HO arasına bir kanal çizer"
#property description "dolgu rengi her N tikten sonra"
#property description "rassal olarak değiştirilir"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
//--- plot Intersection
#property indicator_label1 "Intersection"
#property indicator_type1 DRAW_FILLING
#property indicator_color1 clrRed,clrBlue
#property indicator_width1 1
//--- giriş parametreleri
input int Fast=13; // Hızlı olan ortalamanın periyodu
input int Slow=21; // Yavaş olan ortalamanın periyodu
input int shift=1; // Ortalamaların ileriye doğru (pozitif) kaydırılması
input int N=5; // Değişim için gerekli tik sayısı
//--- Gösterge tamponları
double IntersectionBuffer1[];
double IntersectionBuffer2[];
int fast_handle;
int slow_handle;
//--- Renkleri depolayacak bir dizi
color colors[]={clrRed,clrBlue,clrGreen,clrAquamarine,clrBlanchedAlmond,clrBrown,clrCoral,clrDarkSlateGray};
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- gösterge tamponlarının eşlenmesi
SetIndexBuffer(0,IntersectionBuffer1,INDICATOR_DATA);
SetIndexBuffer(1,IntersectionBuffer2,INDICATOR_DATA);
//---
PlotIndexSetInteger(0,PLOT_SHIFT,shift);
//---
fast_handle=iMA(_Symbol,_Period,Fast,0,MODE_SMA,PRICE_CLOSE);
slow_handle=iMA(_Symbol,_Period,Slow,0,MODE_SMA,PRICE_CLOSE);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
static int ticks=0;
//--- Çizginin stilini,rengini ve genişliğini değiştirmek için tikleri hesapla
ticks++;
//--- Yeterli sayıda tik birikmişse
if(ticks>=N)
{
//--- Çizgi özelliklerini değiştir
ChangeLineAppearance();
//--- Tik sayacını sıfırla
ticks=0;
}
//--- Göstergenin ilk hesabının yapılması; veya gösterge daha önce hesaplanmışsa, tüm hesabın yaniden yapılması
if(prev_calculated==0)
{
//--- Tüm gösterge değerlerini uygun tamponlara kopyala
int copied1=CopyBuffer(fast_handle,0,0,rates_total,IntersectionBuffer1);
int copied2=CopyBuffer(slow_handle,0,0,rates_total,IntersectionBuffer2);
}
else // Sadece güncellenen veriyi doldur
{
//--- OnCalculate() fonksiyonunun şimdiki ve daha önceki çağrıları arasındaki farkı çubuk bazında al
int to_copy=rates_total-prev_calculated;
//--- Fark yoksa, sadece tek değer kopyalarız - sıfır çubuğu üzerinde
if(to_copy==0) to_copy=1;
//--- to_copy değerlerini gösterge tamponunun en sonuna kopyala
int copied1=CopyBuffer(fast_handle,0,0,to_copy,IntersectionBuffer1);
int copied2=CopyBuffer(slow_handle,0,0,to_copy,IntersectionBuffer2);
}
//--- bir sonraki çağrı için prev_calculated değerine dönüş yap
return(rates_total);
}
//+------------------------------------------------------------------+
//| Kanal dolgusunun rengini değiştirir |
//+------------------------------------------------------------------+
void ChangeLineAppearance()
{
//--- Çizgi özelliklerine dair bilginin biçimlendirilmesi için bir dizgi
string comm="";
//--- Çizgi rengini değiştirmek için bir blok
int number=MathRand(); // Rassal bir sayı al
//--- Bölen, colors[] dizisinin boyutuna eşit
int size=ArraySize(colors);
//--- Bölümden kalan tam-sayı değeri şeklinde yeni bir renk seçmek için, indis değerini al
int color_index1=number%size;
//--- İlk rengi, PLOT_LINE_COLOR özelliği ile ayarla
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,colors[color_index1]);
//--- İlk rengi yaz
comm=comm+"\r\nColor1 "+(string)colors[color_index1];
//--- Bölümden kalan tam-sayı değeri şeklinde yeni bir renk seçmek için, indis değerini al
number=MathRand(); // Rassal bir sayı yaz
int color_index2=number%size;
//--- İkinci rengi, PLOT_LINE_COLOR özelliğiyle ayarla
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,colors[color_index2]);
//--- İkinci rengi yaz
comm=comm+"\r\nColor2 "+(string)colors[color_index2];
//--- Bir yorum kullanarak, çizelge üzerinde bilgi göster
Comment(comm);
}
|