//+------------------------------------------------------------------+
//|                                                       SIXTHS.mq4 |
//|                                                      Magnumfreak |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Magnumfreak"
#property link      ""
#property version "1.1"
#property indicator_chart_window
#property description "Bruster400 mods:"
#property description "Shift set to 1 to remove zoom effects"
#property description "Added TradeZoneBoxes"

/* NOTES:
version 1.1 corrected pipMultTab values to work with cfd's with Digits==1.
*/

extern int BarCount = 150; 
extern bool ShowFutureLines = false;
extern bool ShowEndLine = false;
extern bool ShowTradeZoneBoxes = false;
extern color SellZoneClr = clrLightSalmon;
extern color BuyZoneClr = clrSkyBlue;

double pip;// Points for 1 pip;
int pipMult;//pip-to-Points multiplier;
int pipMultTab[]={1,1,1,10,1,10,100}; // multiplier to convert pips to Points;

string prefix = "Indi-Sixth";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  pipMult = pipMultTab[Digits];
  pip     = pipMult*Point;
//---- indicators
   //int shift = MathMax(WindowFirstVisibleBar()-WindowBarsPerChart()*0.8,0);
   int shift = 1;

   DrawSixthsLines(BarCount, shift);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   DeleteSixthsLines();
   Comment("");
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int bars_count = WindowBarsPerChart();
   if (BarCount==0) BarCount = WindowBarsPerChart();

   //int shift = MathMax(WindowFirstVisibleBar()-WindowBarsPerChart()*0.8,0);
   int shift = 1;
   DrawSixthsLines(BarCount, shift);
   
   
   return(0);
  }


    //+------------------------------------------------------------------+
   
    //+------------------------------------------------------------------+
 void DrawSixthsLines(int _BarCount, int shift)
    {
      double high = High[iHighest(NULL,0,MODE_HIGH,_BarCount,shift)];
      double low  = Low[iLowest(NULL,0,MODE_LOW,_BarCount,shift)];
   
      double value = high-low;      //value top of the chart - value buttom
      double sixth = value/6;
      double seventh = value/7;
      double valueS = value/pip;
      double sixthS = sixth/pip;
      double seventhS = seventh/pip;
   
      DeleteSixthsLines();
      color SixthsColor[] = {clrRoyalBlue,clrCornflowerBlue,clrSkyBlue,clrSlateGray,clrSkyBlue,clrCornflowerBlue,clrRoyalBlue};
      for (int i=0;i<=6;i++) {
        ObjectCreate(prefix+i,OBJ_TREND,0,Time[shift],low+i*sixth,Time[shift+(_BarCount/6)],low+i*sixth);
        ObjectSet(prefix+i,OBJPROP_COLOR,SixthsColor[i]);
        ObjectSet(prefix+i,OBJPROP_STYLE,STYLE_SOLID);
        ObjectSet(prefix+i,OBJPROP_WIDTH,2);
        ObjectSet(prefix+i,OBJPROP_RAY,false);
      
      //draw dashed lines as "future continuation" of Sixth Lines
      
      if(ShowFutureLines)
        {

        ObjectCreate(prefix+"Future"+i,OBJ_TREND,0,Time[shift],low+i*sixth,Time[shift]+_BarCount/4*Period()*60,low+i*sixth);
        ObjectSet(prefix+"Future"+i,OBJPROP_COLOR,SixthsColor[i]);
        ObjectSet(prefix+"Future"+i,OBJPROP_STYLE,STYLE_DASH);
        ObjectSet(prefix+"Future"+i,OBJPROP_RAY,false);
        }
      }
      
      // draw a filled box for the buy and sell zones
 
   if(ShowTradeZoneBoxes && !ShowFutureLines){
   ObjectCreate("buyzone", OBJ_RECTANGLE,0,Time[shift],low,Time[shift+(_BarCount/6)],low+sixth);
   ObjectSet("buyzone", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet("buyzone", OBJPROP_COLOR, BuyZoneClr);
   //ObjectSet("buyzone", OBJPROP_BACK, True);
   
   ObjectCreate("sellzone", OBJ_RECTANGLE,0,Time[shift],low+5*sixth,Time[shift+(_BarCount/6)],low+6*sixth);
   ObjectSet("sellzone", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet("sellzone", OBJPROP_COLOR,SellZoneClr);
   //ObjectSet("sellzone", OBJPROP_BACK, True);
      }
      
    if(ShowTradeZoneBoxes && ShowFutureLines){
   ObjectCreate("buyzone", OBJ_RECTANGLE,0,Time[shift]+_BarCount/4*Period()*60,low,Time[shift+(_BarCount/6)],low+sixth);
   ObjectSet("buyzone", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet("buyzone", OBJPROP_COLOR, BuyZoneClr);
   //ObjectSet("buyzone", OBJPROP_BACK, True);
   
   ObjectCreate("sellzone", OBJ_RECTANGLE,0,Time[shift]+_BarCount/4*Period()*60,low+5*sixth,Time[shift+(_BarCount/6)],low+6*sixth);
   ObjectSet("sellzone", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet("sellzone", OBJPROP_COLOR,SellZoneClr);
   //ObjectSet("sellzone", OBJPROP_BACK, True);
      }  
      
      if(ShowEndLine)
        {
      // draw a vertical line at the anchor point of the SixthLines
      ObjectCreate(prefix+"AnchorTime",OBJ_VLINE,0,Time[shift],0);
      ObjectSet(prefix+"AnchorTime",OBJPROP_COLOR,clrSlateGray);
      ObjectSet(prefix+"AnchorTime",OBJPROP_STYLE,STYLE_DOT);
         }
       Comment("Top to bottom = ", (valueS), " pips", "\n" ,"Distance between lines = ", (sixthS), " pips" , 
           "\n" ,"TAKE PROFIT DISTANCE = ", (seventhS), " pips");

    }

    void DeleteSixthsLines()
    {
      for (int i=0;i<=6;i++) {
        ObjectDelete(prefix+i);
        ObjectDelete(prefix+"Future"+i);
      }
      ObjectDelete(prefix+"AnchorTime");
      ObjectDelete("buyzone");
      ObjectDelete("sellzone");
      
    }
    
/*
    //+------------------------------------------------------------------+
    void DrawSixthsFibs(int BarCount, int shift)
    //+------------------------------------------------------------------+
    {
      double high = High[iHighest(NULL,0,MODE_HIGH,BarCount,shift)];
      double low  = Low[iLowest(NULL,0,MODE_LOW,BarCount,shift)];
   
      double value = high-low;      //value top of the chart - value buttom
      double sixth = value/6;

      // draw "fib" lines for entry+stop+TP levels:
      ObjectDelete(prefix);
      ObjectCreate(prefix,OBJ_FIBO,0,Time[shift+BarCount],low+1*sixth,Time[shift],low+0*sixth);
      ObjectSet(prefix,OBJPROP_RAY,false);
      ObjectSet(prefix,OBJPROP_LEVELCOLOR,clrSlateGray); 
      ObjectSet(prefix,OBJPROP_FIBOLEVELS,7);
      ObjectSet(prefix,OBJPROP_LEVELSTYLE,STYLE_DASH);
      for (int i=0;i<=6;i++) {
        ObjectSet(prefix,OBJPROP_FIRSTLEVEL+i,i);
        ObjectSetFiboDescription(prefix,i,"%$");
      }
    }
*/
    
//+------------------------------------------------------------------+