/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/

#property indicator_chart_window
#property indicator_levelcolor Black
#property indicator_levelstyle 1
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_width1 3
#property indicator_level1 250.0
#property indicator_width2 3
#property indicator_level2 -250.0

int g_period_76 = 21;
int gi_80 = 1;
double g_ibuf_84[];
double g_ibuf_88[];
double g_ibuf_92[];
int g_ma_method_96;
string gs_100;

int init() {
   IndicatorBuffers(3);
   SetIndexBuffer(2, g_ibuf_84);
   SetIndexBuffer(1, g_ibuf_88);
   SetIndexBuffer(0, g_ibuf_92);
   SetIndexStyle(2, DRAW_LINE, STYLE_SOLID);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);
   switch (gi_80) {
   case 1:
      gs_100 = "EMA";
      g_ma_method_96 = 1;
      break;
   case 2:
      gs_100 = "SMMA";
      g_ma_method_96 = 2;
      break;
   case 3:
      gs_100 = "LWMA";
      g_ma_method_96 = 3;
      break;
   case 4:
      gs_100 = "LSMA";
      break;
   default:
      gs_100 = "SMA";
      g_ma_method_96 = 0;
   }
   IndicatorShortName(gs_100 + " (" + g_period_76 + ") ");
   return (0);
}

double LSMA(int ai_0, int ai_4) {
   double ld_24;
   double ld_32;
   int li_20 = ai_0;
   double ld_12 = 0;
   for (int li_8 = li_20; li_8 >= 1; li_8--) {
      ld_24 = li_20 + 1;
      ld_24 /= 3.0;
      ld_32 = 0;
      ld_32 = (li_8 - ld_24) * (Close[li_20 - li_8 + ai_4]);
      ld_12 += ld_32;
   }
   double ld_ret_40 = 6.0 * ld_12 / (li_20 * (li_20 + 1));
   return (ld_ret_40);
}

int start() {
   double l_ima_0;
   double l_ima_8;
   int li_20 = IndicatorCounted();
   if (li_20 < 0) return (-1);
   if (li_20 > 0) li_20--;
   int li_16 = Bars - li_20;
   for (int li_24 = li_16; li_24 >= 0; li_24--) {
      if (gi_80 == 4) {
         l_ima_0 = LSMA(g_period_76, li_24);
         l_ima_8 = LSMA(g_period_76, li_24 + 1);
      } else {
         l_ima_0 = iMA(NULL, 0, g_period_76, 0, g_ma_method_96, PRICE_CLOSE, li_24);
         l_ima_8 = iMA(NULL, 0, g_period_76, 0, g_ma_method_96, PRICE_CLOSE, li_24 + 1);
      }
      g_ibuf_92[li_24] = l_ima_0;
      g_ibuf_88[li_24] = l_ima_0;
      g_ibuf_84[li_24] = l_ima_0;
      if (l_ima_8 > l_ima_0) g_ibuf_88[li_24] = EMPTY_VALUE;
      else {
         if (l_ima_8 < l_ima_0) g_ibuf_84[li_24] = EMPTY_VALUE;
         else {
            g_ibuf_84[li_24] = EMPTY_VALUE;
            g_ibuf_88[li_24] = EMPTY_VALUE;
         }
      }
   }
   return (0);
}
