//+------------------------------------------------------------------+ //| Period_Extreme.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://mql5.com" #property version "1.00" #property description "Period Extreme indicator" #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 2 //--- plot UP #property indicator_label1 "UP" #property indicator_type1 DRAW_ARROW #property indicator_color1 clrGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot DN #property indicator_label2 "DN" #property indicator_type2 DRAW_ARROW #property indicator_color2 clrRed #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- input parameters input uint InpPeriod = 1; // Period //--- indicator buffers double BufferUP[]; double BufferDN[]; //--- global variables int period; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- set global variables period=int(InpPeriod<1 ? 1 : InpPeriod)-1; //--- indicator buffers mapping SetIndexBuffer(0,BufferUP,INDICATOR_DATA); SetIndexBuffer(1,BufferDN,INDICATOR_DATA); //--- setting a code from the Wingdings charset as the property of PLOT_ARROW PlotIndexSetInteger(0,PLOT_ARROW,159); PlotIndexSetInteger(1,PLOT_ARROW,159); //--- setting indicator parameters IndicatorSetString(INDICATOR_SHORTNAME,"Period Extreme ("+(string)period+")"); IndicatorSetInteger(INDICATOR_DIGITS,Digits()); //--- setting buffer arrays as timeseries ArraySetAsSeries(BufferUP,true); ArraySetAsSeries(BufferDN,true); //--- 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[]) { //--- Установка массивов буферов как таймсерий ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(close,true); //--- Проверка и расчёт количества просчитываемых баров if(rates_total1) { limit=rates_total-period-2; ArrayInitialize(BufferUP,EMPTY_VALUE); ArrayInitialize(BufferDN,EMPTY_VALUE); } //--- Расчёт индикатора for(int i=limit; i>=0 && !IsStopped(); i--) { int bl=Lowest(period+1,i+1); int bh=Highest(period+1,i+1); if(bl==WRONG_VALUE || bh==WRONG_VALUE) continue; double min=low[bl]; double max=high[bh]; BufferUP[i]=EMPTY_VALUE; BufferDN[i]=EMPTY_VALUE; if(close[i]>max) BufferUP[i]=max; else if(close[i]