//+---   cm_WaterLevel v3   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 |
//+--------------------------------------------------------------------+
//| WaterLevel v3_TRO_MODIFIED_VERSIONabbiR9                           |
//| MODIFIED BY AVERY T. HORTON, JR. AKA THERUMPLEDONE@GMAIL.COM     |
//| I am NOT the ORIGINAL author 
//  and I am not claiming authorship of this indicator. 
//  All I did was modify it. I hope you find my modifications useful.|
//|                                                                  |
//+------------------------------------------------------------------+
 
 
 
#property indicator_chart_window
#property indicator_buffers 8

#property indicator_color1 Gold
#property indicator_color2 GreenYellow
#property indicator_color3 Red
#property indicator_color4 Lime

#property indicator_color5 Khaki
#property indicator_color6 LightSalmon
#property indicator_color7 HotPink
#property indicator_color8 MediumSlateBlue

//+---------- HH/LL code ------------------------------------------------+

extern int HHLLPeriod = 4;

//+---------- HH/LL code ------------------------------------------------+

//+---------- rule of 9 code ------------------------------------------------+

extern string TimeFrameR9_value = "TimeFrame(0,M5,M15,M30,H1,D1)";
extern string TimeFrameR9 = "0";
extern int SumPeriod = 30;
extern string Sum_Mode = "0=Close-Open, 1=+1/-1";
extern int SumMode = 1;
extern string Day_Calculation_Type = "0=Brian,1=Logical Trader,2=Amibroker";
extern int Calculation_Type = 0;

double P, PRU, PRD, R, D;

double LastValue[];
double HSum[];
double LSum[];
double SumValue[];

int LastBar = -1;

double HCount[];
double LCount[];

double HigherTimeFrameValue[];
int timeFrameR9 = 0;


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

extern bool ShowLable=true;
extern double Level1Factor = 2.3;
extern double Level2Factor = 0.85;
extern int HistoryWeek      = 104;
//extern int FontSize         = 16;

string TimeFrame_value = "TimeFrame(0,M5,M15,M30,H1,D1)";
string TimeFrame = "0";
string biMA_Type_value = "SMA, EMA, LWMA";
string biMA_Type = "SMA";

int timeFrame = 0;
double pair1Close;
int totalWeek = 0;
int lastDay = 0;
int bimaType;

double BufBI[];
double BufBIHHLevel1[];
double BufBIHHLevel2[];
double BufBILLLevel2[];
double BufBILLLevel1[];

int MaxWeek = 0;
double WeekCloseArray[];
double WeekHHpipsArray[];
double WeekLLpipsArray[];
int History2, History3, History4, History5;

datetime LastWeekDateTime = 0;

string sShortName = "_tp BI (SP) V2.02";
int objectcnt=1;



extern int   MaxBars         = 24;
extern int  ma211period      = 1440 ;

string     tma211period ;


//---- indicator buffers 

double     D1Range[4] ; 
double     AvgD1Range ;


double     MaxRange = 0 ; 
double     MinRange = 0 ; 
double     AvgRange = 0 ; 
double     xRange   = 0 ; 
double     tRange   = 0 ; 

//---- buffers


double zRange = 0;


double   AboveTF2, BelowTF2, AboveTF1, BelowTF1 ;

double xRet, close ;
double xRetPct;  

//+--------- TRO MODIFICATION ---------------------------------------+ 

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


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 Show_BuySell_Price         = true;
extern bool Dynamic_BuySell_Price      = false;

extern bool Show_Magnified_WL_Price  = true;
extern int Magnified_WL_Price_Corner = 3;
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               = "Verdana"; // Tahoma Courier

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 = "";

//+--------- TRO MODIFICATION ---------------------------------------+ 
string symbol, tChartPeriod,  tShortName ;  
int    digits, period  ; 

bool Trigger ;

int OldBars = -1 ;



string ArrowN  = "ñ"; // NORTH
string ArrowNE = "ö";  // NORTHEAST
string ArrowE  = "ð";  // EAST
string ArrowSE = "ø";  // SOUTHEAST
string ArrowS  = "ò";  // SOUTH

string Arrow935, Arrow936, Arrow937, ArrowSMA05, ArrowSMA07, ArrowSMA22 ;
color colorArrowSMA05, colorArrowSMA07, colorArrowSMA22 ;

//+------------------------------------------------------------------+
int init() {


//+---------- rule of 9 code ------------------------------------------------+


   for(int idx=0; idx < SumPeriod; idx++) {

      SumValue[idx] = 0.0;
      HCount[idx] = 0.0;
      LCount[idx] = 0.0;
      HSum[idx] = 0.0;
      LSum[idx] = 0.0;
      LastValue[idx] = 0.0;

   }

   if (TimeFrameR9 == "M5") {

      timeFrameR9 = PERIOD_M5;

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

      timeFrameR9 = PERIOD_M15;

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

      timeFrameR9 = PERIOD_M30;

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

      timeFrameR9 = PERIOD_H1;

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

      timeFrameR9 = PERIOD_H4;

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

      timeFrameR9 = PERIOD_D1;

   } else {

      timeFrameR9 = 0;

   }

   LastBar = iTime(NULL, 0, 0);

//+---------- rule of 9 code ------------------------------------------------+


   if (biMA_Type == "SMA") {

      bimaType = MODE_SMA;

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

      bimaType = MODE_EMA;

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

      bimaType = MODE_LWMA;

   } else {

      bimaType = MODE_SMA;

   }


//+--------- TRO MODIFICATION ---------------------------------------+ 


tma211period = TimeFrameToString(ma211period) ;

bool Trigger ;

int OldBars = -1 ;


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

   tShortName = "wl3"+ symbol + tChartPeriod  ;

   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_BuySell_Price)
   {
   SetIndexStyle(2,DRAW_LINE, STYLE_DOT);
   SetIndexBuffer(2,SellPrice);
   SetIndexLabel(2,"Sell Level");
   SetIndexStyle(3,DRAW_LINE, STYLE_DOT);
   SetIndexBuffer(3,BuyPrice);
   SetIndexLabel(3,"Buy Level");
   }

   SetIndexStyle(4,DRAW_LINE, STYLE_DASHDOT);
   SetIndexBuffer(4,TimeFrame2AverageMA1);
   SetIndexLabel(4,"" + MA_Type + "(" + Period_MA1 + ")");
   SetIndexStyle(5,DRAW_LINE, STYLE_DASHDOT);
   SetIndexBuffer(5,TimeFrame2AverageMA2);
   SetIndexLabel(5,"" + MA_Type + "(" + Period_MA2 + ")");
   SetIndexStyle(6,DRAW_LINE, STYLE_DASHDOT);
   SetIndexBuffer(6,TimeFrame2AverageMA3);
   SetIndexLabel(6,"" + MA_Type + "(" + Period_MA3 + ")");
   SetIndexStyle(7,DRAW_LINE, STYLE_DASHDOT);
   SetIndexBuffer(7,TimeFrame2AverageMA4);
   SetIndexLabel(7,"" + MA_Type + "(" + Period_MA4 + ")");




   if (TimeFrame == "M5") {

      timeFrame = PERIOD_M5;

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

      timeFrame = PERIOD_M15;

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

      timeFrame = PERIOD_M30;

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

      timeFrame = PERIOD_H1;

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

      timeFrame = PERIOD_D1;

   } else {

      timeFrame = 0;

   }
   ArrayResize(WeekCloseArray, HistoryWeek);
   ArrayResize(WeekHHpipsArray, HistoryWeek);
   ArrayResize(WeekLLpipsArray, HistoryWeek);


   return(0);

}

//+------------------------------------------------------------------+
int deinit() {
 


//+--------- TRO MODIFICATION ---------------------------------------+ 
         ObjectDelete("Market_Price_Label");
         ObjectDelete("TimeFrame1_Level_Label");
         ObjectDelete("TimeFrame2_Level_Label");

   ObjectDelete(tShortName+"01"); 
   ObjectDelete(tShortName+"02"); 
   ObjectDelete(tShortName+"03"); 
   ObjectDelete(tShortName+"04");   
   ObjectDelete(tShortName+"05"); 
   ObjectDelete(tShortName+"06"); 
   ObjectDelete(tShortName+"07"); 
   ObjectDelete(tShortName+"08");   
      


   ObjectDelete("WLV929");
   ObjectDelete("WLV929B");
   ObjectDelete("WLV930");   
   ObjectDelete("WLV931");
   ObjectDelete("WLV932");
   ObjectDelete("WLV933");  
   ObjectDelete("WLV934");     
   ObjectDelete("WLV935");
   ObjectDelete("WLV936");  
   ObjectDelete("WLV937");      
   ObjectDelete("WLV938");  
   ObjectDelete("WLV939");   
   ObjectDelete("WLV940");  
   ObjectDelete("WLV941");     
   ObjectDelete("WLV942");  
   ObjectDelete("WLV943");     
   ObjectDelete("WLV944");  
   ObjectDelete("WLV945");     
   ObjectDelete("WLV946");  
   ObjectDelete("WLV947");  
   ObjectDelete("WLV948");  
   ObjectDelete("WLV949");    
   
   ObjectDelete("WLV950");   
   ObjectDelete("WLV951");
   ObjectDelete("WLV952");   
   ObjectDelete("WLV953");     
   ObjectDelete("WLV954");   
   ObjectDelete("WLV955");     
   ObjectDelete("WLV956");   
   ObjectDelete("WLV957");     
   ObjectDelete("WLV958");   
   ObjectDelete("WLV959");   
   
   
                              
   return(0);

}

//+------------------------------------------------------------------+
int start() {

//+--------- TRO MODIFICATION ---------------------------------------+   
   if( Bars != OldBars ) { Trigger = True ; }
 
   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);
      
// object code was here

      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;

      i--;

   }


      if (Show_Magnified_WL_Price == true){

         string Market_Price = DoubleToStr(Bid, Digits);
         string TimeFrame1WaterLevel = DoubleToStr(TimeFrame1Level[0], Digits); // was [i]
         string TimeFrame2WaterLevel = DoubleToStr(TimeFrame2Level[0], 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);


color WL1color ;

if( Close[0] >= TimeFrame1Level[0]) { WL1color = Lime ; } else { WL1color = Red ; }   

         ObjectCreate("TimeFrame1_Level_Label", OBJ_LABEL, 0, 0, 0);
         ObjectSetText("TimeFrame1_Level_Label", TimeFrame1String + " WL=" + TimeFrame1WaterLevel, FontSize, FontType, WL1color); // was 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);

color WL2color ;

if( Close[0] >= TimeFrame2Level[0]) { WL2color = Lime ; } else { WL2color = Red ; }   

         ObjectCreate("TimeFrame2_Level_Label", OBJ_LABEL, 0, 0, 0);
         ObjectSetText("TimeFrame2_Level_Label", TimeFrame2String + " WL=" + TimeFrame2WaterLevel, FontSize, FontType, WL2color); // was 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");

      }



//+--------- TRO MODIFICATION ---------------------------------------+  
      
      if ( Trigger &&  Sound.Alert ) 
      {
        if( Close[0] == TimeFrame1Level[0] ) { Trigger = False ; Alert(symbol,"  ", tChartPeriod, " Price at Water Level 1 "+ DoubleToStr(TimeFrame1Level[0] ,digits)); }
        if( Close[0] == TimeFrame2Level[0] ) { Trigger = False ; Alert(symbol,"  ", tChartPeriod, " Price at Water Level 2 "+ DoubleToStr(TimeFrame2Level[0] ,digits)); }     
      }

   if(Show.PriceBox) { DoBox() ; }
    
   OldBars = Bars ;   

/*
Comment( 
"1 TimeFrame1Level[0] = ",  DoubleToStr( TimeFrame1Level[0] , Digits) , "\n",
"2 TimeFrame2Level[0] = ",  DoubleToStr( TimeFrame2Level[0] , Digits) , "\n",
"") ;    
*/



    MaxRange = 0 ; 
    MinRange = 999999 ; 

   double HighVal,LowVal; 
   int limit; 


   AboveTF2 = 0 ; 
   BelowTF2 = 0 ; 
   AboveTF1 = 0 ; 
   BelowTF1  = 0 ;
  
   limit = MaxBars + 1;  

//---- RANGE counted in the 1-st buffer 


		double buf_tmp = 0 ;
		int z = 0 ;


  
   

   
     zRange = HighVal - LowVal ; // range         
 
   for( i=1; i<limit; i++) 
   { 
 
     if( Close[i] > TimeFrame2Level[0] ) {AboveTF2 = AboveTF2 + 1  ; } // time frame chart
     if( Close[i] < TimeFrame2Level[0] ) {BelowTF2 = BelowTF2 + 1  ; }     

     if( Close[i] > TimeFrame1Level[0] ) {AboveTF1 = AboveTF1 + 1  ; } // time frame user
     if( Close[i] < TimeFrame1Level[0] ) {BelowTF1 = BelowTF1 + 1  ; }     
                 
   } 
  

   AvgRange = buf_tmp / MaxBars /Point ; // average range 
  
   
// xRetPct =  ( 100 ) * ( zRange / AvgRange )  ;  
   


string tPeriod = " "+tChartPeriod ;




   ObjectCreate("WLV930", OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText("WLV930"," Water("+MaxBars+")",FontSize, FontType, FontColor );
   ObjectSet("WLV930", OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet("WLV930", OBJPROP_XDISTANCE, 5);
   ObjectSet("WLV930", OBJPROP_YDISTANCE, FontSize*6+25);

string  RAN929 = TimeFrame2String + " A/B=" + DoubleToStr( AboveTF2 ,0) + "/" + DoubleToStr( BelowTF2 ,0) ;    // top left

   ObjectCreate("WLV929", OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText("WLV929",RAN929, FontSize, FontType, FontColor  );
   ObjectSet("WLV929", OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet("WLV929", OBJPROP_XDISTANCE, 5);
   ObjectSet("WLV929", OBJPROP_YDISTANCE, FontSize*4+15);

string  RAN929b = TimeFrame1String + " A/B=" + DoubleToStr( AboveTF1 ,0) + "/" + DoubleToStr( BelowTF1 ,0) ;   // bot left
 
  
   ObjectCreate("WLV929b", OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText("WLV929b", RAN929b ,  FontSize, FontType, FontColor );
   ObjectSet("WLV929b", OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet("WLV929b", OBJPROP_XDISTANCE, 5);
   ObjectSet("WLV929b", OBJPROP_YDISTANCE, FontSize*5+20);                 
                   
/*                  
string  RAN931 = DoubleToStr(zRange,0)+tPeriod + " " + DoubleToStr(xRetPct,0) + "%" ;
                   
   ObjectCreate("WLV931", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("WLV931", RAN931 , 25, "Arial Bold", RangeColor );
   ObjectSet("WLV931", OBJPROP_CORNER, 0);
   ObjectSet("WLV931", OBJPROP_XDISTANCE, 765+price.x.offset); // 765
   ObjectSet("WLV931", OBJPROP_YDISTANCE, 220+price.y.offset); 
         

string  RAN932 = DoubleToStr( TimeFrame2Level[0] , Digits) + " " + TimeFrame2String  ;  // top right

   ObjectCreate("WLV932", OBJ_LABEL, win, 0, 0);   // 
   ObjectSetText("WLV932", RAN932 , 15, "Arial Bold", ColorTF2); // RANGEBuffer2[0] buf0[0]
   ObjectSet("WLV932", OBJPROP_CORNER, 0);
   ObjectSet("WLV932", OBJPROP_XDISTANCE, 860+price.x.offset);
   ObjectSet("WLV932", OBJPROP_YDISTANCE, 197+price.y.offset);
                 
string  RAN934 = DoubleToStr( TimeFrame1Level[0] , Digits) + " " + TimeFrame1String  ; // bot right           
           
   ObjectCreate("WLV934", OBJ_LABEL, win, 0, 0);
   ObjectSetText("WLV934", RAN934 , 15, "Arial Bold",  ColorTF1);
   ObjectSet("WLV934", OBJPROP_CORNER, 0);
   ObjectSet("WLV934", OBJPROP_XDISTANCE, 850+price.x.offset);
   ObjectSet("WLV934", OBJPROP_YDISTANCE, 260+price.y.offset);    
*/     

   WindowRedraw();    


















//+--------- TRO MODIFICATION ---------------------------------------+                  
   return(0);
}

//+--------- TRO MODIFICATION ---------------------------------------+  
void DoBox()    
{


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

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

     if( Show_BuySell_Price ) 
     {

       if (ObjectFind(tShortName+"03") != 0)
      {
          ObjectCreate(tShortName+"03",OBJ_ARROW,0,Time[0],SellPrice[0]);
          ObjectSet(tShortName+"03",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"03",OBJPROP_COLOR,indicator_color3);  
          ObjectSet(tShortName+"03",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"03",0,Time[0],SellPrice[0]);
         ObjectSet(tShortName+"03",OBJPROP_COLOR,indicator_color3);  
      } 
      
       if (ObjectFind(tShortName+"04") != 0)
      {
          ObjectCreate(tShortName+"04",OBJ_ARROW,0,Time[0],BuyPrice[0]);
          ObjectSet(tShortName+"04",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"04",OBJPROP_COLOR,indicator_color4);  
          ObjectSet(tShortName+"04",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"04",0,Time[0],BuyPrice[0]);
         ObjectSet(tShortName+"04",OBJPROP_COLOR,indicator_color4);  
      }      
     }// if Show_BuySell_Price

     if( Show_MAs ) 
     {

       if (ObjectFind(tShortName+"05") != 0)
      {
          ObjectCreate(tShortName+"05",OBJ_ARROW,0,Time[0],TimeFrame2AverageMA1[0]);
          ObjectSet(tShortName+"05",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"05",OBJPROP_COLOR,indicator_color5);  
          ObjectSet(tShortName+"05",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"05",0,Time[0],TimeFrame2AverageMA1[0]);
         ObjectSet(tShortName+"05",OBJPROP_COLOR,indicator_color5);  
      } 
      
       if (ObjectFind(tShortName+"06") != 0)
      {
          ObjectCreate(tShortName+"06",OBJ_ARROW,0,Time[0],TimeFrame2AverageMA2[0]);
          ObjectSet(tShortName+"06",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"06",OBJPROP_COLOR,indicator_color6);  
          ObjectSet(tShortName+"06",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"06",0,Time[0],TimeFrame2AverageMA2[0]);
         ObjectSet(tShortName+"06",OBJPROP_COLOR,indicator_color6);  
      } 
      

       if (ObjectFind(tShortName+"07") != 0)
      {
          ObjectCreate(tShortName+"07",OBJ_ARROW,0,Time[0],TimeFrame2AverageMA3[0]);
          ObjectSet(tShortName+"07",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"07",OBJPROP_COLOR,indicator_color7);  
          ObjectSet(tShortName+"07",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"07",0,Time[0],TimeFrame2AverageMA1[0]);
         ObjectSet(tShortName+"07",OBJPROP_COLOR,indicator_color7);  
      } 
      
       if (ObjectFind(tShortName+"08") != 0)
      {
          ObjectCreate(tShortName+"08",OBJ_ARROW,0,Time[0],TimeFrame2AverageMA4[0]);
          ObjectSet(tShortName+"08",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"08",OBJPROP_COLOR,indicator_color8);  
          ObjectSet(tShortName+"08",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"08",0,Time[0],TimeFrame2AverageMA2[0]);
         ObjectSet(tShortName+"08",OBJPROP_COLOR,indicator_color8);  
      }  
                
     }// Show_MAs

 
 

   int i, j, counted_bars = IndicatorCounted();
   int AvailableWeek = 0;
   
   i = Bars - counted_bars - 1;
   
   
   double TotalHHtoLastFriClose = 0.0; 
   double TotalLLtoLastFriClose = 0.0;

   if (LastWeekDateTime != iTime(NULL,PERIOD_W1,1) )
   {
      for (j = HistoryWeek; j>0; j--)
      {
         if (iClose(NULL,PERIOD_W1,j+1) > 0)
         {
            TotalHHtoLastFriClose = TotalHHtoLastFriClose  + ( iHigh(NULL,PERIOD_W1,j) - iClose(NULL,PERIOD_W1,j+1) );
            TotalLLtoLastFriClose = TotalLLtoLastFriClose  + ( iLow(NULL,PERIOD_W1,j) - iClose(NULL,PERIOD_W1,j+1) );
            AvailableWeek++;
         }
      }
      TotalHHtoLastFriClose = TotalHHtoLastFriClose / AvailableWeek / MarketInfo(Symbol(),MODE_POINT);
      TotalLLtoLastFriClose = TotalLLtoLastFriClose / AvailableWeek / MarketInfo(Symbol(),MODE_POINT);

      LastWeekDateTime = iTime(NULL,PERIOD_D1,1);
    }

   ArrayResize(BufBI, Bars);

   while (i >= 0) 
   {

      int timeFrameIndex = iBarShift(0, timeFrame, Time[i], true);

      if ((TimeDayOfWeek(iTime(NULL, timeFrame, timeFrameIndex)) == 1 && TimeDayOfWeek(iTime(NULL, timeFrame, timeFrameIndex+1)) == 5) ||
         (TimeDayOfWeek(iTime(NULL, timeFrame, timeFrameIndex)) == 0 && TimeDayOfWeek(iTime(NULL, timeFrame, timeFrameIndex+1)) == 5)){

         pair1Close = iClose(NULL, timeFrame, timeFrameIndex+1);  // closes of last week
      }
      

      if (pair1Close > 0 && TimeDayOfWeek(iTime(NULL, timeFrame, i)) >= 1) 
      {
          
          if (lastDay != TimeDayOfWeek(iTime(NULL, timeFrame, i))) 
          {
            lastDay = TimeDayOfWeek(iTime(NULL, timeFrame, i));
            totalWeek = 0;

          }

          BufBI[i] = (iClose(Symbol(), timeFrame, i) - pair1Close)/MarketInfo(Symbol(),MODE_POINT);
          BufBIHHLevel1[i] = TotalHHtoLastFriClose * Level1Factor;
          BufBIHHLevel2[i] = TotalHHtoLastFriClose * Level2Factor;
          BufBILLLevel2[i] = TotalLLtoLastFriClose * Level2Factor;
          BufBILLLevel1[i] = TotalLLtoLastFriClose * Level1Factor;
      } 

      i--;

   }


color BIcolor ;

if( BufBI[0] >= 0 ) { BIcolor = Lime ; } else { BIcolor = Red ; }      
 
string  RAN931 = "Brian Index= "   + DoubleToStr( BufBI[0] , 0) ;   
 

   ObjectCreate("WLV931", OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText("WLV931",RAN931 ,FontSize, FontType, BIcolor );
   ObjectSet("WLV931", OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet("WLV931", OBJPROP_XDISTANCE, 5);
   ObjectSet("WLV931", OBJPROP_YDISTANCE, FontSize*7+30);


double ma211 = iMA(NULL, ma211period, 211, 0, 1, PRICE_CLOSE,0);

string TheTrade ;

color ma211color ;

if( Close[0] >= ma211) { ma211color = Lime ; Arrow937 = ArrowN ;} else { ma211color = Red ; Arrow937 = ArrowS ;}   

string RAN932 = tma211period + " EMA(211) = " +  DoubleToStr( ma211 , Digits) ;

   ObjectCreate("WLV932", OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText("WLV932",RAN932 ,FontSize, FontType, ma211color );
   ObjectSet("WLV932", OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet("WLV932", OBJPROP_XDISTANCE, 5);
   ObjectSet("WLV932", OBJPROP_YDISTANCE, FontSize*8+35);



color DiffWL1color ;

double DiffWL1 = Close[0] - TimeFrame1Level[0] ;

if(DiffWL1 >=0 ) { DiffWL1color = Lime ; Arrow936 = ArrowN ; } else { DiffWL1color = Red ;  Arrow936 = ArrowS ;}   


string RAN933 =  TimeFrame1String + " Diff = " +  DoubleToStr( DiffWL1 / Point , 0) ;

   ObjectCreate("WLV933", OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText("WLV933",RAN933 ,FontSize, FontType, DiffWL1color );
   ObjectSet("WLV933", OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet("WLV933", OBJPROP_XDISTANCE, 5);
   ObjectSet("WLV933", OBJPROP_YDISTANCE, FontSize*9+40);


color DiffWL2color ;

double DiffWL2 = Close[0] - TimeFrame2Level[0] ;

if(DiffWL2 >=0 ) { DiffWL2color = Lime ; Arrow935 = ArrowN ; } else { DiffWL2color = Red ; Arrow935 = ArrowS ;}   


string RAN934 =  TimeFrame2String + " Diff = " +  DoubleToStr( DiffWL2 / Point , 0) ;

   ObjectCreate("WLV934", OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText("WLV934",RAN934 ,FontSize, FontType, DiffWL2color );
   ObjectSet("WLV934", OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet("WLV934", OBJPROP_XDISTANCE, 5);
   ObjectSet("WLV934", OBJPROP_YDISTANCE, FontSize*10+45);


string tObjName03 = "WLV935"  ; 

   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, Arrow935 , FontSize , "Wingdings" , DiffWL2color );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE, 5);
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*12+55); 


  tObjName03 = "WLV936"  ; 

   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, Arrow936 , FontSize , "Wingdings" , DiffWL1color );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE, FontSize*2 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*12+55); 
   
  tObjName03 = "WLV937"  ; 

   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, Arrow937 , FontSize , "Wingdings" , ma211color );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE, FontSize*3+15 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*12+55); 
      

  string RAN938 =  tma211period + " EMA(211) " + TimeFrame1String + TimeFrame2String ;
  
  tObjName03 = "WLV938"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN938 , FontSize ,  FontType,  FontColor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*13+60); 
   
   
   

color DiffMA211color ;

double DiffMA211 = Close[0] - ma211 ;

if(DiffMA211 >=0 ) { DiffMA211color = Lime ;   } else { DiffMA211color = Red ;   }   


string RAN939 =  tma211period + " EMA(211) Diff = " +  DoubleToStr( DiffMA211 / Point , 0) ;

 tObjName03 = "WLV939"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN939 , FontSize ,  FontType,  DiffMA211color );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*11+50); 
    
   
   
//+------------------------------------------------------------------+                
  
  
//+---------- rule of 9 code ------------------------------------------------+

ArrayResize( LastValue,Bars) ; 
ArrayResize( SumValue,Bars) ; 
ArrayResize( HCount , Bars ) ;
ArrayResize( LCount , Bars ) ;
ArrayResize( HSum , Bars ) ;
ArrayResize( LSum , Bars ) ;

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

   if (i < SumPeriod) {
   
      i = SumPeriod;
   
   }
   
   while (i >= 0) {

      if (iTime(NULL, timeFrameR9, i) != LastBar) {

         LastBar = iTime(NULL, timeFrameR9, i);
         sum = 0;

         if (Calculation_Type == 0 || (Calculation_Type != 1 && Calculation_Type != 2)) {
         
            D = (iOpen(NULL, timeFrameR9, i) - iClose(NULL, timeFrameR9, i+1));
         
         } else if (Calculation_Type == 1) {
         
            D = (iClose(NULL, timeFrameR9, i+1) - iOpen(NULL, timeFrameR9, i+1));
            
         } else if (Calculation_Type == 2) {
         
            D = (iClose(NULL, timeFrameR9, i) - iOpen(NULL, timeFrameR9, i+1));

         }
         
/*         // Experiment of the logical trader book ACD signal
         P = (iHigh(NULL, PERIOD_D1, i+1) + iLow(NULL, PERIOD_D1, i+1) + iClose(NULL, PERIOD_D1, i+1)) / 3;
         R = (iHigh(NULL, PERIOD_D1, i+1) + iLow(NULL, PERIOD_D1, i+1)) / 2;
         PRU = P+(MathAbs(P-R));
         PRD = P-(MathAbs(P-R));

         if (iOpen(NULL, PERIOD_D1, i+1) <= PRU && iClose(NULL, PERIOD_D1, i+1) > PRU) {
      
            LastValueUp[i] = 2;
      
         } else if (iOpen(NULL, PERIOD_D1, i+1) >= PRD && iClose(NULL, PERIOD_D1, i+1) < PRD) {
      
            LastValueUp[i] = -2;
      
         } else {
      
            LastValueUp[i] = 0;
      
         }
*/

         if (SumMode == 0) {

            LastValue[i] = D;

         } else {

            if (D > 0) {
  
               LastValue[i] = 1;

            } else {

               LastValue[i] = -1;

            }
               
         
         }
 
 
 
 
         
         int period = 0;
         
         if (SumPeriod > ArraySize(LastValue) ) {

            period = ArraySize(LastValue);

         } else {

            period = SumPeriod;

         }






         for(int idx=0; idx<period; idx++) {
      
            sum += LastValue[i+idx];

         }

         SumValue[i] = sum;




         HSum[i] = SumValue[ArrayMaximum(SumValue, SumPeriod*8, 0)];
         LSum[i] = SumValue[ArrayMinimum(SumValue, SumPeriod*8, 0)];



         if (SumValue[i] >= 8) {
         
            HCount[i] = HCount[i+1] + 1;
             
         } else {
         
            HCount[i] = 0.0;

         }
         if (SumValue[i] <= -8) {

            LCount[i] = LCount[i+1] + 1;

         } else {

            LCount[i] = 0.0;

         }
         
         if (LCount[i] <= -9 || HCount[i] >= 9) {
         
            Alert("Potential trend change on ", TimeToStr(Time[i], TIME_DATE));
         
         }
         
      }

      i--;

   }
 

   
//+---------- rule of 9 code ------------------------------------------------+



color Rule9color = Yellow ;


if(SumValue[0] >= 8 ) { Rule9color = Lime ;   } 
else { if(SumValue[0] <= -8 ) { Rule9color = Red ;   }   }


string RAN940 =  "Rule9 = " +  DoubleToStr( SumValue[0] , 0) ;

 tObjName03 = "WLV940"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN940 , FontSize ,  FontType,  Rule9color );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*14+65); 
    
    
//+---------- rule of 9 code ------------------------------------------------+  
           

//+---------- HH/LL code ------------------------------------------------+           
           
           
           
           
   int iHH = iHighest(NULL,1440,MODE_HIGH,HHLLPeriod,0); // index to high
   int iLL = iLowest(NULL,1440,MODE_LOW,HHLLPeriod,0); // index to low  

   double HH = iHigh(NULL,1440,iHH);
   double LL = iLow(NULL,1440,iLL); 


   
   double HHpips = Close[0] - HH ;
   double LLpips = Close[0] - LL ;   
   
color LLcolor = Yellow ;


if(LLpips >= 0 ) { LLcolor = Lime ;   } else { LLcolor = Red ;   }  


string RAN942 =  " Pips LL(" + HHLLPeriod + ")= "  +  DoubleToStr( LLpips  / Point , 0) ;

 tObjName03 = "WLV942"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN942 , FontSize ,  FontType,  LLcolor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*15+70); 


string RAN943 =  "LL("+ HHLLPeriod +")= "  +  DoubleToStr( LL , Digits) ;   
 tObjName03 = "WLV943"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN943 , FontSize ,  FontType,  LLcolor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*16+75);              
 
  
color HHcolor = Yellow ;


if(HHpips >= 0 ) { HHcolor = Lime ;   } else { HHcolor = Red ;   }  


string RAN944 =  " Pips HH(" + HHLLPeriod + ")= "  +  DoubleToStr( HHpips  / Point , 0) ;

 tObjName03 = "WLV944"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN944 , FontSize ,  FontType,  HHcolor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*17+80); 


string RAN945 =  "HH("+ HHLLPeriod +")= "  +  DoubleToStr( HH , Digits) ;   
 tObjName03 = "WLV945"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN945 , FontSize ,  FontType,  HHcolor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*18+85);   
 


   double D1HH = iHigh(NULL,1440,0);
   double D1LL = iLow(NULL,1440,0); 


   
   double D1HHpips = Close[0] - D1HH ;
   double D1LLpips = Close[0] - D1LL ;   
   
color D1LLcolor = Yellow ;


if(D1LLpips >= 0 ) { D1LLcolor = Lime ;   } else { D1LLcolor = Red ;   }  


string RAN946 =  " Pips D1LL = "  +  DoubleToStr( D1LLpips  / Point , 0) ;

 tObjName03 = "WLV946"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN946 , FontSize ,  FontType,  D1LLcolor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*19+90); 


string RAN947 =  "D1LL = "  +  DoubleToStr( D1LL , Digits) ;   
 tObjName03 = "WLV947"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN947 , FontSize ,  FontType,  D1LLcolor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*20+95);              
 
  
color D1HHcolor = Yellow ;


if(D1HHpips >= 0 ) { D1HHcolor = Lime ;   } else { D1HHcolor = Red ;   }  


string RAN948 =  " Pips D1HH = "  +  DoubleToStr( D1HHpips  / Point , 0) ;

 tObjName03 = "WLV948"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN948 , FontSize ,  FontType,  D1HHcolor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*21+100); 


string RAN949 =  "D1HH = "  +  DoubleToStr( D1HH , Digits) ;   
 tObjName03 = "WLV949"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN949 , FontSize ,  FontType,  D1HHcolor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*22+105);   

//+---------- HH/LL code ------------------------------------------------+
     
//+---------- D1 RANGE CODE ------------------------------------------------+     
 
AvgD1Range = 0 ; 
     
for( i=0; i<5; i++)
{

   D1Range[i] = (iHigh(NULL,PERIOD_D1,i) - iLow(NULL,PERIOD_D1,i))  / Point;
   AvgD1Range = AvgD1Range + D1Range[i]  ;

}    

AvgD1Range = NormalizeDouble(AvgD1Range / 5 , Digits ) ;

string RAN950 =   DoubleToStr( D1Range[0]  , 0) ;  
       tObjName03 = "WLV950"  ; 

   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN950 , FontSize ,  FontType, FontColor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE, 5);
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*23+110 ); 

string RAN951 =   DoubleToStr( D1Range[1]   , 0) ;  
  tObjName03 = "WLV951"  ; 

   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN951 , FontSize ,  FontType, FontColor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE, FontSize*3+30 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*23+110 ); 

string RAN952 =   DoubleToStr( AvgD1Range   , 0) ;     
  tObjName03 = "WLV952"  ; 

   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN952 , FontSize ,  FontType, FontColor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE, FontSize*6+35 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*23+110 ); 
      
      

string RAN953 =  "D(0) D(1) Avg(5)"  ;   
 tObjName03 = "WLV953"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN953 , FontSize ,  FontType,  FontColor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*24+115);         


//+---------- D1 RANGE CODE ------------------------------------------------+ 



//+---------- SMA 5 X 7 X 22 CODE ------------------------------------------------+ 


double sma05 = iMA(NULL, PERIOD_D1, 5, 0, 0, PRICE_CLOSE,0);
double sma07 = iMA(NULL, PERIOD_D1, 7, 0, 0, PRICE_CLOSE,0);
double sma22 = iMA(NULL, PERIOD_D1, 22, 0, 0, PRICE_CLOSE,0);

double sma05p = iMA(NULL, PERIOD_D1, 5, 0, 0, PRICE_CLOSE,1);
double sma07p = iMA(NULL, PERIOD_D1, 7, 0, 0, PRICE_CLOSE,1);
double sma22p = iMA(NULL, PERIOD_D1, 22, 0, 0, PRICE_CLOSE,1);

double diff05_07 = ( sma05 - sma07 ) / Point;
double diff07_22 = ( sma07 - sma22 ) / Point; 



if( sma05 >= sma05p) { colorArrowSMA05 = Lime ; ArrowSMA05 = ArrowN ; } else { colorArrowSMA05 = Red ;  ArrowSMA05 = ArrowS ;  }  
if( sma07 >= sma07p) { colorArrowSMA07 = Lime ; ArrowSMA07 = ArrowN ; } else { colorArrowSMA07 = Red ;  ArrowSMA07 = ArrowS ;  }  
if( sma22 >= sma22p) { colorArrowSMA22 = Lime ; ArrowSMA22 = ArrowN ; } else { colorArrowSMA22 = Red ;  ArrowSMA22 = ArrowS ;  }  


color diff05_07color = Yellow ;


if(diff05_07 >= 0 ) { diff05_07color = Lime ;   } else { diff05_07color = Red ;   }  


string RAN954 =  "diff05x07 = "  +  DoubleToStr( diff05_07 , 0) ;

 tObjName03 = "WLV954"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN954 , FontSize ,  FontType,  diff05_07color );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*25+120); 
  

color diff07_22color = Yellow ;


if(diff07_22 >= 0 ) { diff07_22color = Lime ;   } else { diff07_22color = Red ;   }  


string RAN955 =  "diff07x22 = "  +  DoubleToStr( diff07_22 , 0) ;

 tObjName03 = "WLV955"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN955 , FontSize ,  FontType,  diff07_22color );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*26+125); 
  




 tObjName03 = "WLV956"  ; 

   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, ArrowSMA05 , FontSize , "Wingdings" , colorArrowSMA05 ); //
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE, 15);
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*27+130); 


  tObjName03 = "WLV957"  ; 

   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, ArrowSMA07 , FontSize , "Wingdings" , colorArrowSMA07 );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE, FontSize*2+20 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*27+130); 
   
  tObjName03 = "WLV958"  ; 

   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, ArrowSMA22 , FontSize , "Wingdings" , colorArrowSMA22 );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE, FontSize*3+40 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*27+130); 
      

  string RAN959 =   "D1-SMA 22  07  05 "   ;
  
  tObjName03 = "WLV959"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN959 , FontSize ,  FontType,  FontColor );
   ObjectSet(tObjName03, OBJPROP_CORNER, Magnified_WL_Price_Corner);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, FontSize*28+135); 
   

//+---------- SMA 5 X 7 X 22 CODE ------------------------------------------------+ 

                
   return(0);
}


//+--------- TRO MODIFICATION ---------------------------------------+  

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);
}



//+--------- TRO MODIFICATION ---------------------------------------+  

/*

   
Comment(
"SumMode = ",SumMode , "\n", 
"ArraySize(LastValue) = ", ArraySize(LastValue) , "\n", 
"LastBar = ", TimeToStr(LastBar) , "\n", 
"D = ", DoubleToStr(D, Digits) , "\n", 
"!! i  = ",i , "\n", 
"LastValue[i] = ", DoubleToStr(LastValue[i], Digits) , "\n", 
"period = ", period , "\n", 
"HSum[i] = ", HSum[i] , "\n", 
"LSum[i] = ", LSum[i] , "\n",
"SumValue[i] = ", SumValue[i] , "\n",

"");   
*/