//+------------------------------------------------------------------+ //| HLR.mq4 | //| Copyright © 2007, Alexandre | //| http://www.kroufr.ru/content/view/1184/124/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Alexandre" #property link "http://www.kroufr.ru/content/view/1184/124/" //---- #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 clrLimeGreen #property indicator_width1 2 #property strict // // // input int HLR_Range = 40; // High/Low Range period input double LevelUp = 80; // Overbought level input double LevelDn = 20; // Oversold level input ENUM_LINE_STYLE levSty = STYLE_DOT; // Levels style input color levClr = clrSilver; // Levels color double val[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0,val,INDICATOR_DATA); SetIndexStyle(0,DRAW_LINE); IndicatorSetDouble(INDICATOR_MINIMUM,0); IndicatorSetDouble(INDICATOR_MAXIMUM,100); IndicatorSetInteger(INDICATOR_LEVELS,3); IndicatorSetDouble( INDICATOR_LEVELVALUE,0,LevelDn); IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,levSty); IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,levClr); IndicatorSetDouble( INDICATOR_LEVELVALUE,1,50); IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,levSty); IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,levClr); IndicatorSetDouble( INDICATOR_LEVELVALUE,2,LevelUp); IndicatorSetInteger(INDICATOR_LEVELSTYLE,2,levSty); IndicatorSetInteger(INDICATOR_LEVELCOLOR,2,levClr); IndicatorSetString(INDICATOR_SHORTNAME,"Range Oscillator (" + (string)HLR_Range + ")"); 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 i=rates_total-prev_calculated+1; if (i>=rates_total) i=rates_total-1; // // // for (; i>=0 && !_StopFlag; i--) { double hhv = high[ArrayMaximum(high,HLR_Range,i)]; double llv = low [ArrayMinimum(low ,HLR_Range,i)]; double rng = (high[i]+low[i])*0.50; val[i] = (hhv!=llv) ? 100*(rng-llv)/(hhv-llv) : 0; } return(rates_total); }