/*
   G e n e r a t e d  by ex4-to-mq4 decompiler FREEWARE 4.0.509.5
   Website:  HT T p : //Www .m E t aq uOt e S. N e t
   E-mail :  suPpo rT@ MEt aQU oTEs.n Et
*/

#property indicator_chart_window

string Gs_76 = "TrendPlus_Zone";
extern string StartTime = "06:00";
extern string EndTime = "09:00";
extern string SessionEndTime = "00:00";
extern color SessionColor = C'0x37,0x37,0x37';
extern int NumDays = 60;
extern int MinBoxSizeInPips = 25;
extern int MaxBoxSizeInPips = 55;
extern bool LimitBoxToMaxSize = true;
extern double TP1Factor = 0.618;
extern double TP3Factor = 2.618;  //2.0;
extern double LevelsResizeFactor = 1.0;
extern color BoxColorOK = C'0x6C,0x6C,0x00';
extern color BoxColorNOK = C'0x6C,0x6C,0x00';
extern color BoxColorMAX = Gold;
extern color LevelColor = C'0x6C,0x6C,0x00';
extern int FibLength = 12;
extern bool showProfitZone = true;
extern color ProfitColor = DimGray;
extern bool Show_BoxInfos = true;
extern bool EnableMaxBoxAverage = true;
extern double Factor_BoxAverage = 0.5;
extern string ____MaxLimitWithATR = "";
extern bool EnableMaxBoxWithATR = false;
extern double Factor_ATR = 4.0;
extern int Period_ATR = 100;
extern string objPrefix = ".";
//---
double middTP;
double PONT;

int Gi_376 = 8519755;
int Gi_396 = 58;

// E37F0136AA3FFAF149B351F6A4C948E9
int init() 
{
   string Ls_0;
   string Ls_8;
   ObjectsDELETE(objPrefix);
   calcPOINT();
   middTP = (TP1Factor + TP3Factor) / 2.0;
   Comment(Gs_76 + " " + StartTime + "p," + DoubleToStr(TP1Factor, 1) + "/" + DoubleToStr(TP3Factor, 1));
   if (Show_BoxInfos) {
      if (EnableMaxBoxWithATR) Ls_0 = "Factor ATR= " + DoubleToStr(Factor_ATR, 1);
      if (EnableMaxBoxAverage || EnableMaxBoxWithATR) {
         Ls_8 = objPrefix + ".";
         DrawLABEL(Ls_8, Ls_0, 0, 3, Gi_396, 8, "Impact", Gi_376, false);
      }
   }
//------
return (0);
}

// 52D46093050F38C27267BCE42543EF60
int deinit() 
{
   ObjectsDELETE(objPrefix);
   Comment("");
//---
return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() 
{
   int CountedBars = IndicatorCounted();
   int limit = MathMin(NumDays*(1440/_Period),Bars-CountedBars-1);

// F84DB01F626D753AAA27A8E2A12F76A6
   double Ld_60;
   double Ld_68;
   double Ld_76;
   double Ld_84;
   //---
   int countCETM=0;
   //---
   double deltaPN=0;
   double sumDeltaHL=0, curHI, curLO;
   //---
   bool boolEndTM=false;
//------
//------
   
   for (int i=limit; i>=0; i--)
    { 
     datetime curTM = Time[i];
     int startTM = StrToTime(TimeToStr(curTM, TIME_DATE) + " " + StartTime);
     int endTM = StrToTime(TimeToStr(curTM, TIME_DATE) + " " + EndTime);
     //---
     if (startTM > endTM) startTM -= 86400;
     if (curTM < endTM) {
         startTM -= 86400;
         endTM -= 86400; }
     //---
     int TMend = endTM;
     int sesETM = StrToTime(TimeToStr(TMend, TIME_DATE) + " " + SessionEndTime);
     if (TMend > sesETM) sesETM += 86400;
     //---
     if (TimeDayOfWeek(startTM) != 0) 
      {
       int shStart = iBarShift(NULL, 0, startTM);
       int shEnd = iBarShift(NULL, 0, endTM);
       //---
       double bxHIGH = High[iHighest(NULL, 0, MODE_HIGH, shStart - shEnd + 1, shEnd)];
       double bxLOW = Low[iLowest(NULL, 0, MODE_LOW, shStart - shEnd + 1, shEnd)];
       //---
       double deltaHL = bxHIGH - bxLOW;
       double medianHL = (bxHIGH + bxLOW) / 2.0;
       //---
       if (curTM == endTM) countCETM++;
       //---
       if (i == limit) {
           curHI = High[i];
           curLO = Low[i]; }
       //---
       else {
             if (High[i] > curHI) curHI = High[i];
             if (Low[i] < curLO) curLO = Low[i]; }
       //---
       if (curTM == endTM) {
           sumDeltaHL += (curHI - curLO) / _Point;
           curHI = High[i];
           curLO = Low[i]; }
       //---
       if (curTM == endTM) {
           deltaPN += deltaHL / _Point;
           Ld_60 = deltaPN / countCETM;
           Ld_68 = sumDeltaHL / countCETM;
           Ld_76 = 100.0 * (Ld_60 / Ld_68);
           Ld_84 = 100.0 * (deltaHL / _Point / Ld_68);
           if (Show_BoxInfos) double curATR = iATR(NULL, 0, Period_ATR, i); }
       //---
       if (EnableMaxBoxWithATR) {
           if (curTM == endTM) MaxBoxSizeInPips = MathRound(curATR * Factor_ATR / _Point); } 
       else {
             if (EnableMaxBoxAverage)
                if (curTM == endTM) MaxBoxSizeInPips = MathRound(Ld_60 * Factor_BoxAverage); }
       //---
       if (deltaHL >= MaxBoxSizeInPips * PONT && LimitBoxToMaxSize == true) {
           medianHL = iMA(NULL, 0, shStart - shEnd, 0, MODE_EMA, PRICE_MEDIAN, shEnd);
           deltaHL = MaxBoxSizeInPips * PONT;
           bxHIGH = medianHL + deltaHL / 2.0;
           bxLOW = medianHL - deltaHL / 2.0; }
       //---
       double levResize = LevelsResizeFactor * deltaHL;
       //---
       double PriceHI = bxHIGH;
       double levHighTP1 = PriceHI + levResize * TP1Factor;
       double levHighTP2 = PriceHI + levResize * middTP;
       double levHighTP3 = PriceHI + levResize * TP3Factor;
       //---
       double PriceLO = bxLOW;
       double levLowTP1 = PriceLO - levResize * TP1Factor;
       double levLowTP2 = PriceLO - levResize * middTP;
       double levLowTP3 = PriceLO - levResize * TP3Factor;
       //////---
       ////double Ld_108 = (levHighTP1 - PriceHI) / PONT;
       ////double Ld_116 = (levHighTP2 - PriceHI) / PONT;
       ////double Ld_118 = (levHighTP3 - PriceHI) / PONT;
       //////---
       ////double Ld_132 = (PriceLO - levLowTP1) / PONT;
       ////double Ld_140 = (PriceLO - levLowTP2) / PONT;
       ////double Ld_148 = (PriceLO - levLowTP3) / PONT;
       //////---
       f0_1(objPrefix + "Session-" + TimeToStr(TMend, TIME_DATE|TIME_SECONDS), TMend, 0, sesETM, 2.0 * PriceHI, SessionColor, 1, STYLE_SOLID, true);
       //---
       if (boolEndTM != endTM) 
        {
         boolEndTM = endTM;
         string boxName = objPrefix + "Box-" + TimeToStr(Time[i], TIME_DATE) + "-" + StartTime + "-" + EndTime;
         if (deltaHL <= MinBoxSizeInPips * PONT) {
            f0_5(boxName, startTM, bxLOW, endTM, bxHIGH, BoxColorNOK, 1, STYLE_SOLID, true);
            DrawTEXT(objPrefix + "Lbl-" + TimeToStr(Time[i], TIME_DATE) + "-" + StartTime + "-" + EndTime, ". (" + DoubleToStr(deltaHL / PONT, 0) + "p)", startTM + (endTM - startTM) / 2, bxLOW, 12, "Arial Black", BoxColorNOK, 3); } 
         //---
         else {
               if (deltaHL >= MaxBoxSizeInPips * PONT) {
                   if (LimitBoxToMaxSize == false) {
                      f0_5(boxName, startTM, bxLOW, endTM, bxHIGH, BoxColorNOK, 1, STYLE_SOLID, true);
                      DrawTEXT(objPrefix + "Lbl-" + TimeToStr(Time[i], TIME_DATE) + "-" + StartTime + "-" + EndTime, ". (" + DoubleToStr(deltaHL / PONT, 0) + "p)", startTM + (endTM - startTM) / 2, bxLOW, 12, "Arial Black", LevelColor, 3); }
                  //---
                  else {
                        f0_5(boxName, startTM, bxLOW, endTM, bxHIGH, BoxColorMAX, 1, STYLE_SOLID, true);
                        DrawTEXT(objPrefix + "." + TimeToStr(Time[i], TIME_DATE) + "-" + StartTime + "-" + EndTime, " (" + DoubleToStr(deltaHL / PONT, 0) + "p)", startTM + (endTM - startTM) / 2, bxLOW, 12, "Arial Black", LevelColor, 3); } } 
               //---
               else if (deltaHL > MinBoxSizeInPips * PONT) f0_5(boxName, startTM, bxLOW, endTM, bxHIGH, BoxColorOK, 1, STYLE_SOLID, true); }
         //---
         if (showProfitZone) {
             f0_5(objPrefix + "BuyProfitZone-" + TimeToStr(TMend, TIME_DATE), TMend, levHighTP1, sesETM, levHighTP3, ProfitColor, 1, STYLE_SOLID, true);
             f0_5(objPrefix + "SellProfitZone-" + TimeToStr(TMend, TIME_DATE), TMend, levLowTP1, sesETM, levLowTP3, ProfitColor, 1, STYLE_SOLID, true); }
         //---
         string fibName = objPrefix + "Fibo-" + endTM;
         ObjectCreate(fibName, OBJ_FIBO, 0, startTM, PriceLO, startTM + 10 * (60 * FibLength), PriceHI);
         ObjectSet(fibName, OBJPROP_RAY, false);
         ObjectSet(fibName, OBJPROP_LEVELCOLOR, LevelColor);
         ObjectSet(fibName, OBJPROP_FIBOLEVELS, 2);
         ObjectSet(fibName, OBJPROP_LEVELSTYLE, STYLE_SOLID);
         ObjectSet(fibName, OBJPROP_FIRSTLEVEL, 0.0);
         ObjectSet(fibName, 211, 1.0);
         ObjectSet(fibName, 212, -TP1Factor);
         ObjectSet(fibName, 213, -TP3Factor);
         ObjectSet(fibName, 214, TP1Factor + 1.0);
         ObjectSet(fibName, 215, TP3Factor + 1.0);
         ObjectSet(fibName, 216, middTP + 1.0);
         ObjectSet(fibName, 217, -middTP);
         ObjectSetFiboDescription(fibName, 0, "Look For a Buy");
         ObjectSetFiboDescription(fibName, 1, "Look For a Sell");
         ObjectSetFiboDescription(fibName, 2, "TP 1= %$");
         ObjectSetFiboDescription(fibName, 3, "TP 3= %$");
         ObjectSetFiboDescription(fibName, 4, "TP 1= %$");
         ObjectSetFiboDescription(fibName, 5, "TP 3= %$");
         ObjectSetFiboDescription(fibName, 6, "TP 2= %$");
         ObjectSetFiboDescription(fibName, 7, "TP 2= %$");
        }
      }
    }
//------
return(0);
}
// 9FF08A95CD5516B83CFC5989AFAD512C
// 9FF08A95CD5516B83CFC5989AFAD512C
// 9FF08A95CD5516B83CFC5989AFAD512C
void calcPOINT() 
{
   if (Digits == 2 || Digits == 4) PONT = _Point;
   else {
      if (Digits == 3 || Digits == 5) PONT = 10.0 * _Point;
      else
         if (Digits == 6) PONT = 100.0 * _Point;
   }
}

// 7EFBB2081D355DE1694C4F6F7C12CA9E
void ObjectsDELETE(string PREF) {
   string objName = ".";
   for (int objTot = ObjectsTotal(); objTot >= 0; objTot--) {
      objName = ObjectName(objTot);
      if (StringFind(objName, PREF, 0) > -1) ObjectDelete(objName);
   }
}

// ACA65665128A0CF8017DAAE0F9155F38
void f0_5(string A_name_0, int A_datetime_8, double A_price_12, int A_datetime_20, double A_price_24, color A_color_32, int A_width_36, int A_style_40, int A_bool_44) {
   if (ObjectFind(A_name_0) == -1) ObjectCreate(A_name_0, OBJ_RECTANGLE, 0, A_datetime_8, A_price_12, A_datetime_20, A_price_24);
   else {
      ObjectSet(A_name_0, OBJPROP_TIME1, A_datetime_8);
      ObjectSet(A_name_0, OBJPROP_TIME2, A_datetime_20);
      ObjectSet(A_name_0, OBJPROP_PRICE1, A_price_12);
      ObjectSet(A_name_0, OBJPROP_PRICE2, A_price_24);
   }
   ObjectSet(A_name_0, OBJPROP_COLOR, A_color_32);
   ObjectSet(A_name_0, OBJPROP_BACK, A_bool_44);
   ObjectSet(A_name_0, OBJPROP_SELECTABLE, false);
   ObjectSet(A_name_0, OBJPROP_WIDTH, A_width_36);
   ObjectSet(A_name_0, OBJPROP_STYLE, A_style_40);
}

// 52589CDF39E9DDC46A6F293D64E4FB97
void f0_1(string A_name_0, int A_datetime_8, double A_price_12, int A_datetime_20, double A_price_24, color A_color_32, int A_width_36, int A_style_40, int A_bool_44) {
   if (ObjectFind(A_name_0) == -1) {
      ObjectCreate(A_name_0, OBJ_RECTANGLE, 0, A_datetime_8, A_price_12, A_datetime_20, A_price_24);
      ObjectSet(A_name_0, OBJPROP_COLOR, A_color_32);
      ObjectSet(A_name_0, OBJPROP_BACK, A_bool_44);
      ObjectSet(A_name_0, OBJPROP_SELECTABLE, false);
      ObjectSet(A_name_0, OBJPROP_WIDTH, A_width_36);
      ObjectSet(A_name_0, OBJPROP_STYLE, A_style_40);
   }
}

// 2C8935E4EDCF9473B3F924051DD87F8D
void DrawLABEL(string A_name_0, string A_text_8, int A_corner_16, int A_x_20, int A_y_24, int A_fontsize_28, string A_fontname_32, color A_color_40, int A_bool_44) {
   if (ObjectFind(A_name_0) < 0) ObjectCreate(A_name_0, OBJ_LABEL, 0, 0, 0);
   ObjectSet(A_name_0, OBJPROP_CORNER, A_corner_16);
   ObjectSet(A_name_0, OBJPROP_XDISTANCE, A_x_20);
   ObjectSet(A_name_0, OBJPROP_YDISTANCE, A_y_24);
   ObjectSet(A_name_0, OBJPROP_BACK, A_bool_44);
   ObjectSet(A_name_0, OBJPROP_SELECTABLE, false);
   ObjectSetText(A_name_0, A_text_8, A_fontsize_28, A_fontname_32, A_color_40);
}

// 818FC4350ABD260C26C96D0591E9A2B1
void DrawTEXT(string A_name_0, string A_text_8, int A_datetime_16, double A_price_20, int A_fontsize_28, string A_fontname_32, color A_color_40, int Ai_unused_44) {
   if (ObjectFind(A_name_0) < 0) ObjectCreate(A_name_0, OBJ_TEXT, 0, A_datetime_16, A_price_20);
   else {
      if (ObjectType(A_name_0) == 21) {
         ObjectSet(A_name_0, OBJPROP_TIME1, A_datetime_16);
         ObjectSet(A_name_0, OBJPROP_PRICE1, A_price_20);
      }
   }
   ObjectSet(A_name_0, OBJPROP_FONTSIZE, A_fontsize_28);
   ObjectSetText(A_name_0, A_text_8, A_fontsize_28, A_fontname_32, A_color_40);
   ObjectSet(A_name_0, OBJPROP_SELECTABLE, false);
}

