/*
   G e n e r a t e d  by ex4-to-mq4 decompiler FREEWARE 4.0.509.5
   Website: H ttp : / /WWW . mEt a Qu OtEs .N E t
   E-mail : sUP Po RT@M e TAq u O T Es. NeT
*/
#property copyright "TDI+"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 Aqua
#property indicator_color2 Aqua
#property indicator_color3 Yellow
#property indicator_color4 Green
#property indicator_color5 Red
#property indicator_color6 FireBrick
#property indicator_color7 LimeGreen
#property indicator_color8 CLR_NONE

#include <WinUser32.mqh>
#import "user32.dll"
   int GetParent(int a0);
   int SetWindowTextA(int a0, string a1);
#import

extern string UseSymbol = "";
extern string UseSymbol_note = "---- If empty indicator will use current symbol";
extern string ______Shark_Fin_Alerts_____ = "";
extern bool AlertPopup = FALSE;
extern bool AlertSound = FALSE;
extern string AlertSoundFile = "alert.wav";
extern bool AlertMail = FALSE;
extern string _____Level_Line_Colors_____ = "";
extern color LevelExtremeHighColor = Red;
extern color LevelHighColor = Pink;
extern color LevelMiddleColor = DimGray;
extern color LevelLowColor = LawnGreen;
extern color LevelExtremeLowColor = DarkGreen;
extern string LevelColor_note = "---- Use NONE value to hide the line";
extern int LevelWidth = 1;
extern int LevelStyle = 2;
extern bool ShowLevelValue = TRUE;
extern string _____Advanced_Settings_____ = "";
extern int LevelExtremeHigh = 80;
extern int LevelHigh = 70;
extern int LevelMiddle = 50;
extern int LevelLow = 30;
extern int LevelExtremeLow = 20;
extern string Level_note = "---- Use 0 value to hide the level";
extern int RSIPeriod = 21;
extern int PriceLinePeriod = 2;
extern int SignalLinePeriod = 7;
extern int VolatilityBandPeriod = 34;
extern string revision_6 = "revision 6";
string Gs_228 = "TDI+";
double G_ibuf_236[];
double G_ibuf_240[];
double G_ibuf_244[];
double G_ibuf_248[];
double G_ibuf_252[];
double G_ibuf_256[];
double G_ibuf_260[];
double G_ibuf_264[];
int G_window_268 = -1;
int Gi_272 = 0;
bool Gi_276 = FALSE;
string Gs_280 = "";
bool Gi_288 = FALSE;
int Gi_292 = 0;

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   string Ls_0;
   int Lia_8[5];
   IndicatorDigits(2);
   SetLevelStyle(12, 1, CLR_NONE);
   SetLevelValue(0, 0);
   SetLevelValue(1, 0);
   SetLevelValue(2, 0);
   SetLevelValue(3, 0);
   SetLevelValue(4, 0);
   UseSymbol = StringTrimLeft(StringTrimRight(UseSymbol));
   Gs_280 = Gs_228;
   if (UseSymbol != "") {
      if (!f0_3(UseSymbol)) {
         Ls_0 = "Not valid symbol " + UseSymbol + " for " + Gs_228;
         Alert(Ls_0);
         IndicatorShortName(Ls_0);
         return (-1);
      }
      Gs_280 = UseSymbol + " " + Gs_228;
      Gi_288 = TRUE;
   } else UseSymbol = Symbol();
   color color_12 = CLR_NONE;
   Lia_8[0] = LevelExtremeHighColor;
   Lia_8[1] = LevelHighColor;
   Lia_8[2] = LevelMiddleColor;
   Lia_8[3] = LevelLowColor;
   Lia_8[4] = LevelExtremeLowColor;
   Gi_276 = FALSE;
   for (int index_16 = 0; index_16 < ArraySize(Lia_8); index_16++) {
      if (Lia_8[index_16] >= 0) {
         if (color_12 == CLR_NONE) color_12 = Lia_8[index_16];
         if (color_12 != Lia_8[index_16]) Gi_276 = TRUE;
      }
   }
   if (LevelWidth > 1 && LevelStyle != 0) LevelStyle = 0;
   if (ShowLevelValue == FALSE) Gi_276 = TRUE;
   if (Gi_276 == FALSE) {
      SetLevelStyle(LevelStyle, LevelWidth, color_12);
      if (LevelExtremeHigh != 0 && LevelExtremeHighColor >= Black) SetLevelValue(0, LevelExtremeHigh);
      if (LevelHigh != 0 && LevelHighColor >= Black) SetLevelValue(1, LevelHigh);
      if (LevelMiddle != 0 && LevelMiddleColor >= Black) SetLevelValue(2, LevelMiddle);
      if (LevelLow != 0 && LevelLowColor >= Black) SetLevelValue(3, LevelLow);
      if (LevelExtremeLow != 0 && LevelExtremeLowColor >= Black) SetLevelValue(4, LevelExtremeLow);
      deinit();
   }
   IndicatorBuffers(8);
   SetIndexBuffer(0, G_ibuf_236);
   SetIndexBuffer(1, G_ibuf_240);
   SetIndexBuffer(2, G_ibuf_244);
   SetIndexBuffer(3, G_ibuf_248);
   SetIndexBuffer(4, G_ibuf_252);
   SetIndexBuffer(5, G_ibuf_256);
   SetIndexBuffer(6, G_ibuf_260);
   SetIndexBuffer(7, G_ibuf_264);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexStyle(3, DRAW_LINE);
   SetIndexStyle(4, DRAW_LINE);
   SetIndexStyle(5, DRAW_LINE);
   SetIndexStyle(6, DRAW_LINE);
   SetIndexStyle(7, DRAW_NONE);
   SetIndexLabel(0, NULL);
   SetIndexLabel(1, NULL);
   SetIndexLabel(2, NULL);
   SetIndexLabel(3, "RSI Price Line");
   SetIndexLabel(4, NULL);
   SetIndexLabel(5, NULL);
   SetIndexLabel(6, NULL);
   SetIndexLabel(7, NULL);
   return (0);
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
   ObjectDelete(Gs_228 + G_window_268 + "_LevelExtremeHigh");
   ObjectDelete(Gs_228 + G_window_268 + "_LevelHigh");
   ObjectDelete(Gs_228 + G_window_268 + "_LevelMiddle");
   ObjectDelete(Gs_228 + G_window_268 + "_LevelLow");
   ObjectDelete(Gs_228 + G_window_268 + "_LevelExtremeLow");
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   double Ld_0;
   double Lda_8[];
   string Ls_28;
   ArrayResize(Lda_8, VolatilityBandPeriod);
   int Li_20 = Bars - IndicatorCounted() - 1;
   for (int Li_12 = Li_20; Li_12 >= 0; Li_12--) {
      G_ibuf_264[Li_12] = iRSI(UseSymbol, Period(), RSIPeriod, PRICE_CLOSE, Li_12);
      Ld_0 = 0;
      for (int Li_24 = Li_12; Li_24 < Li_12 + VolatilityBandPeriod; Li_24++) {
         Lda_8[Li_24 - Li_12] = G_ibuf_264[Li_24];
         Ld_0 += G_ibuf_264[Li_24] / VolatilityBandPeriod;
      }
      G_ibuf_236[Li_12] = Ld_0 + 1.6185 * f0_0(Lda_8, VolatilityBandPeriod);
      G_ibuf_240[Li_12] = Ld_0 - 1.6185 * f0_0(Lda_8, VolatilityBandPeriod);
      G_ibuf_244[Li_12] = (G_ibuf_236[Li_12] + G_ibuf_240[Li_12]) / 2.0;
   }
   for (Li_12 = Li_20 - 1; Li_12 >= 0; Li_12--) {
      G_ibuf_248[Li_12] = iMAOnArray(G_ibuf_264, 0, PriceLinePeriod, 0, MODE_SMA, Li_12);
      G_ibuf_252[Li_12] = iMAOnArray(G_ibuf_264, 0, SignalLinePeriod, 0, MODE_SMA, Li_12);
      G_ibuf_256[Li_12] = EMPTY_VALUE;
      G_ibuf_260[Li_12] = EMPTY_VALUE;
   }
   if (Gi_276) {
      if (G_window_268 == -1) {
         MathSrand(GetTickCount());
         Ls_28 = Gs_228 + Seconds() + MathRand();
         IndicatorShortName(Ls_28);
         G_window_268 = WindowFind(Ls_28);
         IndicatorShortName(Gs_280);
      }
      f0_6(Gs_228 + G_window_268 + "_LevelExtremeHigh", LevelExtremeHigh, LevelExtremeHighColor);
      f0_6(Gs_228 + G_window_268 + "_LevelHigh", LevelHigh, LevelHighColor);
      f0_6(Gs_228 + G_window_268 + "_LevelMiddle", LevelMiddle, LevelMiddleColor);
      f0_6(Gs_228 + G_window_268 + "_LevelLow", LevelLow, LevelLowColor);
      f0_6(Gs_228 + G_window_268 + "_LevelExtremeLow", LevelExtremeLow, LevelExtremeLowColor);
   }
   if (IsDllsAllowed() && Gi_288) SetWindowTextA(GetParent(WindowHandle(Symbol(), 0)), Gs_228 + " " + f0_4(Period()));
   if (Time[0] != Gi_292) {
      Gi_292 = Time[0];
      if (f0_1() && LevelHigh != 0) f0_2(UseSymbol + ": Upper Shark Fin", G_ibuf_256);
      if (f0_5() && LevelLow != 0) f0_2(UseSymbol + ": Lower Shark Fin", G_ibuf_260);
   }
   return (0);
}

// 2314816F7AAD707E9F271CD7C0C76DC8
double f0_0(double Ada_0[], int Ai_4) {
   double Ld_8;
   double Ld_16;
   for (int index_24 = 0; index_24 < Ai_4; index_24++) {
      Ld_8 += Ada_0[index_24];
      Ld_16 += MathPow(Ada_0[index_24], 2);
   }
   return (MathSqrt((Ld_16 * Ai_4 - Ld_8 * Ld_8) / (Ai_4 * (Ai_4 - 1))));
}

// 5EEDCCAA1778992C2A6E4C5A9C9A5B6B
bool f0_3(string A_symbol_0) {
   double bid_8 = MarketInfo(A_symbol_0, MODE_BID);
   if (GetLastError() == 4106/* UNKNOWN_SYMBOL */) return (FALSE);
   return (TRUE);
}

// EE1166EA6E157B9C21187813EFA22CB2
void f0_6(string A_name_0, double A_price_8, color A_color_16) {
   if (A_price_8 == 0.0 || A_color_16 < Black) {
      ObjectDelete(A_name_0);
      return;
   }
   if (ObjectFind(A_name_0) != 0) {
      if (ShowLevelValue) ObjectCreate(A_name_0, OBJ_HLINE, G_window_268, 0, A_price_8);
      else ObjectCreate(A_name_0, OBJ_TREND, G_window_268, Time[0] + 31536000, A_price_8, Time[0], A_price_8);
   }
   ObjectSet(A_name_0, OBJPROP_PRICE1, A_price_8);
   ObjectSet(A_name_0, OBJPROP_PRICE2, A_price_8);
   ObjectSet(A_name_0, OBJPROP_STYLE, LevelStyle);
   ObjectSet(A_name_0, OBJPROP_COLOR, A_color_16);
   ObjectSet(A_name_0, OBJPROP_WIDTH, LevelWidth);
   ObjectSet(A_name_0, OBJPROP_BACK, TRUE);
   if (ShowLevelValue == FALSE) ObjectSet(A_name_0, OBJPROP_RAY, TRUE);
}

// 4BBEC4302E0AF45D741B8E0A30AF19AD
void f0_2(string As_0, double &Ada_8[]) {
   bool Li_16 = FALSE;
   if (AlertPopup) {
      Alert(As_0);
      Li_16 = TRUE;
   }
   if (AlertSound && AlertSoundFile != "") {
      PlaySound(AlertSoundFile);
      Li_16 = TRUE;
   }
   if (AlertMail) {
      SendMail(As_0, As_0 + " " + TimeMonth(TimeLocal()) + "/" + TimeDay(TimeLocal()) + "/" + TimeYear(TimeLocal()) + " " + TimeToStr(TimeLocal(), TIME_SECONDS));
      Li_16 = TRUE;
   }
   if (Li_16) for (int index_12 = 0; index_12 <= Gi_272; index_12++) Ada_8[index_12] = G_ibuf_248[index_12];
}

// B69AE6435CA312EDB19A3B43ADC42BDE
string f0_4(int Ai_0) {
   switch (Ai_0) {
   case 1:
      return ("M1");
   case 5:
      return ("M5");
   case 15:
      return ("M15");
   case 30:
      return ("M30");
   case 60:
      return ("H1");
   case 240:
      return ("H4");
   case 1440:
      return ("D1");
   case 10080:
      return ("W1");
   case 43200:
      return ("MN");
   }
   return ("");
}

// 4B2FFB09A3D4651138C5611B735DF88F
int f0_1() {
   if (G_ibuf_248[0] > G_ibuf_236[0]) return (0);
   bool Li_ret_0 = FALSE;
   double Ld_4 = G_ibuf_248[0];
   double Ld_12 = G_ibuf_236[0];
   for (int Li_20 = 1; Li_20 < 20; Li_20++) {
      if (G_ibuf_248[Li_20] > Ld_4) {
         Ld_4 = G_ibuf_248[Li_20];
         Ld_12 = G_ibuf_236[Li_20];
      }
      if (G_ibuf_248[Li_20] < G_ibuf_236[Li_20]) {
         Li_ret_0 = TRUE;
         Gi_272 = Li_20;
         break;
      }
   }
   if (Ld_4 < Ld_12 || Li_20 < 2 || Ld_4 < LevelHigh) Li_ret_0 = FALSE;
   return (Li_ret_0);
}

// DB8315E84310EAEA5BC04B823EFBA37D
int f0_5() {
   if (G_ibuf_248[0] < G_ibuf_240[0]) return (0);
   bool Li_ret_0 = FALSE;
   double Ld_4 = G_ibuf_248[0];
   double Ld_12 = G_ibuf_240[0];
   for (int Li_20 = 1; Li_20 < 20; Li_20++) {
      if (G_ibuf_248[Li_20] < Ld_4) {
         Ld_4 = G_ibuf_248[Li_20];
         Ld_12 = G_ibuf_240[Li_20];
      }
      if (G_ibuf_248[Li_20] > G_ibuf_240[Li_20]) {
         Li_ret_0 = TRUE;
         Gi_272 = Li_20;
         break;
      }
   }
   if (Ld_4 > Ld_12 || Li_20 < 2 || Ld_4 > LevelLow) Li_ret_0 = FALSE;
   return (Li_ret_0);
}
