//+------------------------------------------------------------------+
//| iFractals.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 RoyalBlue
#property indicator_width1 1
#property indicator_width2 1
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[],buf;
double bufUpPrice[500]; //массив цен Up фракталов
double bufUpDate[500]; //массив дат Up фракталов
double bufDownPrice[500]; //массив цен Down фракталов
double bufDownDate[500]; //массив дат Down фракталов
int Up = 0; //счетчик Up фракталов
int Down = 0; //счетчик Down фракталов
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0,217);
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexEmptyValue(0, 0.0);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 218);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexEmptyValue(1, 0.0);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("iFractals");
SetIndexLabel(0, "iFractalsUp");
SetIndexLabel(1, "iFractalsDn");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
//----
int limit;
//---- последний посчитанный бар будет пересчитан
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars;
//---- основной цикл
for(int i = 2; i < limit; i++)
{
ExtMapBuffer1[i] = iFractals(NULL, 0, MODE_UPPER, i);
buf=iFractals(NULL, 0, MODE_UPPER, i);
if (buf!=0)
{
Up++;
bufUpPrice[Up]=iFractals(NULL, 0, MODE_UPPER, i);
bufUpDate[Up]=Time[i];
}
ExtMapBuffer2[i] = iFractals(NULL, 0, MODE_LOWER, i);
buf=iFractals(NULL, 0, MODE_LOWER, i);
if (buf!=0)
{
Down++;
bufDownPrice[Down]=iFractals(NULL, 0, MODE_LOWER, i);
bufDownDate[Down]=Time[i];
}
}
if(IsNewBar()){RefreshRates();coment();}
//----
return(0);
}
//+------------------------------------------------------------------+
////////////////////
bool IsNewBar()
{
static int nBars = 0;
if (nBars == 0)
{
nBars = Bars;
return(false);
}
if (nBars != Bars)
{
nBars = Bars;
return(true);
}
return(false);
}
////////////////////
void coment()
{
string st=
bufUpPrice[1]+" - "+bufUpDate[1]+"\n"+
bufUpPrice[2]+" - "+bufUpDate[2]+"\n"+
bufUpPrice[3]+" - "+bufUpDate[3]+"\n"+
bufDownPrice[1]+" - "+bufDownDate[1]+"\n"+
bufDownPrice[2]+" - "+bufDownDate[2]+"\n"+
bufDownPrice[3]+" - "+bufDownDate[3];
Comment(st);
}