/*
   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 2
#property indicator_color1 MediumSeaGreen
#property indicator_color2 Salmon

#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 Active S/R";
extern string Copyright = "© 2012, Dean Malone ";
extern string Web_Address = "www.synergyprotrader.com";
extern string Color = "=== Color settings ===";
extern color Resistance_Color = MediumSeaGreen;
extern color Support_Color = Salmon;
double g_ibuf_140[];
double g_ibuf_144[];
double g_ifractals_148;
double g_ifractals_156;
int g_bars_164;
double g_ima_168;
double g_ima_176;
double gd_184;

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(2);
   SetIndexBuffer(0, g_ibuf_140);
   SetIndexBuffer(1, g_ibuf_144);
   SetIndexArrow(0, 167);
   SetIndexArrow(1, 167);
   SetIndexStyle(0, DRAW_ARROW, STYLE_DOT, 0, Resistance_Color);
   SetIndexStyle(1, DRAW_ARROW, STYLE_DOT, 0, Support_Color);
   SetIndexDrawBegin(0, g_bars_164 - 1);
   SetIndexDrawBegin(1, g_bars_164 - 1);
   SetIndexLabel(0, "Active Resistance");
   SetIndexLabel(1, "Active Support");
   IndicatorShortName("Synergy_Pro_ASR");
   //f0_1();
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   if (gi_80) return (0);
   for (g_bars_164 = Bars; g_bars_164 >= 0; g_bars_164--) {
      g_ima_168 = iMA(NULL, 0, 9, 1, MODE_EMA, PRICE_HIGH, g_bars_164);
      g_ima_176 = iMA(NULL, 0, 9, 1, MODE_EMA, PRICE_LOW, g_bars_164);
      gd_184 = (Open[g_bars_164] + High[g_bars_164] + Low[g_bars_164] + Close[g_bars_164]) / 4.0;
      g_ifractals_148 = iFractals(NULL, 0, MODE_UPPER, g_bars_164);
      if (g_ifractals_148 > 0.0 && gd_184 > g_ima_168) g_ibuf_140[g_bars_164] = High[g_bars_164];
      else g_ibuf_140[g_bars_164] = g_ibuf_140[g_bars_164 + 1];
      g_ifractals_156 = iFractals(NULL, 0, MODE_LOWER, g_bars_164);
      if (g_ifractals_156 > 0.0 && gd_184 < g_ima_176) g_ibuf_144[g_bars_164] = Low[g_bars_164];
      else g_ibuf_144[g_bars_164] = g_ibuf_144[g_bars_164 + 1];
   }
   return (0);
}