Вы находитесь на странице: 1из 2

//+------------------------------------------------------------------+

//| Fractals.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_ARROW
#property indicator_type2 DRAW_ARROW
#property indicator_color1 clrYellow
#property indicator_color2 clrYellow
#property indicator_label1 "Fractal Up"
#property indicator_label2 "Fractal Down"
#property strict
//---- indicator buffers
double ExtUpperBuffer[];
double ExtLowerBuffer[];

input int lado=2;


input int ExtArrowShift=50;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if(!ArraySetAsSeries(ExtUpperBuffer,true))
return(INIT_FAILED);
if(!ArraySetAsSeries(ExtLowerBuffer,true))
return(INIT_FAILED);

if(!SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA))
return(INIT_FAILED);

if(!SetIndexBuffer(1,ExtLowerBuffer,INDICATOR_DATA))
return(INIT_FAILED);

#ifdef __MQL4__
SetIndexArrow(0,217);
SetIndexArrow(1,218);
#endif

#ifdef __MQL5__
if(!PlotIndexSetInteger(0,PLOT_ARROW,217))
return(INIT_FAILED);
if(!PlotIndexSetInteger(1,PLOT_ARROW,218))
return(INIT_FAILED);
#endif

return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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[])
{
if(!ArraySetAsSeries(low,true))
return(prev_calculated);
if(!ArraySetAsSeries(high,true))
return(prev_calculated);

int cont3;

for(int i=((prev_calculated==0)?(rates_total-1):prev_calculated);i>=0;i--)
{
ExtUpperBuffer[i]=EMPTY_VALUE;
ExtLowerBuffer[i]=EMPTY_VALUE;

if(i>=rates_total-1-lado)
continue;

if(i<lado)
continue;

cont3=1;
while(cont3<=lado)
{
if(high[i]<high[i+cont3] || high[i]<high[i-cont3])
break;

cont3++;
}
if(cont3==lado+1)
ExtUpperBuffer[i]=high[i]+ExtArrowShift*_Point;

cont3=1;
while(cont3<=lado)
{
if(low[i]>low[i+cont3] || low[i]>low[i-cont3])
break;

cont3++;
}
if(cont3==lado+1)
ExtLowerBuffer[i]=low[i]-ExtArrowShift*_Point;

}
return(lado);
}
//+------------------------------------------------------------------+

Вам также может понравиться