/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/

#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Black
#property indicator_color2 MediumBlue
#property indicator_color3 Yellow
#property indicator_color4 MediumBlue
#property indicator_color5 Green
#property indicator_color6 Red
#property indicator_color7 Aqua

extern string TimeFrame = "Current time frame";
extern string IndicatorUniqueID = "Traders Dynamic Index Visual mtf";
extern bool Show_VISUAL_Alerts = TRUE;
extern int SHIFT_Sideway = 0;
extern int SHIFT_Up_Down = 0;
extern int RSI_Period = 13;
extern int RSI_Price = 0;
extern int Volatility_Band = 34;
extern int RSI_Price_Line = 2;
extern int RSI_Price_Type = 0;
extern int Trade_Signal_Line = 7;
extern bool SHOW_Trade_Signal_Line2 = TRUE;
extern int Trade_Signal_Line2 = 18;
extern int Trade_Signal_Type = 0;
extern bool Interpolate = true;
double g_ibuf_124[];
double g_ibuf_128[];
double g_ibuf_132[];
double g_ibuf_136[];
double g_ibuf_140[];
double g_ibuf_144[];
double g_ibuf_148[];
double g_bid_152;

//
//
//
//
//

string indicatorFileName;
bool   calculateValue;
bool   returnBars;
int    timeFrame;

int init() {
   IndicatorShortName(IndicatorUniqueID);
   SetIndexBuffer(0, g_ibuf_124);
   SetIndexBuffer(1, g_ibuf_128);
   SetIndexBuffer(2, g_ibuf_132);
   SetIndexBuffer(3, g_ibuf_136);
   SetIndexBuffer(4, g_ibuf_140);
   SetIndexBuffer(5, g_ibuf_144);
   if (SHOW_Trade_Signal_Line2 == DRAW_SECTION) SHOW_Trade_Signal_Line2 = FALSE;
   else SHOW_Trade_Signal_Line2 = 12;
   SetIndexStyle(6, SHOW_Trade_Signal_Line2);
   SetIndexBuffer(6, g_ibuf_148);
   SetIndexStyle(0, DRAW_NONE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexStyle(3, DRAW_LINE);
   SetIndexStyle(4, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexStyle(5, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexLabel(0, NULL);
   SetIndexLabel(1, "VB High");
   SetIndexLabel(2, "Market Base Line");
   SetIndexLabel(3, "VB Low");
   SetIndexLabel(4, "RSI Price Line");
   SetIndexLabel(5, "Trade Signal Line");
   SetIndexLabel(6, "Trade Signal2 Line");

      //
      //
      //
      //
      //

      indicatorFileName = WindowExpertName();
      calculateValue    = (TimeFrame=="calculateValue"); if (calculateValue) return(0);
      returnBars        = (TimeFrame=="returnBars");     if (returnBars)     return(0);
      timeFrame         = stringToTimeFrame(TimeFrame);

   return (0);
}

int deinit() {
   ObjectsDeleteAll(0, OBJ_TREND);
   ObjectDelete("TDI_SIG");
   ObjectDelete("TDI_SIG1");
   ObjectDelete("TDI_SIG2");
   ObjectDelete("TDI_SIG3");
   ObjectDelete("TDI_SIG4");
   ObjectDelete("TDI_SIG5");
   ObjectDelete("TDI_SIG6");
   ObjectDelete("TDI_SIG7");
   ObjectDelete("TDI_SIG8");
   ObjectDelete("TDI_SIG9");
   return (0);
}

int start() {
   CreateLEVEL();
   return (0);
}

void Createline(string a_name_0, double a_price_8, double a_price_16, color a_color_24) {
   ObjectCreate(a_name_0, OBJ_TREND, WindowFind(IndicatorUniqueID), 0, a_price_8, Time[0], a_price_16);
   ObjectSet(a_name_0, OBJPROP_COLOR, a_color_24);
   ObjectSet(a_name_0, OBJPROP_STYLE, STYLE_DOT);
   ObjectSet(a_name_0, OBJPROP_RAY, FALSE);
}

void DeleteCreateline() {
   ObjectDelete("UPPERLINE");
   ObjectDelete("LOWERLINE");
   ObjectDelete("MEDLINE");
}

void CreateLEVEL() {
   double ld_0;
   double lda_8[];
   string l_text_28;
   string l_text_36;
   string l_text_44;
   string l_text_52;
   string l_text_60;
   string l_text_68;
   color l_color_76;
   color l_color_80;
   color l_color_84;
   color l_color_88;
   int li_unused_92;
   DeleteCreateline();
   Createline("UPPERLINE", 68, 68, C'0x46,0x46,0x46');
   Createline("LOWERLINE", 50, 50, C'0x00,0x46,0x00');
   Createline("MEDLINE", 32, 32, C'0x46,0x46,0x46');
   ArrayResize(lda_8, Volatility_Band);

   int l_ind_counted_12 = IndicatorCounted();

   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         int li_16 = MathMin(Bars-counted_bars,Bars-1);
         if (returnBars) { g_ibuf_124[0] = li_16+1; return(0); }

   //
   //
   //
   //
   //
   
   if (calculateValue || timeFrame == Period())
   {
   for (int li_20 = li_16; li_20 >= 0; li_20--) {
      g_ibuf_124[li_20] = iRSI(NULL, 0, RSI_Period, RSI_Price, li_20);
      ld_0 = 0;
      for (int li_24 = li_20; li_24 < li_20 + Volatility_Band; li_24++) {
         lda_8[li_24 - li_20] = g_ibuf_124[li_24];
         ld_0 += g_ibuf_124[li_24] / Volatility_Band;
      }
      g_ibuf_128[li_20] = ld_0 + 1.6185 * StDev(lda_8, Volatility_Band);
      g_ibuf_136[li_20] = ld_0 - 1.6185 * StDev(lda_8, Volatility_Band);
      g_ibuf_132[li_20] = (g_ibuf_128[li_20] + g_ibuf_136[li_20]) / 2.0;
   }
   for (li_20 = li_16 - 1; li_20 >= 0; li_20--) {
      g_ibuf_140[li_20] = iMAOnArray(g_ibuf_124, 0, RSI_Price_Line, 0, RSI_Price_Type, li_20);
      g_ibuf_144[li_20] = iMAOnArray(g_ibuf_124, 0, Trade_Signal_Line, 0, Trade_Signal_Type, li_20);
      g_ibuf_148[li_20] = iMAOnArray(g_ibuf_124, 0, Trade_Signal_Line2, 0, Trade_Signal_Type, li_20);
      l_text_28 = "";
      l_text_36 = "";
      l_text_44 = "";
      l_text_52 = "";
      l_text_60 = "";
      l_text_68 = "";
      if (Show_VISUAL_Alerts == TRUE && li_20==0) {
         li_unused_92 = 0;
         if (g_ibuf_140[0] > g_ibuf_144[0] && g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] < g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_28 = "é";
            l_color_76 = SeaGreen;
         }
         if (g_ibuf_140[0] > g_ibuf_144[0] && g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] < g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_44 = "Weak Buy";
            l_color_80 = SeaGreen;
         }
         if (g_ibuf_140[0] > g_ibuf_144[0] && g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] < g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_36 = " @ " + DoubleToStr(g_bid_152, Digits) + "";
            l_color_80 = SeaGreen;
         }
         if (g_ibuf_140[0] > g_ibuf_144[0] && g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] < g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            g_bid_152 = Bid;
            li_unused_92 = 2;
         }
         if (g_ibuf_140[0] < g_ibuf_144[0] && g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] > g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_28 = "ê";
            l_color_76 = Orange;
         }
         if (g_ibuf_140[0] < g_ibuf_144[0] && g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] > g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_44 = "Weak Sell";
            l_color_80 = Orange;
         }
         if (g_ibuf_140[0] < g_ibuf_144[0] && g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] > g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_36 = " @ " + DoubleToStr(g_bid_152, Digits) + "";
            l_color_80 = Orange;
         }
         if (g_ibuf_140[0] < g_ibuf_144[0] && g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] > g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            g_bid_152 = Bid;
            li_unused_92 = 1;
         }
         if (g_ibuf_140[0] > g_ibuf_144[0] && g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_28 = "é";
            l_color_76 = Lime;
         }
         if (g_ibuf_140[0] > g_ibuf_144[0] && g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_44 = "Strong Buy";
            l_color_80 = Lime;
         }
         if (g_ibuf_140[0] > g_ibuf_144[0] && g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_36 = " @ " + DoubleToStr(g_bid_152, Digits) + "";
            l_color_80 = Lime;
         }
         if (g_ibuf_140[0] > g_ibuf_144[0] && g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            g_bid_152 = Bid;
            li_unused_92 = 2;
         }
         if (g_ibuf_140[0] > g_ibuf_144[0] && g_ibuf_140[0] > g_ibuf_132[0] && g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_44 = "Medium Buy";
            l_color_80 = Green;
         }
         if (g_ibuf_140[0] > g_ibuf_144[0] && g_ibuf_140[0] > g_ibuf_132[0] && g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_36 = " @ " + DoubleToStr(g_bid_152, Digits) + "";
            l_color_80 = Green;
         }
         if (g_ibuf_140[0] > g_ibuf_144[0] && g_ibuf_140[0] > g_ibuf_132[0] && g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_68 = "é";
            l_color_80 = Green;
         }
         if (g_ibuf_140[0] > g_ibuf_144[0] && g_ibuf_140[0] > g_ibuf_132[0] && g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            g_bid_152 = Bid;
            li_unused_92 = 2;
         }
         if (g_ibuf_140[0] < g_ibuf_144[0] && g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_28 = "ê";
            l_color_76 = Red;
         }
         if (g_ibuf_140[0] < g_ibuf_144[0] && g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_44 = "Strong Sell";
            l_color_80 = Red;
         }
         if (g_ibuf_140[0] < g_ibuf_144[0] && g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_36 = " @ " + DoubleToStr(g_bid_152, Digits) + "";
            l_color_80 = Red;
         }
         if (g_ibuf_140[0] < g_ibuf_144[0] && g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            g_bid_152 = Bid;
            li_unused_92 = 1;
         }
         if (g_ibuf_140[0] < g_ibuf_144[0] && g_ibuf_140[0] < g_ibuf_132[0] && g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_44 = "Medium Sell";
            l_color_80 = Tomato;
         }
         if (g_ibuf_140[0] < g_ibuf_144[0] && g_ibuf_140[0] < g_ibuf_132[0] && g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_36 = " @ " + DoubleToStr(g_bid_152, Digits) + "";
            l_color_80 = Tomato;
         }
         if (g_ibuf_140[0] < g_ibuf_144[0] && g_ibuf_140[0] < g_ibuf_132[0] && g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            l_text_68 = "ê";
            l_color_80 = Tomato;
         }
         if (g_ibuf_140[0] < g_ibuf_144[0] && g_ibuf_140[0] < g_ibuf_132[0] && g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] > 32.0 && g_ibuf_140[0] < 68.0) {
            g_bid_152 = Bid;
            li_unused_92 = 1;
         }
         if (g_ibuf_140[0] >= 68.0) {
            l_text_28 = "ê";
            l_color_76 = Red;
         }
         if (g_ibuf_140[0] >= 68.0) {
            g_bid_152 = Bid;
            li_unused_92 = 2;
         }
         if (g_ibuf_140[0] >= 68.0) {
            l_text_44 = "Caution !";
            l_color_80 = Red;
         }
         if (g_ibuf_140[0] >= 68.0) {
            l_text_36 = " @ " + DoubleToStr(g_bid_152, Digits) + "";
            l_color_80 = Red;
         }
         if (g_ibuf_140[0] <= 32.0) {
            l_text_28 = "é";
            l_color_76 = Red;
         }
         if (g_ibuf_140[0] <= 32.0) {
            g_bid_152 = Bid;
            li_unused_92 = 1;
         }
         if (g_ibuf_140[0] <= 32.0) {
            l_text_44 = "Caution !";
            l_color_80 = Red;
         }
         if (g_ibuf_140[0] <= 32.0) {
            l_text_36 = " @ " + DoubleToStr(g_bid_152, Digits) + "";
            l_color_80 = Red;
         }
         if (g_ibuf_144[0] > g_ibuf_132[0]) {
            l_text_52 = "é";
            l_color_84 = Lime;
         }
         if (g_ibuf_144[0] < g_ibuf_132[0] && g_ibuf_140[0] > g_ibuf_132[0]) {
            l_text_52 = "é";
            l_color_84 = Orange;
         }
         if (g_ibuf_144[0] < g_ibuf_132[0]) {
            l_text_52 = "ê";
            l_color_84 = Red;
         }
         if (g_ibuf_144[0] > g_ibuf_132[0] && g_ibuf_140[0] < g_ibuf_132[0]) {
            l_text_52 = "é";
            l_color_84 = Green;
         }
         if (g_ibuf_128[0] - g_ibuf_136[li_20] < 20.0) {
            l_text_60 = "Consolidation";
            l_color_88 = Silver;
         }
         ObjectDelete("TDI_SIG");
         ObjectCreate("TDI_SIG", OBJ_LABEL, WindowFind(IndicatorUniqueID), 0, 0);
         ObjectSetText("TDI_SIG", l_text_28, 25, "Wingdings", l_color_76);
         ObjectSet("TDI_SIG", OBJPROP_CORNER, 1);
         ObjectSet("TDI_SIG", OBJPROP_XDISTANCE, SHIFT_Sideway + 80);
         ObjectSet("TDI_SIG", OBJPROP_YDISTANCE, SHIFT_Up_Down + 20);
         ObjectDelete("TDI_SIG1");
         ObjectCreate("TDI_SIG1", OBJ_LABEL, WindowFind(IndicatorUniqueID), 0, 0);
         ObjectSetText("TDI_SIG1", l_text_36, 15, "Tahoma Narrow", l_color_80);
         ObjectSet("TDI_SIG1", OBJPROP_CORNER, 1);
         ObjectSet("TDI_SIG1", OBJPROP_XDISTANCE, SHIFT_Sideway + 120);
         ObjectSet("TDI_SIG1", OBJPROP_YDISTANCE, SHIFT_Up_Down + 30);
         ObjectDelete("TDI_SIG2");
         ObjectCreate("TDI_SIG2", OBJ_LABEL, WindowFind(IndicatorUniqueID), 0, 0);
         ObjectSetText("TDI_SIG2", l_text_44, 15, "Tahoma Narrow", l_color_80);
         ObjectSet("TDI_SIG2", OBJPROP_CORNER, 1);
         ObjectSet("TDI_SIG2", OBJPROP_XDISTANCE, SHIFT_Sideway + 120);
         ObjectSet("TDI_SIG2", OBJPROP_YDISTANCE, SHIFT_Up_Down + 10);
         ObjectDelete("TDI_SIG3");
         ObjectCreate("TDI_SIG3", OBJ_LABEL, WindowFind(IndicatorUniqueID), 0, 0);
         ObjectSetText("TDI_SIG3", l_text_68, 25, "Wingdings", l_color_80);
         ObjectSet("TDI_SIG3", OBJPROP_CORNER, 1);
         ObjectSet("TDI_SIG3", OBJPROP_XDISTANCE, SHIFT_Sideway + 80);
         ObjectSet("TDI_SIG3", OBJPROP_YDISTANCE, SHIFT_Up_Down + 20);
         ObjectDelete("TDI_SIG4");
         ObjectCreate("TDI_SIG4", OBJ_LABEL, WindowFind(IndicatorUniqueID), 0, 0);
         ObjectSetText("TDI_SIG4", l_text_52, 25, "Wingdings", l_color_84);
         ObjectSet("TDI_SIG4", OBJPROP_CORNER, 1);
         ObjectSet("TDI_SIG4", OBJPROP_XDISTANCE, SHIFT_Sideway + 80);
         ObjectSet("TDI_SIG4", OBJPROP_YDISTANCE, SHIFT_Up_Down + 55);
         ObjectDelete("TDI_SIG5");
         ObjectCreate("TDI_SIG5", OBJ_LABEL, WindowFind(IndicatorUniqueID), 0, 0);
         ObjectSetText("TDI_SIG5", "TDI Trend", 15, "Tahoma Narrow", l_color_84);
         ObjectSet("TDI_SIG5", OBJPROP_CORNER, 1);
         ObjectSet("TDI_SIG5", OBJPROP_XDISTANCE, SHIFT_Sideway + 120);
         ObjectSet("TDI_SIG5", OBJPROP_YDISTANCE, SHIFT_Up_Down + 60);
         ObjectDelete("TDI_SIG6");
         ObjectCreate("TDI_SIG6", OBJ_LABEL, WindowFind(IndicatorUniqueID), 0, 0);
         ObjectSetText("TDI_SIG6", l_text_60, 15, "Tahoma Narrow", l_color_88);
         ObjectSet("TDI_SIG6", OBJPROP_CORNER, 1);
         ObjectSet("TDI_SIG6", OBJPROP_XDISTANCE, SHIFT_Sideway + 100);
         ObjectSet("TDI_SIG6", OBJPROP_YDISTANCE, SHIFT_Up_Down + 100);
      }
      ObjectDelete("TDI_SIG7");
      ObjectDelete("TDI_SIG7");
      if (ObjectFind("TDI_SIG7") != 0) {
         ObjectCreate("TDI_SIG7", OBJ_TEXT, WindowFind(IndicatorUniqueID), Time[0], 70);
         ObjectSetText("TDI_SIG7", "          68 ", 7, "Tahoma Narrow", CadetBlue);
      } else ObjectMove("TDI_SIG7", 0, Time[0], 70);
      ObjectDelete("TDI_SIG8");
      ObjectDelete("TDI_SIG8");
      if (ObjectFind("TDI_SIG8") != 0) {
         ObjectCreate("TDI_SIG8", OBJ_TEXT, WindowFind(IndicatorUniqueID), Time[0], 52);
         ObjectSetText("TDI_SIG8", "          50 ", 7, "Tahoma Narrow", CadetBlue);
      } else ObjectMove("TDI_SIG8", 0, Time[0], 52);
      ObjectDelete("TDI_SIG9");
      ObjectDelete("TDI_SIG9");
      if (ObjectFind("TDI_SIG9") != 0) {
         ObjectCreate("TDI_SIG9", OBJ_TEXT, WindowFind(IndicatorUniqueID), Time[0], 34);
         ObjectSetText("TDI_SIG9", "          32 ", 7, "Tahoma Narrow", CadetBlue);
      } else ObjectMove("TDI_SIG9", 0, Time[0], 34);
   }

   //
   //
   //
   //
   //
   
   return;
   }


   //
   //
   //
   //
   //

   int limit = MathMax(li_16,MathMin(Bars,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));
   for (int i=limit;i>=0;i--)
   {
      int y = iBarShift(NULL,timeFrame,Time[i]);
         g_ibuf_128[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",IndicatorUniqueID,Show_VISUAL_Alerts,SHIFT_Sideway,SHIFT_Up_Down,RSI_Period,RSI_Price,Volatility_Band,RSI_Price_Line,RSI_Price_Type,Trade_Signal_Line,SHOW_Trade_Signal_Line2,Trade_Signal_Line2,Trade_Signal_Type,1,y);
         g_ibuf_132[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",IndicatorUniqueID,Show_VISUAL_Alerts,SHIFT_Sideway,SHIFT_Up_Down,RSI_Period,RSI_Price,Volatility_Band,RSI_Price_Line,RSI_Price_Type,Trade_Signal_Line,SHOW_Trade_Signal_Line2,Trade_Signal_Line2,Trade_Signal_Type,2,y);
         g_ibuf_136[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",IndicatorUniqueID,Show_VISUAL_Alerts,SHIFT_Sideway,SHIFT_Up_Down,RSI_Period,RSI_Price,Volatility_Band,RSI_Price_Line,RSI_Price_Type,Trade_Signal_Line,SHOW_Trade_Signal_Line2,Trade_Signal_Line2,Trade_Signal_Type,3,y);
         g_ibuf_140[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",IndicatorUniqueID,Show_VISUAL_Alerts,SHIFT_Sideway,SHIFT_Up_Down,RSI_Period,RSI_Price,Volatility_Band,RSI_Price_Line,RSI_Price_Type,Trade_Signal_Line,SHOW_Trade_Signal_Line2,Trade_Signal_Line2,Trade_Signal_Type,4,y);
         g_ibuf_144[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",IndicatorUniqueID,Show_VISUAL_Alerts,SHIFT_Sideway,SHIFT_Up_Down,RSI_Period,RSI_Price,Volatility_Band,RSI_Price_Line,RSI_Price_Type,Trade_Signal_Line,SHOW_Trade_Signal_Line2,Trade_Signal_Line2,Trade_Signal_Type,5,y);

         //
         //
         //
         //
         //
      
            if (!Interpolate || y==iBarShift(NULL,timeFrame,Time[i-1])) continue;

         //
         //
         //
         //
         //

         datetime time = iTime(NULL,timeFrame,y);
            for(int n = 1; i+n < Bars && Time[i+n] >= time; n++) continue;	
            for(int k = 1; k < n; k++)
            {
               g_ibuf_128[i+k] = g_ibuf_128[i] + (g_ibuf_128[i+n] - g_ibuf_128[i])*k/n;
               g_ibuf_132[i+k] = g_ibuf_132[i] + (g_ibuf_132[i+n] - g_ibuf_132[i])*k/n;
               g_ibuf_136[i+k] = g_ibuf_136[i] + (g_ibuf_136[i+n] - g_ibuf_136[i])*k/n;
               g_ibuf_140[i+k] = g_ibuf_140[i] + (g_ibuf_140[i+n] - g_ibuf_140[i])*k/n;
               g_ibuf_144[i+k] = g_ibuf_144[i] + (g_ibuf_144[i+n] - g_ibuf_144[i])*k/n;
            }               
   }
   return;

}

double StDev(double ada_0[], int ai_4) {
   return (MathSqrt(Variance(ada_0, ai_4)));
}

double Variance(double ada_0[], int ai_4) {
   double ld_8;
   double ld_16;
   for (int l_index_24 = 0; l_index_24 < ai_4; l_index_24++) {
      ld_8 += ada_0[l_index_24];
      ld_16 += MathPow(ada_0[l_index_24], 2);
   }
   return ((ld_16 * ai_4 - ld_8 * ld_8) / (ai_4 * (ai_4 - 1)));
}

//+-------------------------------------------------------------------
//|                                                                  
//+-------------------------------------------------------------------
//
//
//
//
//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//
//
//
//
//

int stringToTimeFrame(string tfs)
{
   tfs = stringUpperCase(tfs);
   for (int i=ArraySize(iTfTable)-1; i>=0; i--)
         if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period()));
                                                      return(Period());
}
string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}

//
//
//
//
//

string stringUpperCase(string str)
{
   string   s = str;

   for (int length=StringLen(str)-1; length>=0; length--)
   {
      int char = StringGetChar(s, length);
         if((char > 96 && char < 123) || (char > 223 && char < 256))
                     s = StringSetChar(s, length, char - 32);
         else if(char > -33 && char < 0)
                     s = StringSetChar(s, length, char + 224);
   }
   return(s);
}

