/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "www.copypastepips.com"
#property link      "http://www.copypastepips.com"

#property indicator_separate_window
#property indicator_levelcolor LightGray
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Black
#property indicator_color4 Black

#import "BladeTradingSystem.dll"
//   bool Activate(string a0, string a1, int a2, int a3, string a4);
   void GetLastErrorDescription(string a0);
   double func101(double a0);
#import

extern int BarsBack = 500;
extern int CCPeriod = 50;
extern int ATRPeriod = 5;
bool gi_88 = FALSE;
bool gi_92 = FALSE;
string gs_96;
int gi_104;
double gd_108;
double g_ibuf_116[];
double g_ibuf_120[];
double g_ibuf_124[];
double g_ibuf_128[];
int gi_132 = 0;

int init() {
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 4);
   SetIndexBuffer(0, g_ibuf_116);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 4);
   SetIndexBuffer(1, g_ibuf_120);
   SetIndexBuffer(2, g_ibuf_124);
   SetIndexBuffer(3, g_ibuf_128);
   IndicatorShortName("BladeOscillator");
   if (IsDemo()) gi_104 = 1;
   else gi_104 = 2;
   if (AccountNumber() == 0) {
      gi_88 = TRUE;
      return (0);
   }
 //  gi_92 = Activate(TerminalPath(), "" + AccountNumber(), gi_104, 1, "BladeOscillator");
   gi_92 = TRUE; //added
   if (gi_92) {
      Print("BladeOscillator License Activated");
      Comment("BladeOscillator License Activated");
   }
   gs_96 = "1231231231313311111111111111111111111111111111111111111111111111111111111111111111111111111111111";
   GetLastErrorDescription(gs_96);
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   int li_0;
   double ld_4;
   double ld_12;
   double l_icci_20;
   double l_icci_28;
   if (gi_88) {
      if (AccountNumber() == 0) {
         Comment("Connecting to license server...");
         return (0);
      }
      gi_88 = FALSE;
      if (IsDemo()) gi_104 = 1;
      else gi_104 = 2;
  //    gi_92 = Activate(TerminalPath(), "" + AccountNumber(), gi_104, 1, "BladeOscillator");
      gi_92 = TRUE;  //added 
      if (gi_92) {
         Print("BladeOscillator License Activated");
         Comment("BladeOscillator License Activated");
      }
      gs_96 = "1231231231313311111111111111111111111111111111111111111111111111111111111111111111111111111111111";
      GetLastErrorDescription(gs_96);
   }
   if (gi_92 == FALSE) {
      Comment(gs_96);
      return (0);
   }
   gd_108 = func101(Close[0]);
   if (BarsBack >= Bars) BarsBack = Bars - 2;
   for (int li_36 = BarsBack; li_36 >= 0; li_36--) {
      g_ibuf_116[li_36] = EMPTY_VALUE;
      g_ibuf_120[li_36] = EMPTY_VALUE;
   }
   for (li_36 = BarsBack; li_36 >= 0; li_36--) {
      l_icci_20 = iCCI(NULL, 0, CCPeriod, PRICE_TYPICAL, li_36);
      l_icci_28 = iCCI(NULL, 0, CCPeriod, PRICE_TYPICAL, li_36 + 1);
      li_0 = li_36;
      ld_4 = 0;
      ld_12 = 0;
      for (li_0 = li_36; li_0 >= li_36 - 9; li_0--) ld_12 += MathAbs(High[li_0] - Low[li_0]);
      ld_4 = ld_12 / gd_108;
      if (l_icci_20 >= gi_132 && l_icci_28 < gi_132) g_ibuf_116[li_36 + 1] = g_ibuf_120[li_36 + 1];
      if (l_icci_20 <= gi_132 && l_icci_28 > gi_132) g_ibuf_120[li_36 + 1] = g_ibuf_116[li_36 + 1];
      if (l_icci_20 >= gi_132) {
         g_ibuf_116[li_36] = Low[li_36] - iATR(NULL, 0, ATRPeriod, li_36);
         if (g_ibuf_116[li_36] < g_ibuf_116[li_36 + 1]) g_ibuf_116[li_36] = g_ibuf_116[li_36 + 1];
      } else {
         if (l_icci_20 <= gi_132) {
            g_ibuf_120[li_36] = High[li_36] + iATR(NULL, 0, ATRPeriod, li_36);
            if (g_ibuf_120[li_36] > g_ibuf_120[li_36 + 1]) g_ibuf_120[li_36] = g_ibuf_120[li_36 + 1];
         }
      }
   }
   for (li_36 = BarsBack; li_36 >= 0; li_36--) {
      if (g_ibuf_120[li_36] != EMPTY_VALUE && g_ibuf_120[li_36] > 0.0) g_ibuf_120[li_36] = Close[li_36] - g_ibuf_120[li_36];
      if (g_ibuf_116[li_36] != EMPTY_VALUE && g_ibuf_116[li_36] > 0.0) g_ibuf_116[li_36] = Close[li_36] - g_ibuf_116[li_36];
   }
   return (0);
}