//------------------------------------------------------------------ #property copyright "© mladen, 2018" #property link "mladenfx@gmail.com" #property description "Higher Highs & Lower Lows" //------------------------------------------------------------------ #property indicator_separate_window #property indicator_buffers 4 #property indicator_plots 3 #property indicator_label1 "Fill zone" #property indicator_type1 DRAW_FILLING #property indicator_color1 C'235,255,235',C'255,235,235' #property indicator_label2 "HH value" #property indicator_type2 DRAW_LINE #property indicator_color2 clrMediumSeaGreen #property indicator_width2 2 #property indicator_label3 "LL value" #property indicator_type3 DRAW_LINE #property indicator_color3 clrOrangeRed #property indicator_width3 2 // //--- input parameters // input int inpPeriod = 20; // Period // //--- buffers declarations // double valhh[],valll[],fillu[],filld[]; double ª_alpha; //------------------------------------------------------------------ // Custom indicator initialization function //------------------------------------------------------------------ int OnInit() { // //--- indicator buffers mapping // SetIndexBuffer(0,fillu,INDICATOR_DATA); SetIndexBuffer(1,filld,INDICATOR_DATA); SetIndexBuffer(2,valhh,INDICATOR_DATA); SetIndexBuffer(3,valll,INDICATOR_DATA); ª_alpha = 2.0/(inpPeriod+1.0); // //--- indicator short name assignment // IndicatorSetString(INDICATOR_SHORTNAME,"Higher Highs & Lower Lows ("+(string)inpPeriod+")"); return (INIT_SUCCEEDED); } void OnDeinit(const int reason) { } //------------------------------------------------------------------ // 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[]) { int start= prev_calculated-1; if (start<0) start=0; for (int i=start; i0) { double _hhval = (high[i]>high[i-1]) ? 100*(high[i]-_hhmin)/(_hhmax-_hhmin) : 0; double _llval = (low[i] 0) ? forPeriod : 1; prevmin = valueMin; prevmax = valueMax; currmin = valueMin; currmax = valueMax; ArrayResize(minArray,period-1); ArrayInitialize(minArray,valueMin); ArrayResize(maxArray,period-1); ArrayInitialize(maxArray,valueMax); } if (period>1) { int _pos = (i) % (period-1); minArray[_pos] = currmin; maxArray[_pos] = currmax; prevmin = minArray[ArrayMinimum(minArray)]; prevmax = maxArray[ArrayMaximum(maxArray)]; } else { prevmin = valueMin; prevmax = valueMax; } } // // // currmin = valueMin; currmax = valueMax; max = (prevmax>valueMax) ? prevmax : valueMax; min = (prevmin