//+------------------------------------------------------------------+
//|                                                     mn Fxcba.mq4 |
//+------------------------------------------------------------------+
// luna2010 modified the original "mn Fxcba" code to just see 
//  the Daily High and Low on Renko charts
// reduced buffers from 6 to 2 and hid unneeded instructions using //
// and changed TimeFrame from 60 to 1440(=Day) and mBars from 3 to 1

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
//#property indicator_color3 Lime
//#property indicator_color4 Orange
//#property indicator_color5 White
//#property indicator_color6 Yellow

#property indicator_width1 0
#property indicator_width2 0
//#property indicator_width3 2
//#property indicator_width4 2
//#property indicator_width5 2
//#property indicator_width6 2
#property indicator_style1 0
#property indicator_style2 0

extern int TimeFrame = 1440;
extern int Shift = 0;

double UpBuffer[];
double DnBuffer[];
double OpenBuffer[];
double CloseBuffer[];
double HighestClose[];
double LowestClose[];

//+------------------------------------------------------------------+
int init()
{
string short_name;

SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,UpBuffer);
SetIndexLabel(0,"High");
SetIndexDrawBegin(0,0);

SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,DnBuffer);
SetIndexLabel(1,"Low");
SetIndexDrawBegin(1,0);

//SetIndexStyle(2,DRAW_LINE);
//SetIndexBuffer(2,OpenBuffer);
//SetIndexLabel(2,"Open");
//SetIndexDrawBegin(2,0);

//SetIndexStyle(3,DRAW_LINE);
//SetIndexBuffer(3,CloseBuffer);
//SetIndexLabel(3,"Close");
//SetIndexDrawBegin(3,0);

//SetIndexStyle(4,DRAW_LINE);
//SetIndexBuffer(4,HighestClose);
//SetIndexLabel(4,"H_Close");
//SetIndexDrawBegin(4,0);

//SetIndexStyle(5,DRAW_LINE);
//SetIndexBuffer(5,LowestClose);
//SetIndexLabel(5,"L_Close");
//SetIndexDrawBegin(3,0);

SetIndexShift(0,Shift*TimeFrame/Period());
SetIndexShift(1,Shift*TimeFrame/Period());
//SetIndexShift(2,Shift*TimeFrame/Period());
//SetIndexShift(3,Shift*TimeFrame/Period());
//SetIndexShift(4,Shift*TimeFrame/Period());
//SetIndexShift(5,Shift*TimeFrame/Period());

short_name="Range_v2("+TimeFrame+") ";
IndicatorShortName(short_name);


switch(TimeFrame) 
{
   case 1 : TimeFrame=PERIOD_M1; break; 
   case 5 : TimeFrame=PERIOD_M5; break;
   case 15 : TimeFrame=PERIOD_M15; break;
   case 30 : TimeFrame=PERIOD_M30; break;
   case 60 : TimeFrame=PERIOD_H1; break;
   case 240 : TimeFrame=PERIOD_H4; break;
   case 1440 : TimeFrame=PERIOD_D1; break;
   case 7200 : TimeFrame=PERIOD_W1; break;
   case 28800: TimeFrame=PERIOD_MN1; break;
   default : TimeFrame=Period(); break;
}
return(0);
}

//+------------------------------------------------------------------+
int start()
{
datetime TimeArray[];
int i=0,y=0, prevy=0; 
int counted_bars=IndicatorCounted();
double LowArray[],HighArray[],OpenArray[],CloseArray[], mHclose, mLclose;


if (TimeFrame < Period()) 
{
 SetIndexDrawBegin(0,Bars); 
 SetIndexDrawBegin(1,Bars);
 Comment("Incorrect TimeFrame");
 return(0);
}

if ( counted_bars > 0 ) int limit=Bars-counted_bars+TimeFrame/Period();
if ( counted_bars < 0 ) return(0);
if ( counted_bars ==0 ) limit=Bars-1; 

ArrayCopySeries(TimeArray,MODE_TIME , Symbol(), TimeFrame);
ArrayCopySeries(LowArray,MODE_LOW, Symbol(), TimeFrame); 
ArrayCopySeries(HighArray,MODE_HIGH , Symbol(), TimeFrame);
ArrayCopySeries(OpenArray,MODE_OPEN , Symbol(), TimeFrame); 
ArrayCopySeries(CloseArray, MODE_CLOSE, Symbol(), TimeFrame);

  for(i = limit; i >= 0; i--)
   {
   int mShift = iBarShift(NULL, TimeFrame, Time[i], false);
   UpBuffer[i]=HighArray[mShift]; 
   DnBuffer[i]=LowArray[mShift];
   OpenBuffer[i]=OpenArray[mShift]; 
   CloseBuffer[i]=CloseArray[mShift];
   
    mHclose = 0; mLclose = 999;
   int z = iBarShift(NULL, 0, iTime(NULL, 1440, 0), false);
   for(int j = 0; j <= z;  j++)  
     {
       if(Close[j] > mHclose)
         mHclose = Close[j];
       if(Close[j] < mLclose)
         mLclose = Close[j];
     }
      HighestClose[i] = mHclose;
      LowestClose[i] = mLclose;
   } 
   
   return(0);
 }
//+------------------------------------------------------------------+