//+------------------------------------------------------------------+
//|                                           SIXTHS Floating SQ.mq4 |
//|                                                          Squalou |
//|                                                                  |
//+------------------------------------------------------------------+


//Draws the NNB Sixths lines for each bar.
//Auto bar count and sixths level calculation are pulled from the source of SIXTHS SCREEN VER 3.6_DC auto barCount


#property copyright "by Squalou"

#property indicator_chart_window

#property indicator_buffers 7
#property indicator_color1 Blue
#property indicator_color2 Orange //Gold
#property indicator_color3 Green
#property indicator_color4 Red //White
#property indicator_color5 Green
#property indicator_color6 Orange //Gold
#property indicator_color7 Blue
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 1

//+------------------------------------------------------------------+

//---- input parameters

extern int barCount = 0; // 0 will use the default values recommended by Macman

//+------------------------------------------------------------------+

double top[],topGold[],bottomGold[],center[],topGreen[],bottomGreen[],bottom[];

//+------------------------------------------------------------------+
int init()
//+------------------------------------------------------------------+
{
  IndicatorShortName("NNB Sixths Floating Lines");
   
  SetIndexBuffer(0, top);
  SetIndexBuffer(1, topGold);
  SetIndexBuffer(2, topGreen);
  SetIndexBuffer(3, center);
  SetIndexBuffer(4, bottomGreen);
  SetIndexBuffer(5, bottomGold);
  SetIndexBuffer(6, bottom);

  barCount = SixthsBarCount (barCount);
   
  return(0);
}

//+------------------------------------------------------------------+
int SixthsBarCount (int barCount)
//+------------------------------------------------------------------+
{
  double n = barCount;

  //auto bar count taken from MagnumFreak Sixths 3.6 w AutoBar count
  if (n == 0)
  {
    //Set up the barCount. H1 TF first. Default barcount set at 170
    string s = StringSubstr(Symbol(), 0, 6);
    if (s == "AUDCAD") { n = 170; }
    if (s == "AUDCHF") { n = 170; }
    if (s == "AUDJPY") { n = 170; }
    if (s == "AUDNZD") { n = 170; }
    if (s == "AUDSGD") { n = 170; }
    if (s == "AUDUSD") { n = 170; }
    if (s == "CADCHF") { n = 170; }
    if (s == "CADJPY") { n = 180; }
    if (s == "CHFJPY") { n = 170; }
    if (s == "CHFSGD") { n = 170; }
    if (s == "EURAUD") { n = 170; }
    if (s == "EURCAD") { n = 170; }
    if (s == "EURCHF") { n = 170; }
    if (s == "EURGBP") { n = 170; }
    if (s == "EURJPY") { n = 180; }
    if (s == "EURNZD") { n = 170; }
    if (s == "EURSGD") { n = 170; }
    if (s == "EURUSD") { n = 170; }
    if (s == "GBPAUD") { n = 170; }
    if (s == "GBPCAD") { n = 170; }
    if (s == "GBPCHF") { n = 170; }
    if (s == "GBPJPY") { n = 180; }
    if (s == "GBPUSD") { n = 155; }
    if (s == "NZDCAD") { n = 170; }
    if (s == "NZDCHF") { n = 170; }
    if (s == "NZDJPY") { n = 170; }
    if (s == "NZDUSD") { n = 170; }
    if (s == "SGDJPY") { n = 170; }
    if (s == "USDCAD") { n = 170; }
    if (s == "USDCHF") { n = 180; }
    if (s == "USDHKD") { n = 170; }
    if (s == "USDJPY") { n = 180; }
    if (s == "USDSGD") { n = 170; }
  
    //Now accommodate different time frames
    n *= PERIOD_H1;
    n /= Period();
  }

  return (n);
}
         
//+------------------------------------------------------------------+
int deinit()
//+------------------------------------------------------------------+
{
   return(0);
}

//+------------------------------------------------------------------+
int start()
//+------------------------------------------------------------------+
{  
  double ll,hh,sixth;
  
  int i;

   int counted_bars = IndicatorCounted();
//---- check for possible errors
   if(counted_bars < 0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars > 0) counted_bars--;

  for(i=Bars-counted_bars;i>=0;i--)
  {       
    //compute sixths level
    hh = High[iHighest(NULL, 0, MODE_HIGH, barCount, i)];
    ll = Low[iLowest(NULL, 0, MODE_LOW, barCount, i)];      
    sixth = (hh-ll) / 6;

    top[i]         = ll+6*sixth;
    topGold[i]     = ll+5*sixth;
    topGreen[i]    = ll+4*sixth;
    center[i]      = ll+3*sixth;
    bottomGreen[i] = ll+2*sixth;
    bottomGold[i]  = ll+1*sixth;
    bottom[i]      = ll;

  }
          
  return(0);

}

