Navigation´╝ÜHome > Content >

Range_Oscillator_-_mtf_nmc.mq4

Time: 2017-09-20 | Download file:Range_Oscillator_-_mtf_nmc.mq4

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 1 
#property indicator_width1  2
#property indicator_minimum 0 
#property indicator_maximum 100
#property indicator_color1  Red
#property indicator_level1  20
#property indicator_level2  50
#property indicator_level3  80
#property indicator_levelstyle STYLE_DASHDOT
#property indicator_levelcolor DimGray

//
//
//
//
//

extern string TimeFrame   = "Current time frame";
extern int    HLR_Range   = 40;
extern bool   Interpolate = true;

double HLR[];
string indicatorFileName;
int    timeFrame;
bool   returnBars;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   SetIndexBuffer(0,HLR); 
            indicatorFileName = WindowExpertName();
            returnBars        = (TimeFrame=="returnBars"); if (returnBars) return(0);
            timeFrame         = stringToTimeFrame(TimeFrame);
   IndicatorShortName(timeFrameToString(timeFrame)+" Range Oscillator (" + HLR_Range + ")"); 
   return(0);
}
int deinit() { return(0); }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
   int counted_bars=IndicatorCounted();
   int i,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = MathMin(Bars-counted_bars,Bars-1);
         if (returnBars) { HLR[0] = limit+1; return(0); }

   //
   //
   //
   //
   //

   if (timeFrame>Period()) limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));
   for(i=limit; i>=0; i--)
   {
      int y = iBarShift(NULL,timeFrame,Time[i]);
          double hhv = iHigh(NULL,timeFrame,iHighest(NULL,timeFrame,MODE_HIGH,HLR_Range,y));
          double llv = iLow(NULL,timeFrame,iLowest(NULL,timeFrame,MODE_LOW,HLR_Range,y)); 
          double mpr = (iHigh(NULL,timeFrame,y) + iLow(NULL,timeFrame,y)) / 2.0; 
          if(hhv!=llv)
               HLR[i] = 100.0 * (mpr-llv)/(hhv-llv); 
          else HLR[i] = 0.0; 
          
         //
         //
         //
         //
         //
      
         if (timeFrame<=Period() || !Interpolate || y==iBarShift(NULL,timeFrame,Time[i-1])) continue;

         //
         //
         //
         //
         //

         datetime time = iTime(NULL,timeFrame,y);
            for(int n = 1; i+n < Bars && Time[i+n] >= time; n++) continue;	
            for(int k = 1; k < n; k++)
               HLR[i+k] = HLR[i] + (HLR[i+n]-HLR[i])*k/n;
          
   } 
   return(0);
}

//+-------------------------------------------------------------------
//|                                                                  
//+-------------------------------------------------------------------
//
//
//
//
//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//
//
//
//
//

int stringToTimeFrame(string tfs)
{
   tfs = stringUpperCase(tfs);
   for (int i=ArraySize(iTfTable)-1; i>=0; i--)
         if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period()));
                                                      return(Period());
}
string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}

//
//
//
//
//

string stringUpperCase(string str)
{
   string   s = str;

   for (int length=StringLen(str)-1; length>=0; length--)
   {
      int tchar = StringGetChar(s, length);
         if((tchar > 96 && tchar < 123) || (tchar > 223 && tchar < 256))
                     s = StringSetChar(s, length, tchar - 32);
         else if(tchar > -33 && tchar < 0)
                     s = StringSetChar(s, length, tchar + 224);
   }
   return(s);
}

Recommend