/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2006, FX Sniper and Robert Hill"
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_levelcolor Black
#property indicator_levelstyle 1
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_width1 2
#property indicator_level1 250.0
#property indicator_width2 2
#property indicator_level2 -250.0

extern int MAPeriod = 21;
extern int MAType = 0;
double gda_84[];
double gda_88[];
double gda_92[];
int gi_96;
string gs_100;

int init() {
   IndicatorBuffers(3);
   SetIndexBuffer(2, gda_84);
   SetIndexBuffer(1, gda_88);
   SetIndexBuffer(0, gda_92);
   SetIndexStyle(2, DRAW_LINE, STYLE_SOLID);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);
   switch (MAType) {
   case 1:
      gs_100 = "EMA";
      gi_96 = 1;
      break;
   case 2:
      gs_100 = "SMMA";
      gi_96 = 2;
      break;
   case 3:
      gs_100 = "LWMA";
      gi_96 = 3;
      break;
   case 4:
      gs_100 = "LSMA";
      break;
   default:
      gs_100 = "SMA";
      gi_96 = 0;
   }
   IndicatorShortName(gs_100 + " (" + MAPeriod + ") ");
   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_40 = 6.0 * ld_12 / (li_20 * (li_20 + 1));
   return (ld_40);
}

int start() {
   double ld_0;
   double ld_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 (MAType == 4) {
         ld_0 = LSMA(MAPeriod, li_24);
         ld_8 = LSMA(MAPeriod, li_24 + 1);
      } else {
         ld_0 = iMA(NULL, 0, MAPeriod, 0, gi_96, PRICE_CLOSE, li_24);
         ld_8 = iMA(NULL, 0, MAPeriod, 0, gi_96, PRICE_CLOSE, li_24 + 1);
      }
      gda_92[li_24] = ld_0;
      gda_88[li_24] = ld_0;
      gda_84[li_24] = ld_0;
      if (ld_8 > ld_0) gda_88[li_24] = EMPTY_VALUE;
      else {
         if (ld_8 < ld_0) gda_84[li_24] = EMPTY_VALUE;
         else {
            gda_84[li_24] = EMPTY_VALUE;
            gda_88[li_24] = EMPTY_VALUE;
         }
      }
   }
   return (0);
}
