//+--------------------------------------------------------------------+
//|   cm_WaterLevelDD                                  WaterLevel.mq4  |
//|                                         Original concept by Brijon |
//|                  Ideas and helps by NorthPro, Pipo, Walter, Charvo |
//|                                              Coded by Pacific_trip |
//|                         "Magnified Market Price" feature by Habeeb |
//|                          Static buy/sell lines by Skyline & Hornet |
//|              Many thanks to ForexFactory members for their support |
//+--------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 4

#property indicator_color1 Gold
#property indicator_width1 2
#property indicator_color2 GreenYellow
#property indicator_width2 2

extern bool   Sound.Alert    = false ;
extern bool   Show.PriceBox  = true ;
extern int    myBoxWidth  = 3;

extern bool   Show.Lines     = true ;
extern double Line1_PipDiff  = 50 ;
extern double Line1_Style    = STYLE_DASH ;
extern color  Line1_Color    = LimeGreen ;
extern double Line2_PipDiff  = -50 ;
extern int    Line2_Style    = STYLE_DASH ;
extern color  Line2_Color    = OrangeRed ;
 


extern string Time_Frame_value = "TimeFrame(0,M5,M15,M30,H1,H4,D1,W1,MN1)";
extern string Time_Frame = "D1";

extern int Calculate_From_Previous_Bar = 0;
extern bool Dynamic_BuySell_Price = true;

extern bool Show_Magnified_WL_Price = true;
extern int Magnified_WL_Price_Corner = 1
;
extern string note2 = "Default Font Color";
extern color  FontColor = SteelBlue;
extern string note3 = "Font Size";
extern int FontSize=14;
extern string note4 = "Font Type";
extern string FontType="Tahoma";

extern bool Show_Comment = false;
extern bool Show_MAs = false;
extern int Period_MA1 = 5;
extern int Period_MA2 = 7;
extern int Period_MA3 = 22;
extern int Period_MA4 = 34;

extern string MA_Type_value = "SMA, EMA, LWMA";
extern string MA_Type = "SMA";

double TimeFrame1CloseAverageMA1, TimeFrame1CloseAverageMA2, TimeFrame1CloseAverageMA3, TimeFrame1CloseAverageMA4;
double TimeFrame2CloseAverageMA1, TimeFrame2CloseAverageMA2, TimeFrame2CloseAverageMA3, TimeFrame2CloseAverageMA4;

double TimeFrame1HighestHighMA1, TimeFrame1LowestLowMA1, TimeFrame2HighestHighMA1, TimeFrame2LowestLowMA1;
double TimeFrame1HighestHighMA2, TimeFrame1LowestLowMA2, TimeFrame2HighestHighMA2, TimeFrame2LowestLowMA2;
double TimeFrame1HighestHighMA3, TimeFrame1LowestLowMA3, TimeFrame2HighestHighMA3, TimeFrame2LowestLowMA3;
double TimeFrame1HighestHighMA4, TimeFrame1LowestLowMA4, TimeFrame2HighestHighMA4, TimeFrame2LowestLowMA4;

double TimeFrame1HighestHighAverage, TimeFrame1LowestLowAverage;
double TimeFrame2HighestHighAverage, TimeFrame2LowestLowAverage;

double TimeFrame1HHLLAverageMA1, TimeFrame2HHLLAverageMA1;
double TimeFrame1HHLLAverageMA2, TimeFrame2HHLLAverageMA2;
double TimeFrame1HHLLAverageMA3, TimeFrame2HHLLAverageMA3;
double TimeFrame1HHLLAverageMA4, TimeFrame2HHLLAverageMA4;

double TimeFrame1HHLLAverages, TimeFrame2HHLLAverages;
double TimeFrame2AverageMA1[], TimeFrame2AverageMA2[], TimeFrame2AverageMA3[], TimeFrame2AverageMA4[];

double TimeFrame1Level[], TimeFrame2Level[];
double SellPrice[], BuyPrice[];

int timeFrame1, timeFrame2, maType;
string TimeFrame1String, TimeFrame2String;

int lastBarTime = -1;
double lastBarClose = 0;
string InfoDisplay = "";

string linename2  = "cmLine2" ;
string linename1 = "cmLine1" ;

double linelevel1[], linelevel2[];

string symbol, tChartPeriod,  tShortName ;  
int    digits, period  ; 

datetime Trigger ;

int OldBars = -1 ;

color tColor = Yellow ;
//-----------------------------------------------------------------------

int init() {

   period       = Period() ;     
   tChartPeriod =  TimeFrameToString(period) ;
   symbol       =  Symbol() ;
   digits       =  Digits ;   

   tShortName = "cmwldd"+ symbol + tChartPeriod  ;


Line1_PipDiff = Line1_PipDiff * Point ;
Line2_PipDiff = Line2_PipDiff * Point ;


   if (Time_Frame == "M1") {

      timeFrame1 = PERIOD_M1;
      TimeFrame1String = "M1";

   } else if (Time_Frame == "M5") {

      timeFrame1 = PERIOD_M5;
      TimeFrame1String = "M5";

   } else if (Time_Frame == "M15") {

      timeFrame1 = PERIOD_M15;
      TimeFrame1String = "M15";

   } else if (Time_Frame == "M30") {

      timeFrame1 = PERIOD_M30;
      TimeFrame1String = "M30";

   } else if (Time_Frame == "H1") {

      timeFrame1 = PERIOD_H1;
      TimeFrame1String = "H1";

   } else if (Time_Frame == "H4") {

      timeFrame1 = PERIOD_H4;
      TimeFrame1String = "H4";

   } else if (Time_Frame == "D1") {

      timeFrame1 = PERIOD_D1;
      TimeFrame1String = "D1";

   } else if (Time_Frame == "W1") {

      timeFrame1 = PERIOD_W1;
      TimeFrame1String = "W1";

   } else if (Time_Frame == "MN1") {

      timeFrame1 = PERIOD_MN1;
      TimeFrame1String = "MN1";

   } else {

      timeFrame1 = 0;

   }
   
   timeFrame2 = Period();
   
   if (timeFrame2 == PERIOD_M1) {
   
      TimeFrame2String = "M1";
   
   } else if (timeFrame2 == PERIOD_M5) {

      TimeFrame2String = "M5";
   
   } else if (timeFrame2 == PERIOD_M15) {

      TimeFrame2String = "M15";
   
   } else if (timeFrame2 == PERIOD_M30) {

      TimeFrame2String = "M30";
   
   } else if (timeFrame2 == PERIOD_H1) {

      TimeFrame2String = "H1";
   
   } else if (timeFrame2 == PERIOD_H4) {

      TimeFrame2String = "H4";
   
   } else if (timeFrame2 == PERIOD_D1) {

      TimeFrame2String = "D1";
   
   } else if (timeFrame2 == PERIOD_W1) {

      TimeFrame2String = "W1";
   
   } else if (timeFrame2 == PERIOD_MN1) {

      TimeFrame2String = "MN1";
   
   }

   if (MA_Type == "SMA") {

      maType = MODE_SMA;

   } else if (MA_Type == "EMA") {

      maType = MODE_EMA;

   } else if (MA_Type == "LWMA") {

      maType = MODE_LWMA;

   } else {

      maType = MODE_SMA;

   }

   if (timeFrame1 < timeFrame2) {

      Alert("The timeframe must be higher than the current");
      deinit();

   }


   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,TimeFrame1Level);
   SetIndexLabel(0,TimeFrame1String + " Level");
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,TimeFrame2Level);
   SetIndexLabel(1,TimeFrame2String + " Level");


if( Show.Lines )
{
   SetIndexStyle(2,DRAW_LINE,Line1_Style, 1, Line1_Color);
   SetIndexBuffer(2,linelevel1);
//   SetIndexLabel(2,TimeFrame1String + " Level " );
   SetIndexStyle(3,DRAW_LINE,Line2_Style, 1, Line2_Color);
   SetIndexBuffer(3,linelevel2);
//   SetIndexLabel(3,TimeFrame2String + " Level");

} // if( Show.Lines )


      return(0);

}

//-----------------------------------------------------------------------

int deinit() 
{
   ObjectsDeleteAll(0);    
   return(0);

}

//-----------------------------------------------------------------------

int start() {

   int i, idx, counted_bars = IndicatorCounted();
   i = Bars - counted_bars - 1;
   double sum = 0;

   while (i >= 0) {
   
      int timeFrame1Index = iBarShift(0, timeFrame1, Time[i], true);

      // Calculate all values for timeframe1 which is greater than the timeframe1
      // Runs only once every timeframe1 bar
      if (lastBarTime != iTime(NULL, timeFrame1, timeFrame1Index)) {

         lastBarTime = iTime(NULL, timeFrame1, timeFrame1Index);

         // Averages of the selected timeframe
         TimeFrame1CloseAverageMA1 = iMA(NULL, timeFrame1, Period_MA1, 0, maType, PRICE_CLOSE, timeFrame1Index+Calculate_From_Previous_Bar);
         TimeFrame1CloseAverageMA2 = iMA(NULL, timeFrame1, Period_MA2, 0, maType, PRICE_CLOSE, timeFrame1Index+Calculate_From_Previous_Bar);
         TimeFrame1CloseAverageMA3 = iMA(NULL, timeFrame1, Period_MA3, 0, maType, PRICE_CLOSE, timeFrame1Index+Calculate_From_Previous_Bar);
         TimeFrame1CloseAverageMA4 = iMA(NULL, timeFrame1, Period_MA4, 0, maType, PRICE_CLOSE, timeFrame1Index+Calculate_From_Previous_Bar);

         // Highest Highs and Lowest Lows Averages of the selected timeframe
         TimeFrame1HighestHighMA1 = iHigh(NULL, timeFrame1, iHighest(NULL, timeFrame1, MODE_HIGH, Period_MA1, timeFrame1Index+Calculate_From_Previous_Bar));
         TimeFrame1LowestLowMA1 = iLow(NULL, timeFrame1, iLowest(NULL, timeFrame1, MODE_LOW, Period_MA1, timeFrame1Index+Calculate_From_Previous_Bar));

         TimeFrame1HighestHighMA2 = iHigh(NULL, timeFrame1, iHighest(NULL, timeFrame1, MODE_HIGH, Period_MA2, timeFrame1Index+Calculate_From_Previous_Bar));
         TimeFrame1LowestLowMA2 = iLow(NULL, timeFrame1, iLowest(NULL, timeFrame1, MODE_LOW, Period_MA2, timeFrame1Index+Calculate_From_Previous_Bar));

         TimeFrame1HighestHighMA3 = iHigh(NULL, timeFrame1, iHighest(NULL, timeFrame1, MODE_HIGH, Period_MA3, timeFrame1Index+Calculate_From_Previous_Bar));
         TimeFrame1LowestLowMA3 = iLow(NULL, timeFrame1, iLowest(NULL, timeFrame1, MODE_LOW, Period_MA3, timeFrame1Index+Calculate_From_Previous_Bar));

         TimeFrame1HighestHighMA4 = iHigh(NULL, timeFrame1, iHighest(NULL, timeFrame1, MODE_HIGH, Period_MA4, timeFrame1Index+Calculate_From_Previous_Bar));
         TimeFrame1LowestLowMA4 = iLow(NULL, timeFrame1, iLowest(NULL, timeFrame1, MODE_LOW, Period_MA4, timeFrame1Index+Calculate_From_Previous_Bar));

         // HH-LL averages of the selected timeframe
         TimeFrame1HHLLAverageMA1 = TimeFrame1HighestHighMA1 - TimeFrame1LowestLowMA1;
         TimeFrame1HHLLAverageMA2 = TimeFrame1HighestHighMA2 - TimeFrame1LowestLowMA2;
         TimeFrame1HHLLAverageMA3 = TimeFrame1HighestHighMA3 - TimeFrame1LowestLowMA3;
         TimeFrame1HHLLAverageMA4 = TimeFrame1HighestHighMA4 - TimeFrame1LowestLowMA4;
         
         if (Dynamic_BuySell_Price == false) {

            // Highest Highs and Lowest Lows Averages of the currently displayed timeframe
            TimeFrame2HighestHighMA1 = High[iHighest(NULL, 0, MODE_HIGH, Period_MA1, i+Calculate_From_Previous_Bar)];
            TimeFrame2LowestLowMA1 = Low[iLowest(NULL, 0, MODE_LOW, Period_MA1, i+Calculate_From_Previous_Bar)];

            TimeFrame2HighestHighMA2 = High[iHighest(NULL, 0, MODE_HIGH, Period_MA2, i+Calculate_From_Previous_Bar)];
            TimeFrame2LowestLowMA2 = Low[iLowest(NULL, 0, MODE_LOW, Period_MA2, i+Calculate_From_Previous_Bar)];

            TimeFrame2HighestHighMA3 = High[iHighest(NULL, 0, MODE_HIGH, Period_MA3, i+Calculate_From_Previous_Bar)];
            TimeFrame2LowestLowMA3 = Low[iLowest(NULL, 0, MODE_LOW, Period_MA3, i+Calculate_From_Previous_Bar)];

            TimeFrame2HighestHighMA4 = High[iHighest(NULL, 0, MODE_HIGH, Period_MA4, i+Calculate_From_Previous_Bar)];
            TimeFrame2LowestLowMA4 = Low[iLowest(NULL, 0, MODE_LOW, Period_MA4, i+Calculate_From_Previous_Bar)];

         }

      }

      lastBarClose = iClose(NULL, timeFrame1,timeFrame1Index+1);

      if (Dynamic_BuySell_Price == true) {

         // Highest Highs and Lowest Lows Averages of the currently displayed timeframe
         TimeFrame2HighestHighMA1 = High[iHighest(NULL, 0, MODE_HIGH, Period_MA1, i+Calculate_From_Previous_Bar)];
         TimeFrame2LowestLowMA1 = Low[iLowest(NULL, 0, MODE_LOW, Period_MA1, i+Calculate_From_Previous_Bar)];

         TimeFrame2HighestHighMA2 = High[iHighest(NULL, 0, MODE_HIGH, Period_MA2, i+Calculate_From_Previous_Bar)];
         TimeFrame2LowestLowMA2 = Low[iLowest(NULL, 0, MODE_LOW, Period_MA2, i+Calculate_From_Previous_Bar)];

         TimeFrame2HighestHighMA3 = High[iHighest(NULL, 0, MODE_HIGH, Period_MA3, i+Calculate_From_Previous_Bar)];
         TimeFrame2LowestLowMA3 = Low[iLowest(NULL, 0, MODE_LOW, Period_MA3, i+Calculate_From_Previous_Bar)];

         TimeFrame2HighestHighMA4 = High[iHighest(NULL, 0, MODE_HIGH, Period_MA4, i+Calculate_From_Previous_Bar)];
         TimeFrame2LowestLowMA4 = Low[iLowest(NULL, 0, MODE_LOW, Period_MA4, i+Calculate_From_Previous_Bar)];

      }

      // HH-LL averages of the currently displayed timeframe
      TimeFrame2HHLLAverageMA1 = TimeFrame2HighestHighMA1 - TimeFrame2LowestLowMA1;
      TimeFrame2HHLLAverageMA2 = TimeFrame2HighestHighMA2 - TimeFrame2LowestLowMA2;
      TimeFrame2HHLLAverageMA3 = TimeFrame2HighestHighMA3 - TimeFrame2LowestLowMA3;
      TimeFrame2HHLLAverageMA4 = TimeFrame2HighestHighMA4 - TimeFrame2LowestLowMA4;
         
      // Averages of the currently displayed timeframe
      TimeFrame2CloseAverageMA1 = iMA(NULL, 0, Period_MA1, 0, maType, PRICE_CLOSE, i+Calculate_From_Previous_Bar);
      TimeFrame2CloseAverageMA2 = iMA(NULL, 0, Period_MA2, 0, maType, PRICE_CLOSE, i+Calculate_From_Previous_Bar);
      TimeFrame2CloseAverageMA3 = iMA(NULL, 0, Period_MA3, 0, maType, PRICE_CLOSE, i+Calculate_From_Previous_Bar);
      TimeFrame2CloseAverageMA4 = iMA(NULL, 0, Period_MA4, 0, maType, PRICE_CLOSE, i+Calculate_From_Previous_Bar);
      
      if (Symbol() == "GBPUSD") {

         TimeFrame1Level[i] = (TimeFrame1CloseAverageMA1 + TimeFrame1CloseAverageMA2 + TimeFrame1CloseAverageMA3 + TimeFrame1CloseAverageMA4) / 4;
         TimeFrame2Level[i] = (TimeFrame2CloseAverageMA1 + TimeFrame2CloseAverageMA2 + TimeFrame2CloseAverageMA3 + TimeFrame2CloseAverageMA4) / 4;
         
         TimeFrame1HighestHighAverage = (TimeFrame1HighestHighMA1 + TimeFrame1HighestHighMA2 + TimeFrame1HighestHighMA3 + TimeFrame1HighestHighMA4) / 4;
         TimeFrame1LowestLowAverage = (TimeFrame1LowestLowMA1 + TimeFrame1LowestLowMA2 + TimeFrame1LowestLowMA3 + TimeFrame1LowestLowMA4) / 4;
         
         TimeFrame2HighestHighAverage = (TimeFrame2HighestHighMA1 + TimeFrame2HighestHighMA2 + TimeFrame2HighestHighMA3 + TimeFrame2HighestHighMA4) / 4;
         TimeFrame2LowestLowAverage = (TimeFrame2LowestLowMA1 + TimeFrame2LowestLowMA2 + TimeFrame2LowestLowMA3 + TimeFrame2LowestLowMA4) / 4;
         
         InfoDisplay = "*********** " + TimeFrame1String + " Levels ***********\n" + MA_Type + " Period(" + Period_MA1 + ")=" + TimeFrame1CloseAverageMA1 +
                      "\n" + MA_Type + " Period(" + Period_MA2 + ")=" + TimeFrame1CloseAverageMA2 +
                      "\n" + MA_Type + " Period(" + Period_MA3 + ")=" + TimeFrame1CloseAverageMA3 +
                      "\n" + MA_Type + " Period(" + Period_MA4 + ")=" + TimeFrame1CloseAverageMA4 +
                      "\nWaterLevel=" + TimeFrame1Level[i] +
                      "\n*********** " + TimeFrame2String + " Levels ***********\n" + MA_Type + " Period(" + Period_MA1 + ")=" + TimeFrame2CloseAverageMA1 +
                      "\n" + MA_Type + " Period(" + Period_MA2 + ")=" + TimeFrame2CloseAverageMA2 +
                      "\n" + MA_Type + " Period(" + Period_MA3 + ")=" + TimeFrame2CloseAverageMA3 +
                      "\n" + MA_Type + " Period(" + Period_MA4 + ")=" + TimeFrame2CloseAverageMA4 +
                      "\nWaterLevel=" + TimeFrame2Level[i];
				  
      } else {
      
         TimeFrame1Level[i] = (TimeFrame1CloseAverageMA1 + TimeFrame1CloseAverageMA2 + TimeFrame1CloseAverageMA3) / 3;
         TimeFrame2Level[i] = (TimeFrame2CloseAverageMA1 + TimeFrame2CloseAverageMA2 + TimeFrame2CloseAverageMA3) / 3;
         
         TimeFrame1HighestHighAverage = (TimeFrame1HighestHighMA1 + TimeFrame1HighestHighMA2 + TimeFrame1HighestHighMA3) / 3;
         TimeFrame1LowestLowAverage = (TimeFrame1LowestLowMA1 + TimeFrame1LowestLowMA2 + TimeFrame1LowestLowMA3) / 3;
         
         TimeFrame2HighestHighAverage = (TimeFrame2HighestHighMA1 + TimeFrame2HighestHighMA2 + TimeFrame2HighestHighMA3) / 3;
         TimeFrame2LowestLowAverage = (TimeFrame2LowestLowMA1 + TimeFrame2LowestLowMA2 + TimeFrame2LowestLowMA3) / 3;
         
         InfoDisplay = "*********** " + TimeFrame1String + " Levels ***********\n" + MA_Type + " Period(" + Period_MA1 + ")=" + TimeFrame1CloseAverageMA1 +
                      "\n" + MA_Type + " Period(" + Period_MA2 + ")=" + TimeFrame1CloseAverageMA2 +
                      "\n" + MA_Type + " Period(" + Period_MA3 + ")=" + TimeFrame1CloseAverageMA3 +
                      "\nWaterLevel=" + TimeFrame1Level[i] +
                      "\n*********** " + TimeFrame2String + " Levels ***********\n" + MA_Type + " Period(" + Period_MA1 + ")=" + TimeFrame2CloseAverageMA1 +
                      "\n" + MA_Type + " Period(" + Period_MA2 + ")=" + TimeFrame2CloseAverageMA2 +
                      "\n" + MA_Type + " Period(" + Period_MA3 + ")=" + TimeFrame2CloseAverageMA3 +
                      "\nWaterLevel=" + TimeFrame2Level[i];
     
      }
 
      TimeFrame1HHLLAverages = ((TimeFrame1HHLLAverageMA1 + TimeFrame1HHLLAverageMA2 + TimeFrame1HHLLAverageMA3 + TimeFrame1HHLLAverageMA4) / 4) / 4;
      TimeFrame2HHLLAverages = ((TimeFrame2HHLLAverageMA1 + TimeFrame2HHLLAverageMA2 + TimeFrame2HHLLAverageMA3 + TimeFrame2HHLLAverageMA4) / 4) / 4;
     
      if (Show_Comment == false) {

         InfoDisplay = "";

      }
      
      Comment(InfoDisplay);
      
      if (Show_Magnified_WL_Price == true){

         string Market_Price = DoubleToStr(Bid, Digits);
         string TimeFrame1WaterLevel = DoubleToStr((Bid - TimeFrame1Level[i]), Digits);
      //   string TimeFrame2WaterLevel = DoubleToStr(TimeFrame2Level[i], Digits);

         ObjectCreate("Market_Price_Label", OBJ_LABEL, 0, 0, 0);
         ObjectSetText("Market_Price_Label", "P=" + Market_Price, FontSize, FontType, FontColor);
         ObjectSet("Market_Price_Label", OBJPROP_CORNER, Magnified_WL_Price_Corner);
         ObjectSet("Market_Price_Label", OBJPROP_XDISTANCE, 5);
         ObjectSet("Market_Price_Label", OBJPROP_YDISTANCE, FontSize*3+10);

         ObjectCreate("TimeFrame1_Level_Label", OBJ_LABEL, 0, 0, 0);
         ObjectSetText("TimeFrame1_Level_Label", "dWLdist=" + TimeFrame1WaterLevel , FontSize, FontType, FontColor);
         ObjectSet("TimeFrame1_Level_Label", OBJPROP_CORNER, Magnified_WL_Price_Corner);
         ObjectSet("TimeFrame1_Level_Label", OBJPROP_XDISTANCE, 5);
         ObjectSet("TimeFrame1_Level_Label", OBJPROP_YDISTANCE, FontSize*2+5);


     //    ObjectCreate("TimeFrame2_Level_Label", OBJ_LABEL, 0, 0, 0);
     //    ObjectSetText("TimeFrame2_Level_Label", TimeFrame2String + " WL=" + TimeFrame2WaterLevel, FontSize, FontType, FontColor);
     //    ObjectSet("TimeFrame2_Level_Label", OBJPROP_CORNER, Magnified_WL_Price_Corner);
     //    ObjectSet("TimeFrame2_Level_Label", OBJPROP_XDISTANCE, 5);
     //    ObjectSet("TimeFrame2_Level_Label", OBJPROP_YDISTANCE, FontSize);

      } else {

         ObjectDelete("Market_Price_Label");
         ObjectDelete("TimeFrame1_Level_Label");
         ObjectDelete("TimeFrame2_Level_Label");

      }

      SellPrice[i] = lastBarClose + (TimeFrame1HHLLAverages - TimeFrame2HHLLAverages);
      BuyPrice[i] = lastBarClose - (TimeFrame1HHLLAverages - TimeFrame2HHLLAverages);
      
      if (Show_MAs) 
      {

         TimeFrame2AverageMA1[i] = TimeFrame2CloseAverageMA1;
         TimeFrame2AverageMA2[i] = TimeFrame2CloseAverageMA2;
         TimeFrame2AverageMA3[i] = TimeFrame2CloseAverageMA3;
         TimeFrame2AverageMA4[i] = TimeFrame2CloseAverageMA4;
         
      }

      TimeFrame2AverageMA1[i] = (SellPrice[i] + BuyPrice[i]) / 2;

      linelevel1[i] = TimeFrame1Level[i] + Line1_PipDiff ;
      linelevel2[i] = TimeFrame1Level[i] + Line2_PipDiff ;  
      
      i--;

   }



      if ( Trigger != Time[0] &&  Sound.Alert ) 
      {
        if( Close[0] == linelevel1[0] ) { Trigger = Time[0] ; Alert(symbol,"  ", tChartPeriod, " Price touched Line01 "+ DoubleToStr(linelevel1[0] ,digits)); }
        if( Close[0] == linelevel2[0] ) { Trigger = Time[0] ; Alert(symbol,"  ", tChartPeriod, " Price touched Line02 "+ DoubleToStr(linelevel2[0] ,digits)); }     
      }

   if(Show.PriceBox) { DoBox() ; }
   
   return(0);
}
//+------------------------------------------------------------------+


void DoBox()    
{


       if (ObjectFind(tShortName+"01") != 0)
      {
          ObjectCreate(tShortName+"01",OBJ_ARROW,0,Time[0],linelevel1[0]);
          ObjectSet(tShortName+"01",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"01",OBJPROP_COLOR,Line1_Color);  
          ObjectSet(tShortName+"01",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"01",0,Time[0],linelevel1[0]);
         ObjectSet(tShortName+"01",OBJPROP_COLOR,Line1_Color);  
      }

       if (ObjectFind(tShortName+"02") != 0)
      {
          ObjectCreate(tShortName+"02",OBJ_ARROW,0,Time[0],linelevel2[0]);
          ObjectSet(tShortName+"02",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"02",OBJPROP_COLOR,Line2_Color);  
          ObjectSet(tShortName+"02",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"02",0,Time[0],linelevel2[0]);
         ObjectSet(tShortName+"02",OBJPROP_COLOR,Line2_Color);  
      }
 


       if (ObjectFind(tShortName+"03") != 0)
      {
          ObjectCreate(tShortName+"03",OBJ_ARROW,0,Time[0],TimeFrame1Level[0]);
          ObjectSet(tShortName+"03",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"03",OBJPROP_COLOR,indicator_color1);  
          ObjectSet(tShortName+"03",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"03",0,Time[0],TimeFrame1Level[0]);
         ObjectSet(tShortName+"03",OBJPROP_COLOR,indicator_color1);  
      }

       if (ObjectFind(tShortName+"04") != 0)
      {
          ObjectCreate(tShortName+"04",OBJ_ARROW,0,Time[0],TimeFrame2Level[0]);
          ObjectSet(tShortName+"04",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"04",OBJPROP_COLOR,indicator_color2);  
          ObjectSet(tShortName+"04",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"04",0,Time[0],TimeFrame2Level[0]);
         ObjectSet(tShortName+"04",OBJPROP_COLOR,indicator_color2);  
      }
      

                
   return(0);
}


//+------------------------------------------------------------------+
string TimeFrameToString(int tf)
{
   string tfs;
   switch(tf) {
      case PERIOD_M1:  tfs="M1"  ; break;
      case PERIOD_M5:  tfs="M5"  ; break;
      case PERIOD_M15: tfs="M15" ; break;
      case PERIOD_M30: tfs="M30" ; break;
      case PERIOD_H1:  tfs="H1"  ; break;
      case PERIOD_H4:  tfs="H4"  ; break;
      case PERIOD_D1:  tfs="D1"  ; break;
      case PERIOD_W1:  tfs="W1"  ; break;
      case PERIOD_MN1: tfs="MN";
   }
   return(tfs);
}



//+------------------------------------------------------------------+

/*
Comment( 
"TimeFrame1Level[0] = ", DoubleToStr(TimeFrame1Level[0], Digits), "\n",
"linelevel1 = ", DoubleToStr(linelevel1, Digits), "\n",
"linelevel2 = ", DoubleToStr(linelevel2, Digits), "\n",
"") ; 




   if (ObjectFind(linename1) != 0) {
      ObjectCreate(linename1, OBJ_HLINE, 0, Time[0], linelevel1 );
      ObjectSet(linename1, OBJPROP_STYLE, Line1_Style);
      ObjectSet(linename1, OBJPROP_COLOR, Line1_Color);
      
      }
   else {
      ObjectMove(linename1, 0, Time[0], linelevel1);
      
   }


   

   
   if (ObjectFind(linename2) != 0) {
      ObjectCreate(linename2, OBJ_HLINE, 0, Time[0], linelevel2 );
      ObjectSet(linename2, OBJPROP_STYLE, Line2_Style);
      ObjectSet(linename2, OBJPROP_COLOR, Line2_Color);
      
      }
   else {
      ObjectMove(linename2, 0, Time[0], linelevel2);
      
   }
*/