/*
   Generated by EX4-TO-MQ4 decompiler V4.0.427.4 [-]
   Website: https://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2012, Dean Malone"
#property link      "http://www.synergyprotrader.com"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DarkGreen
#property indicator_color2 FireBrick
#property indicator_color3 DarkGoldenrod

#import "CompassFX.dll"
   string gGrab(string a0, string a1);
#import "synergy_pro.dll"
   string returnReg(string a0, string a1);
#import

int g_file_76;
bool gi_80 = FALSE;
string gs_unused_84;
double gd_unused_92 = 1.1;
extern string Custom_Indicator = "Synergy Pro Dynamic S/R";
extern string Copyright = "© 2012, Dean Malone";
extern string Web_Address = "www.synergyprotrader.com";
extern string Color = "=== Color settings ===";
extern color Resistance_Color = DarkGreen;
extern color Support_Color = FireBrick;
extern color Mean_Color = DarkGoldenrod;
double g_ibuf_144[];
double g_ibuf_148[];
double g_ibuf_152[];
double g_ibuf_156[];
double g_ibuf_160[];

int f0_1() {
   int str2int_0;
   bool li_4;
   int li_8;
   g_file_76 = FileOpen("synergy_d.bin", FILE_CSV|FILE_READ);
   if (g_file_76 < 1) li_4 = FALSE;
   else {
      str2int_0 = StrToInteger(FileReadString(g_file_76));
      FileClose(g_file_76);
      li_4 = TRUE;
   }
   if (TimeLocal() - str2int_0 >= 86400 || li_4 == FALSE) {
      li_8 = f0_0();
      switch (li_8) {
      case 0:
         g_file_76 = FileOpen("synergy_d.bin", FILE_WRITE, 8);
         if (g_file_76 < 1) {
            Print("Cannot open password cache!");
            return (0);
         }
         FileWrite(g_file_76, TimeLocal());
         FileClose(g_file_76);
         break;
      case 1:
         Alert("Invalid software key provided!! Please re-install the software with the correct key.");
         gi_80 = TRUE;
         break;
      case 4:
         Alert("Your account has been disabled! Please contact support@compassfx.com");
         gi_80 = TRUE;
         break;
      case 5:
         Alert("Server error!! Please make sure you are connected to the Internet and try again.");
         gi_80 = TRUE;
         break;
      case 6:
         Alert("No key found in your registry (could be a bad installation)! Please re-install Synergy.");
         gi_80 = TRUE;
      }
   }
   return (0);
}

int f0_0() {
   string ls_unused_0;
   string ls_unused_8;
   string ls_unused_16;
   string ls_24 = returnReg("Software\\CompassFX\\Synergy", "key");
   if (ls_24 == "") return (6);
   string ls_32 = "key=" + ls_24;
   string ls_40 = gGrab("http://www.compassfx.com/synergy_scripts/s_login.php", ls_32);
   Print("Result -- ", ls_40);
   if (StringSubstr(ls_40, 0, 1) == "0") {
      gs_unused_84 = ls_40;
      return (0);
   }
   if (StringSubstr(ls_40, 0, 1) == "1") return (1);
   if (StringSubstr(ls_40, 0, 1) == "4") return (4);
   return (5);
}

int init() {
   HideTestIndicators(TRUE);
   IndicatorBuffers(5);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2, Resistance_Color);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2, Support_Color);
   SetIndexStyle(2, DRAW_LINE, STYLE_DOT, 1, Mean_Color);
   SetIndexBuffer(0, g_ibuf_148);
   SetIndexBuffer(1, g_ibuf_144);
   SetIndexBuffer(2, g_ibuf_152);
   SetIndexBuffer(3, g_ibuf_156);
   SetIndexBuffer(4, g_ibuf_160);
   SetIndexLabel(0, "Dynamic_Resistance");
   SetIndexLabel(1, "Dynamic_Support");
   SetIndexLabel(2, "Dynamic_Mean");
   SetIndexDrawBegin(0, 25);
   SetIndexDrawBegin(1, 25);
   SetIndexDrawBegin(2, 25);
   IndicatorShortName("Synergy_Pro_DSR");
   //f0_1();
   return (0);
}

int start() {
   if (gi_80) return (0);
   int ind_counted_0 = IndicatorCounted();
   if (Bars <= 25) return (0);
   int li_4 = Bars - ind_counted_0;
   if (ind_counted_0 > 0) li_4++;
   else {
      g_ibuf_148[li_4] = High[li_4];
      g_ibuf_144[li_4] = Low[li_4];
   }
   for (int li_8 = 0; li_8 < li_4; li_8++) g_ibuf_156[li_8] = (High[iHighest(NULL, 0, MODE_HIGH, 3, li_8)] + Low[iLowest(NULL, 0, MODE_LOW, 3, li_8)] + Close[li_8]) / 3.0;
   for (li_8 = 0; li_8 < li_4; li_8++) g_ibuf_160[li_8] = iMAOnArray(g_ibuf_156, Bars, 25, 0, MODE_SMA, li_8);
   for (li_8 = li_4 - 1; li_8 >= 0; li_8--) {
      if (g_ibuf_156[li_8 + 1] > g_ibuf_160[li_8 + 1] && g_ibuf_156[li_8] < g_ibuf_160[li_8]) g_ibuf_148[li_8] = High[iHighest(NULL, 0, MODE_HIGH, 28, li_8)];
      else g_ibuf_148[li_8] = g_ibuf_148[li_8 + 1];
   }
   for (li_8 = li_4 - 1; li_8 >= 0; li_8--) {
      if (g_ibuf_156[li_8 + 1] < g_ibuf_160[li_8 + 1] && g_ibuf_156[li_8] > g_ibuf_160[li_8]) g_ibuf_144[li_8] = Low[iLowest(NULL, 0, MODE_LOW, 28, li_8)];
      else g_ibuf_144[li_8] = g_ibuf_144[li_8 + 1];
   }
   for (li_8 = 0; li_8 < li_4; li_8++) g_ibuf_152[li_8] = NormalizeDouble((g_ibuf_148[li_8] + g_ibuf_144[li_8]) / 2.0, Digits);
   return (0);
}