#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 1
//---- plot ColorLine
#property indicator_label1 "ColorLine"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrRed,clrGreen,clrBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 3
//--- gösterge tamponları
double ColorLineBuffer[];
double ColorBuffer[];
int MA_handle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- gösterge tamponlarının eşlenmesi
SetIndexBuffer(0,ColorLineBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX);
//--- MA (Hareketli Ortalamanın) işleyicisini al
MA_handle=iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE);
//---
}
//+------------------------------------------------------------------+
//| Renk indisini al |
//+------------------------------------------------------------------+
int getIndexOfColor(int i)
{
int j=i%300;
if(j<100) return(0);// ilk indis
if(j<200) return(1);// ikinci indis
return(2); // üçüncü indis
}
//+------------------------------------------------------------------+
//| 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,modified=0;
int limit;
//--- ilk hesaplama veya çubuk sayısı değişti
if(prev_calculated==0)
{
//--- MA değerlerini ColorLineBuffer gösterge tamponuna kopyala
int copied=CopyBuffer(MA_handle,0,0,rates_total,ColorLineBuffer);
if(copied<=0) return(0);// kopyalama başarısız - çöpe at
//--- şimdi her çubuk için çizgi rengini ayarla
for(int i=0;i<rates_total;i++)
ColorBuffer[i]=getIndexOfColor(i);
}
else
{
//--- MA değerlerini ColorLineBuffer gösterge tamponuna kopyala
int copied=CopyBuffer(MA_handle,0,0,rates_total,ColorLineBuffer);
if(copied<=0) return(0);
ticks++;// tiklerin sayılması
if(ticks>=5)// renk şemasının değişme vakti
{
ticks=0; // sayacı sıfırla
modified++; // renk değişimi sayacı
if(modified>=3)modified=0;// sayacı sıfırla
ResetLastError();
switch(modified)
{
case 0:// ilk renk şeması
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrRed);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrBlue);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrGreen);
Print("Renk şeması "+modified);
break;
case 1:// ikinci renk şeması
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrYellow);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrPink);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrLightSlateGray);
Print("Renk şeması "+modified);
break;
default:// üçüncü renk şeması
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrLightGoldenrod);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrOrchid);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrLimeGreen);
Print("Renk şeması "+modified);
}
}
else
{
//--- başlangıç konumunu ayarla
limit=prev_calculated-1;
//--- şimdi her çubuk için çizgi rengini ayarlıyoruz
for(int i=limit;i<rates_total;i++)
ColorBuffer[i]=getIndexOfColor(i);
}
}
//--- bir sonraki çağrı için prev_calculated değerine dönüş yap
return(rates_total);
}
//+------------------------------------------------------------------+
|