/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2008,FXDB, LLC"
#property link      "http://www.ForexDealButler.com"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Black

//#include <FDB_File.mqh>
#include <Time.mqh>
#include <stdlib.mqh>

#import "wininet.dll"
   int InternetOpenA(string a0, int a1, string a2, string a3, int a4);
   int InternetOpenUrlA(int a0, string a1, string a2, int a3, int a4, int a5);
   int InternetReadFile(int a0, string a1, int a2, int& a3[]);
   int InternetCloseHandle(int a0);
#import

extern int MaxBars = 500;
extern bool Show_News = TRUE;
extern string comment0 = "-----------------------";
extern string comment11 = "Set StopLoss in Pips";
extern bool UseStopLoss = TRUE;
extern int _1m_StopLoss = 20;
extern int _5m_StopLoss = 30;
extern int _15m_StopLoss = 40;
extern int _30m_StopLoss = 50;
extern int _1H_StopLoss = 25;
extern int _4H_StopLoss = 40;
extern int _1D_StopLoss = 50;
extern string comment12 = "-----------------------";
extern string comment13 = "Volatility Filters";
extern bool Use_TMeter_Filter = FALSE;
extern double TMeter_Threshold = 0.05;
extern bool Use_Dynamic_RS_Filter = FALSE;
extern int Dyn_RS = 30;
extern string comment17 = "-----------------------";
extern string comment18 = "Main FXT Settings";
extern int MainPer = 14;
extern double kFactor1 = 1.2;
extern double kFactor2 = 1.4;
extern string comment14 = "-----------------------";
extern string comment15 = "Exit Settings";
extern bool Use_3Bar_Reversal = TRUE;
extern int LinesReversal = 3;
extern bool ignore_inside_bars = FALSE;
extern string comment1 = "-----------------------";
extern string comment2 = "Time Filter is not applied";
extern string comment3 = "above the 60min TF";
extern bool UseTimeFilter = FALSE;
extern int _server_offset = 2;
extern bool Auto_Adjust_TimeZone = TRUE;
extern string comment7 = "-----------------------";
extern bool Trade_Asian_Session = TRUE;
extern int Asian_Start_Hour_GMT = 22;
extern int Asian_End_Hour_GMT = 9;
extern bool Trade_London_Session = TRUE;
extern int London_Start_Hour_GMT = 8;
extern int London_End_Hour_GMT = 16;
extern bool Trade_NY_Session = TRUE;
extern int NY_Start_Hour_GMT = 13;
extern int NY_End_Hour_GMT = 18;
extern int Friday_Stop_Hour = 19;
extern bool Sunday_Trading = TRUE;
extern bool Exit_at_Session_End = FALSE;
extern string comment9 = "-----------------------";
extern bool Display_Bar_Clock = TRUE;
extern color Bar_Clock_Color = White;
extern string comment10 = "-----------------------";
extern bool Use_Alerts = TRUE;
extern bool DoText = TRUE;
extern bool Use_Warnings = TRUE;
extern color Warn_Color = Aqua;
extern bool Send_Email = FALSE;
extern int ArrowSize = 3;
extern color UpArrow = Blue;
extern color DnArrow = Red;
extern color LongXit = Fuchsia;
extern color ShortXit = SkyBlue;
extern int ArrowBuffer = 1;
string g_name_392 = "Html\\DailyFXCalendar.csv";
string gs_400 = "";
bool gi_408 = FALSE;
bool gi_412 = FALSE;
bool gi_416 = TRUE;
bool gi_420 = TRUE;
bool gi_424;
int g_str2dbl_428 = EMPTY_VALUE;
int g_str2dbl_432 = 11950258;
int gi_436 = 3;
int gi_440 = 5;
int gi_444 = 0;
int gi_448 = 0;
int gi_452 = 0;
int gi_456;
int gi_460;
int gi_464;
int g_datetime_468;
int gi_472;
int gi_476;
int gi_480;
int g_count_484;
int gi_488 = 0;
int gi_492;
int gi_496;
int gi_500 = 0;
int gi_504;
int gi_508;
int gi_512 = 13;
int gi_516;
int g_time_520 = 0;
int g_time_524 = 0;
int g_time_528 = 0;
int g_time_532 = 0;
int g_time_536 = 0;
double gd_540;
double gd_548;
double gd_556;
double g_ibuf_564[];
double g_ibuf_568[];
double g_ibuf_572[];

int hSession(bool ai_0) {
   string ls_4;
   if (gi_504 == 0) {
      ls_4 = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)";
      gi_504 = InternetOpenA(ls_4, 0, "0", "0", 0);
      gi_508 = InternetOpenA(ls_4, 1, "0", "0", 0);
   }
   if (ai_0) return (gi_508);
   return (gi_504);
}

int init() {
   gi_420 = TRUE;
   ObjectsDeleteAll(0, OBJ_TEXT);
   DeleteArrows();
   g_datetime_468 = 0;
   IndicatorBuffers(3);
   SetIndexBuffer(0, g_ibuf_564);
   SetIndexBuffer(1, g_ibuf_568);
   SetIndexBuffer(2, g_ibuf_572);
   SetIndexStyle(0, DRAW_NONE);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexStyle(2, DRAW_NONE);
   ArrayInitialize(g_ibuf_568, 0.0);
   ArrayInitialize(g_ibuf_564, 0.0);
   ArrayInitialize(g_ibuf_572, 0.0);
   SetIndexLabel(0, NULL);
   SetIndexLabel(1, NULL);
   SetIndexLabel(2, NULL);
   IndicatorDigits(Digits);
   for (int l_count_0 = 0; l_count_0 < 200; l_count_0++) ObjectDelete("EventMark" + l_count_0);
   g_count_484 = 0;
// if (FDB_Open("FDB.rkey")) {
//      if (FDB_GetStatus(1) == 1) g_str2dbl_428 = StrToDouble(StringTrimLeft(StringTrimRight(FDB_GetValue(1))));
//      if (FDB_GetStatus(2) == 1) g_str2dbl_432 = StrToDouble(StringTrimLeft(StringTrimRight(FDB_GetValue(2))));
//      Print("Run_Key loaded from file.");
//   } else Print("Run_Key file not found.");
   gi_424 = TRUE;
   if (GlobalVariableCheck(Symbol() + "_" + Period() + "_LongStop")) GlobalVariableDel(Symbol() + "_" + Period() + "_LongStop");
   if (GlobalVariableCheck(Symbol() + "_" + Period() + "_ShortStop")) GlobalVariableDel(Symbol() + "_" + Period() + "_ShortStop");
   if (GlobalVariableCheck(Symbol() + "_" + Period() + "_TradeDir")) GlobalVariableDel(Symbol() + "_" + Period() + "_TradeDir");
   gi_500 = fnMakeMagicNumber();
   return (0);
}

int deinit() {
   Comment("");
   ObjectsDeleteAll(0, OBJ_TEXT);
   ObjectsDeleteAll(0, OBJ_ARROW);
   g_count_484 = 0;
   for (int l_count_0 = 0; l_count_0 < gi_488; l_count_0++) ObjectDelete("EventMark" + l_count_0);
   if (GlobalVariableCheck(Symbol() + "_" + Period() + "_LongStop")) GlobalVariableDel(Symbol() + "_" + Period() + "_LongStop");
   if (GlobalVariableCheck(Symbol() + "_" + Period() + "_ShortStop")) GlobalVariableDel(Symbol() + "_" + Period() + "_ShortStop");
   if (GlobalVariableCheck(Symbol() + "_" + Period() + "_TradeDir")) GlobalVariableDel(Symbol() + "_" + Period() + "_TradeDir");
   return (0);
}

int start() {
   string ls_0;
   string l_text_8;
   color l_color_16;
   int l_timeframe_24;
   int li_28;
   int li_32;
   int li_36;
   int li_40;
   int li_44;
   int l_time_48;
   int li_52;
   double l_icustom_56;
   double l_icustom_64;
   double ld_72;
   double ld_88;
   double l_price_96;
   double ld_104;
   double l_price_112;
   double ld_120;
   double l_icustom_128;
   double l_icustom_136;
   double l_icustom_144;
   double l_icustom_152;
   double l_icustom_160;
   double ld_168;
   double ld_176;
   if (!IsConnected()) {
      if (gi_452 > 1) Print("No login Connection.");
      gi_452++;
   }
//   if (CheckKey() == 0 && AccountNumber() != 0) {
      for (int l_count_20 = 0; l_count_20 < 6; l_count_20++) {
//         if (CheckKey() == 1) break;
//         if (l_count_20 == 5 && CheckKey() == 0) {
//            Print("Registration Key Failed for Account#: " + AccountNumber());
//            deinit();
//            return (0);
//         }
//     }
   }
   int l_ind_counted_184 = IndicatorCounted();
   if (l_ind_counted_184 < 0) return (-1);
   if (MaxBars == 0) MaxBars = Bars - 51;
   int li_188 = Bars - l_ind_counted_184;
   if (li_188 > MaxBars) li_188 = MaxBars;
   gi_496 = GetShiftGMT();
   int li_192 = 0 - gi_496 / 60 / 60;
   if (!IsConnected()) li_192 = _server_offset;
   if (!Auto_Adjust_TimeZone) li_192 = _server_offset;
   if (Asian_Start_Hour_GMT > 23) Asian_Start_Hour_GMT = 0;
   if (Asian_Start_Hour_GMT <= gi_496 + 1) Asian_Start_Hour_GMT += 24;
   int li_196 = Asian_Start_Hour_GMT + li_192;
   if (li_196 > 23) li_196 -= 25;
   if (li_196 < 0) li_196 += 24;
   int li_200 = Asian_End_Hour_GMT + li_192;
   int li_204 = London_Start_Hour_GMT + li_192;
   int li_208 = London_End_Hour_GMT + li_192;
   int li_212 = NY_Start_Hour_GMT + li_192;
   int li_216 = NY_End_Hour_GMT + li_192;
   if (!UseTimeFilter) gi_416 = TRUE;
   gi_460 = Time[0] + 60 * Period() - TimeCurrent();
   gi_464 = gi_460 % 60;
   gi_460 = (gi_460 - gi_460 % 60) / 60;
   int l_file_220 = FileOpen(g_name_392, FILE_BIN|FILE_READ);
   if (l_file_220 > 0) li_36 = FileSize(l_file_220);
   else li_36 = 0;
   if (l_file_220 < 1 || li_36 == 0) gi_408 = TRUE;
   if (l_file_220 > 0) FileClose(l_file_220);
   if (GlobalVariableCheck("GV_LastNewsDownload") && li_36 > 0) {
      gd_556 = GlobalVariableGet("GV_LastNewsDownload");
      if (gd_556 == 0.0) gi_408 = TRUE;
      else gi_408 = FALSE;
   }
   if (!GlobalVariableCheck("GV_LastNewsDownload")) gd_556 = 0;
   double ld_80 = GetTimeGMT() + gi_496;
   if (Show_News && !IsDllsAllowed() && gi_420) {
      Alert("Dll calls must be allowed for News reader to work.");
      return (-1);
   }
   if (Show_News && ld_80 > gd_556 + gi_500 || gi_408) {
      if (GlobalVariableGet("GV_NewsDownloading") > ld_80 + 20.0 || gi_408) {
         GlobalVariableSet("GV_NewsDownloading", ld_80);
         GetNews();
         GlobalVariableSet("GV_LastNewsDownload", ld_80);
         for (int l_index_224 = 0; l_index_224 < gi_488; l_index_224++) ObjectDelete("EventMark" + l_index_224);
         GrabNews();
         gd_556 = ld_80;
         gi_408 = FALSE;
      }
   }
   if (Show_News && ld_80 > gi_492 + gi_500 / 2 && li_36 > 0) {
      for (l_index_224 = 0; l_index_224 < gi_488; l_index_224++) ObjectDelete("EventMark" + l_index_224);
      GrabNews();
      gi_492 = ld_80;
   }
   ObjectDelete("time");
   if (Display_Bar_Clock) {
      if (ObjectFind("time") != 0) {
         ObjectCreate("time", OBJ_TEXT, 0, Time[0], Close[0] + 3.0 * Point);
         if (gi_464 < 10) ls_0 = "0" + gi_464;
         else ls_0 = gi_464;
         ObjectSetText("time", "                  <" + gi_460 + ":" + ls_0, 12, "Arial Bold", Bar_Clock_Color);
      } else ObjectMove("time", 0, Time[0], Close[0] + 3.0 * Point);
   }
   int li_228 = 3;
   switch (Period()) {
   case PERIOD_M5:
      li_228 = 8 * ArrowBuffer;
      break;
   case PERIOD_M15:
      li_228 = 10 * ArrowBuffer;
      break;
   case PERIOD_M30:
      li_228 = 13 * ArrowBuffer;
      break;
   case PERIOD_H1:
      li_228 = 15 * ArrowBuffer;
      break;
   case PERIOD_H4:
      li_228 = 35 * ArrowBuffer;
      break;
   case PERIOD_D1:
      li_228 = 90 * ArrowBuffer;
      break;
   case PERIOD_W1:
      li_228 = 120 * ArrowBuffer;
      break;
   case PERIOD_MN1:
      li_228 = 170 * ArrowBuffer;
   }
   if (Digits == 3 || Digits == 5) li_228 = 10 * li_228;
   switch (Period()) {
   case PERIOD_M1:
      l_timeframe_24 = 1;
      li_28 = 5;
      li_32 = 15;
      gi_456 = _1m_StopLoss;
      break;
   case PERIOD_M5:
      l_timeframe_24 = 5;
      li_28 = 15;
      li_32 = 30;
      gi_456 = _5m_StopLoss;
      break;
   case PERIOD_M15:
      l_timeframe_24 = 15;
      li_28 = 30;
      li_32 = 60;
      gi_456 = _15m_StopLoss;
      break;
   case PERIOD_M30:
      l_timeframe_24 = 30;
      li_28 = 60;
      li_32 = 240;
      gi_456 = _30m_StopLoss;
      break;
   case PERIOD_H1:
      l_timeframe_24 = 60;
      li_28 = 240;
      li_32 = 1440;
      gi_456 = _1H_StopLoss;
      break;
   case PERIOD_H4:
      l_timeframe_24 = 240;
      li_28 = 1440;
      li_32 = 10080;
      gi_456 = _4H_StopLoss;
      break;
   case PERIOD_D1:
      l_timeframe_24 = 1440;
      li_28 = 10080;
      li_32 = 43200;
      gi_456 = _1D_StopLoss;
      break;
   case PERIOD_W1:
      l_timeframe_24 = 10080;
      li_28 = 43200;
      li_32 = 43200;
      gi_456 = _1D_StopLoss;
      break;
   case PERIOD_MN1:
      l_timeframe_24 = 43200;
      li_28 = 43200;
      li_32 = 43200;
      gi_456 = _1D_StopLoss;
   }
   gs_400 = "FDB_Signals_v1.0 (" + l_timeframe_24 + "," + li_28 + "," + li_32 + ")";
   IndicatorShortName(gs_400);
   if (Digits == 3 || Digits == 5) gi_456 = 10 * gi_456;
   if (gi_480 == 0) GlobalVariableSet(Symbol() + "_" + Period() + "_TradeDir", 0);
   for (l_index_224 = li_188; l_index_224 >= 0; l_index_224--) {
      for (int li_240 = 1; li_240 < 4; li_240++) {
         if (kFactor1 < 1.0) kFactor1 = 1;
         if (kFactor2 < 1.0) kFactor2 = 1;
         switch (li_240) {
         case 1:
            li_40 = l_timeframe_24;
            li_44 = MathRound(MainPer);
            break;
         case 2:
            li_40 = li_28;
            li_44 = MathRound(MainPer / kFactor1);
            break;
         case 3:
            li_40 = li_32;
            li_44 = MathRound(MainPer / kFactor2);
         }
         l_icustom_56 = iCustom(NULL, 0, "FDB_FXT", li_40, li_44, gi_436, gi_440, gi_444, gi_448, 0, l_index_224);
         l_icustom_64 = iCustom(NULL, 0, "FDB_FXT", li_40, li_44, gi_436, gi_440, gi_444, gi_448, 1, l_index_224);
         switch (li_240) {
         case 1:
            g_ibuf_568[l_index_224] = 0;
            if ((l_icustom_64 < l_icustom_56 && l_icustom_56 > 20.0) || l_icustom_56 >= 80.0) g_ibuf_568[l_index_224] = 1;
            else
               if ((l_icustom_64 >= l_icustom_56 && l_icustom_56 < 80.0) || l_icustom_56 <= 20.0) g_ibuf_568[l_index_224] = 2;
            break;
         case 2:
            g_ibuf_564[l_index_224] = 0;
            if ((l_icustom_64 < l_icustom_56 && l_icustom_56 > 20.0) || l_icustom_56 >= 80.0) g_ibuf_564[l_index_224] = 1;
            else
               if ((l_icustom_64 >= l_icustom_56 && l_icustom_56 < 80.0) || l_icustom_56 <= 20.0) g_ibuf_564[l_index_224] = 2;
            break;
         case 3:
            g_ibuf_572[l_index_224] = 0;
            if ((l_icustom_64 < l_icustom_56 && l_icustom_56 > 20.0) || l_icustom_56 >= 80.0) g_ibuf_572[l_index_224] = 1;
            else
               if ((l_icustom_64 >= l_icustom_56 && l_icustom_56 < 80.0) || l_icustom_56 <= 20.0) g_ibuf_572[l_index_224] = 2;
         }
      }
   }
   switch (Period()) {
   case PERIOD_M1:
      ld_72 = 0.01;
      break;
   case PERIOD_M5:
      ld_72 = 0.05;
      break;
   case PERIOD_M15:
      ld_72 = 0.06;
      break;
   case PERIOD_M30:
      ld_72 = 0.08;
      break;
   case PERIOD_H1:
      ld_72 = 0.1;
      break;
   case PERIOD_H4:
      ld_72 = 0.14;
      break;
   case PERIOD_D1:
      ld_72 = 0.4;
      break;
   case PERIOD_W1:
      ld_72 = 0.5;
      break;
   case PERIOD_MN1:
      ld_72 = 0.6;
   }
   if (TMeter_Threshold == 0.0) TMeter_Threshold = ld_72;
   if (WindowFirstVisibleBar() + MainPer > li_188) li_188 = WindowFirstVisibleBar() + MainPer;
   for (int li_256 = li_188; li_256 >= 0; li_256--) {
      l_time_48 = Time[li_256];
      li_52 = 0;
      ld_88 = High[li_256 + 1] + 2.0 * (li_228 * Point);
      l_price_96 = ld_88 + li_228 * Point;
      ld_104 = Low[li_256 + 1] - li_228 / 2 * Point;
      l_price_112 = ld_104 - li_228 * Point;
      ld_120 = Ask - Bid;
      if (Use_TMeter_Filter) {
         l_icustom_128 = iCustom(Symbol(), l_timeframe_24, "FDB_TMeter", 3, 36, 0.0, Bars, 1, 0, li_256 + 1);
         l_icustom_136 = iCustom(Symbol(), l_timeframe_24, "FDB_TMeter", 3, 36, 0.0, Bars, 1, 0, li_256 + 2);
      }
      if (Use_Dynamic_RS_Filter) l_icustom_144 = iCustom(Symbol(), l_timeframe_24, "FDB_DynamicRS_Filter", Dyn_RS, Bars, 7, li_256);
      l_icustom_152 = iCustom(Symbol(), l_timeframe_24, "FDB_3BarReversal_v2", LinesReversal, ignore_inside_bars, 0, li_256);
      l_icustom_160 = iCustom(Symbol(), l_timeframe_24, "FDB_3BarReversal_v2", LinesReversal, ignore_inside_bars, 1, li_256);
      if (li_256 == 0 && gi_480 != 0) {
         if (gi_480 == 1) GlobalVariableSet(Symbol() + "_" + Period() + "_LongStop", NormalizeDouble(l_icustom_160, Digits));
         if (gi_480 == 2) GlobalVariableSet(Symbol() + "_" + Period() + "_ShortStop", NormalizeDouble(l_icustom_152, Digits));
      }
      if (l_icustom_128 > TMeter_Threshold) ld_168 = 1;
      else {
         if (l_icustom_128 < -TMeter_Threshold) ld_168 = 2;
         else ld_168 = 0;
      }
      if (l_icustom_144 == 1.0) ld_176 = 1;
      else {
         if (l_icustom_144 == 2.0) ld_176 = 2;
         else ld_176 = 0;
      }
      li_52 = newbar(Time[li_256]);
      if (UseTimeFilter) {
         if (Period() > PERIOD_H1) gi_416 = TRUE;
         else {
            gi_416 = FALSE;
            if ((Trade_London_Session && TimeHour(l_time_48) >= li_204 && TimeHour(l_time_48) < li_208) || (Trade_NY_Session && TimeHour(l_time_48) >= li_212 && (TimeDayOfWeek(l_time_48) != 5 &&
               TimeHour(l_time_48) < li_216) || (TimeDayOfWeek(l_time_48) == 5 && (TimeHour(l_time_48) < Friday_Stop_Hour && TimeHour(l_time_48) < li_216))) || (TimeDayOfWeek(l_time_48) != 5 &&
               Trade_Asian_Session && TimeHour(l_time_48) >= li_196 || (li_196 > 12 && l_time_48 >= 0 && TimeHour(l_time_48) < li_200))) gi_416 = TRUE;
            else gi_416 = FALSE;
         }
      }
      if (li_52 && Time[li_256] > gi_476) {
         if (gi_480 == 0) {
            if (!UseTimeFilter || gi_416 && TimeDayOfWeek(l_time_48) != 0 || Sunday_Trading) {
               if (g_ibuf_568[li_256 + 1] == 1.0 && g_ibuf_568[li_256] == 1.0 && g_ibuf_564[li_256] == 1.0 && g_ibuf_564[li_256 + 1] == 1.0 && g_ibuf_572[li_256] == 1.0 && g_ibuf_572[li_256 +
                  1] == 1.0 && ld_168 == 1.0 || !Use_TMeter_Filter && l_icustom_160 != 0.0 || !Use_3Bar_Reversal && ld_176 == 1.0 || !Use_Dynamic_RS_Filter) {
                  DrawArrow(li_256, "up", ld_104);
                  if (li_256 < 2) gd_540 = Ask;
                  else gd_540 = Open[li_256] + ld_120;
                  gi_480 = 1;
                  gi_472 = Time[li_256];
                  if (li_256 < 2) DoAlert(li_256, "OPEN LONG on " + Symbol() + " at " + DoubleToStr(gd_540, Digits) + " at " + TimeHour(l_time_48) + ":" + DoubleToStr(TimeMinute(l_time_48), 0) + "Hours !!!");
                  GlobalVariableSet(Symbol() + "_" + Period() + "_LongStop", NormalizeDouble(l_icustom_160, Digits));
                  GlobalVariableSet(Symbol() + "_" + Period() + "_TradeDir", 1);
               }
               if (g_ibuf_568[li_256] == 2.0 && g_ibuf_568[li_256 + 1] == 2.0 && g_ibuf_564[li_256] == 2.0 && g_ibuf_564[li_256 + 1] == 2.0 && g_ibuf_572[li_256] == 2.0 && g_ibuf_572[li_256 +
                  1] == 2.0 && l_icustom_152 != 0.0 || !Use_3Bar_Reversal && ld_168 == 2.0 || !Use_TMeter_Filter && ld_176 == 2.0 || !Use_Dynamic_RS_Filter) {
                  DrawArrow(li_256, "down", ld_88);
                  if (li_256 < 2) gd_540 = Ask;
                  else gd_540 = Open[li_256];
                  gi_480 = 2;
                  gi_472 = Time[li_256];
                  if (li_256 < 2) DoAlert(li_256, "OPEN SHORT on " + Symbol() + " at " + DoubleToStr(gd_540, Digits) + " at " + TimeHour(l_time_48) + ":" + DoubleToStr(TimeMinute(l_time_48), 0) + "Hours !!!");
                  GlobalVariableSet(Symbol() + "_" + Period() + "_ShortStop", NormalizeDouble(l_icustom_152, Digits));
                  GlobalVariableSet(Symbol() + "_" + Period() + "_TradeDir", 2);
               }
            }
         }
         if (Time[li_256] == gi_472) continue;
      }
      if (gi_480 == 1 || gi_480 == 2 && Time[li_256] > gi_472) {
         if (gi_480 == 1) {
            l_text_8 = "";
            if (li_52 && g_ibuf_572[li_256 + 1] == 1.0 && g_ibuf_572[li_256] == 2.0 && g_ibuf_564[li_256] == 2.0) l_text_8 = "FXT";
            else {
               if (Use_3Bar_Reversal && l_icustom_152 != 0.0) l_text_8 = LinesReversal + "-Bar";
               else {
                  if (li_52 && gi_412 && g_ibuf_564[li_256] == 2.0 && g_ibuf_572[li_256] == 2.0) l_text_8 = "AgXit";
                  else {
                     if (Use_Dynamic_RS_Filter && ld_176 != 1.0) l_text_8 = "RS";
                     else {
                        if (UseStopLoss && Low[li_256] < gd_540 - NormalizeDouble(gi_456 * Point, Digits)) l_text_8 = "Stop";
                        else {
                           if (UseTimeFilter && TimeDayOfWeek(l_time_48) == 5 && TimeHour(l_time_48) >= Friday_Stop_Hour) l_text_8 = "Time";
                           else {
                              if (Exit_at_Session_End && !gi_416) l_text_8 = "SessEnd";
                              else l_text_8 = "";
                           }
                        }
                     }
                  }
               }
            }
         }
         if (gi_480 == 1 && l_text_8 != "") {
            DrawArrow(li_256, "longexit", ld_88);
            gd_548 = Open[li_256];
            if (Use_3Bar_Reversal && l_text_8 == LinesReversal + "-Bar") gd_548 = Low[iLowest(NULL, 0, MODE_LOW, LinesReversal, li_256 + 1)];
            if (li_256 == 0) gd_548 = Close[0];
            if (UseStopLoss && Low[li_256] < gd_540 - NormalizeDouble(gi_456 * Point, Digits)) gd_548 = gd_540 - NormalizeDouble(gi_456 * Point, Digits);
            gi_480 = 0;
            if (li_256 == 0) DoAlert(li_256, "EXIT LONG on " + Symbol() + " at " + DoubleToStr(gd_548, Digits) + " at " + TimeHour(l_time_48) + ":" + DoubleToStr(TimeMinute(l_time_48), 0) + "Hours !!!");
            gi_476 = Time[li_256];
            GlobalVariableDel(Symbol() + "_" + Period() + "_LongStop");
            GlobalVariableSet(Symbol() + "_" + Period() + "_TradeDir", 0);
            if (DoText) {
               l_color_16 = Red;
               if (gd_540 < gd_548) l_color_16 = LimeGreen;
               ObjectCreate("Buy_" + l_time_48, OBJ_TEXT, 0, l_time_48, l_price_96);
               ObjectSetText("Buy_" + l_time_48, l_text_8, 8, "Times New Roman", l_color_16);
            }
            gd_548 = 0;
            gd_540 = 0;
            continue;
         }
         if (gi_480 == 2) {
            l_text_8 = "";
            if (li_52 && g_ibuf_572[li_256 + 1] == 1.0 && g_ibuf_572[li_256] == 1.0 && g_ibuf_564[li_256] == 1.0) l_text_8 = "FXT";
            else {
               if (Use_3Bar_Reversal && l_icustom_160 != 0.0) l_text_8 = LinesReversal + "-Bar";
               else {
                  if (li_52 && gi_412 && g_ibuf_572[li_256] == 1.0 && g_ibuf_572[li_256] == 1.0) l_text_8 = "AgXit";
                  else {
                     if (Use_Dynamic_RS_Filter && ld_176 != 2.0) l_text_8 = "RS";
                     else {
                        if (UseTimeFilter && TimeDayOfWeek(l_time_48) == 5 && TimeHour(l_time_48) >= Friday_Stop_Hour) l_text_8 = "Time";
                        else
                           if (Exit_at_Session_End && !gi_416) l_text_8 = "SessEnd";
                     }
                  }
               }
            }
         }
         if (gi_480 == 2 && l_text_8 != "") {
            DrawArrow(li_256, "shortexit", ld_104);
            gd_548 = Open[li_256];
            if (Use_3Bar_Reversal && l_text_8 == LinesReversal + "-Bar") gd_548 = High[iHighest(NULL, 0, MODE_HIGH, LinesReversal, li_256 + 1)];
            if (li_256 == 0) gd_548 = Close[0];
            if (UseStopLoss && High[li_256] > gd_540 + NormalizeDouble(gi_456 * Point, Digits)) gd_548 = gd_540 + NormalizeDouble(gi_456 * Point, Digits);
            gi_480 = 0;
            if (li_256 == 0) DoAlert(li_256, "EXIT SHORT on " + Symbol() + " at " + DoubleToStr(gd_548, Digits) + " at " + TimeHour(l_time_48) + ":" + DoubleToStr(TimeMinute(l_time_48), 0) + "Hours !!!");
            gi_476 = Time[li_256];
            GlobalVariableDel(Symbol() + "_" + Period() + "_ShortStop");
            GlobalVariableSet(Symbol() + "_" + Period() + "_TradeDir", 0);
            if (DoText) {
               l_color_16 = Red;
               if (gd_540 > gd_548) l_color_16 = LimeGreen;
               ObjectCreate("Sell_" + l_time_48, OBJ_TEXT, 0, l_time_48, l_price_112);
               ObjectSetText("Sell_" + l_time_48, l_text_8, 8, "Times New Roman", l_color_16);
            }
            gd_548 = 0;
            gd_540 = 0;
            continue;
         }
         if (Time[li_256] == gi_476) continue;
      }
      if (Use_Warnings) {
         if (gi_480 == 0) {
            if (TimeDayOfWeek(l_time_48) != 0 || Sunday_Trading) {
               if (!UseTimeFilter || gi_416) {
                  if (g_ibuf_572[li_256] == 1.0 && g_ibuf_568[li_256] == 1.0 && g_ibuf_564[li_256] == 1.0 && ld_168 == 1.0 || !Use_TMeter_Filter && l_icustom_160 != 0.0 || !Use_3Bar_Reversal &&
                     ld_176 == 1.0 || !Use_Dynamic_RS_Filter) {
                     ObjectCreate("Warn." + l_time_48, OBJ_TEXT, 0, l_time_48, Low[li_256] - 15.0 * Point);
                     ObjectSetText("Warn." + l_time_48, "L", 10, "Arial Bold", Warn_Color);
                     if (l_time_48 < g_datetime_468 && Use_Alerts) {
                        if (li_256 == 0) {
                           DoAlert(li_256, "Possible Long Entry on " + Symbol() + " at " + TimeHour(l_time_48) + ":" + TimeMinute(l_time_48) + " !!!");
                           if (Send_Email) SendMail("from FDB", "Possible Long Entry on " + Symbol() + " at " + Open[li_256] + " at " + TimeHour(l_time_48) + ":" + DoubleToStr(TimeMinute(l_time_48), 0) + "Hours !!!");
                        }
                        g_datetime_468 = l_time_48;
                     }
                  }
                  if (g_ibuf_568[li_256] == 2.0 && g_ibuf_564[li_256] == 2.0 && g_ibuf_572[li_256] == 2.0 && l_icustom_152 != 0.0 || !Use_3Bar_Reversal && ld_168 == 2.0 || !Use_TMeter_Filter &&
                     ld_176 == 2.0 || !Use_Dynamic_RS_Filter) {
                     ObjectCreate("Warn." + l_time_48, OBJ_TEXT, 0, l_time_48, High[li_256] + 15.0 * Point);
                     ObjectSetText("Warn." + l_time_48, "S", 12, "Arial Bold", Warn_Color);
                     if (l_time_48 < g_datetime_468 && Use_Alerts) {
                        if (li_256 == 0) {
                           DoAlert(li_256, "Possible Short Entry on " + Symbol() + " at " + TimeHour(l_time_48) + ":" + TimeMinute(l_time_48) + " !!!");
                           if (Send_Email) SendMail("from FDB", "Possible Short Entry on " + Symbol() + " at " + Open[li_256] + " at " + TimeHour(l_time_48) + ":" + DoubleToStr(TimeMinute(l_time_48), 0) + "Hours !!!");
                        }
                        g_datetime_468 = l_time_48;
                     }
                  }
               }
            }
         }
      }
   }
   gi_420 = FALSE;
   SaveComment();
   watermark();
   return (0);
}

int newbar(int ai_0) {
   if (ai_0 != gi_516) {
      gi_516 = ai_0;
      return (1);
   }
   return (0);
}

void SaveComment() {
   string ls_0;
   string l_dbl2str_24;
   string l_dbl2str_32;
   string l_dbl2str_40;
   string l_dbl2str_48;
   string l_dbl2str_56;
   string l_dbl2str_64;
   int li_72;
   int li_76;
   int li_80;
   int li_84;
   double ld_88;
   double ld_96;
   double ld_104;
   double ld_112;
   double l_icustom_120;
   string ls_8 = "";
   string ls_16 = "";
   double l_icustom_128 = iCustom(Symbol(), 0, "FDB_3BarReversal_v2", LinesReversal, ignore_inside_bars, 0, 0);
   double l_icustom_136 = iCustom(Symbol(), 0, "FDB_3BarReversal_v2", LinesReversal, ignore_inside_bars, 1, 0);
   double ld_144 = 0;
   if (l_icustom_136 > 0.0) {
      l_icustom_120 = l_icustom_136;
      ld_144 = (Close[0] - l_icustom_136) / Point;
   } else {
      if (l_icustom_128 > 0.0) {
         l_icustom_120 = l_icustom_128;
         ld_144 = (l_icustom_128 - Close[0]) / Point;
      } else l_icustom_120 = 0;
   }
   for (int l_count_152 = 0; l_count_152 < gi_488; l_count_152++) {
      li_72 = ObjectGet("EventMark" + l_count_152, OBJPROP_TIME1);
      if (li_72 > Time[0]) {
         li_76 = (li_72 - TimeCurrent()) / 60;
         li_80 = li_76 / 60;
         li_84 = MathMod(li_76, 60);
         ls_16 = li_80 + " hours " + li_84 + " minutes";
         break;
      }
      if (TimeCurrent() < TimeLocal() - 86400) ls_16 = "";
   }
   double l_iopen_156 = iOpen(NULL, PERIOD_D1, 0);
   double l_ihigh_164 = iHigh(NULL, PERIOD_D1, 0);
   double l_ilow_172 = iLow(NULL, PERIOD_D1, 0);
   if (Digits == 3 || Digits == 5) {
      ld_88 = iATR(Symbol(), PERIOD_D1, 5, 0) / Point / 10.0;
      ld_96 = iATR(Symbol(), PERIOD_D1, 10, 0) / Point / 10.0;
      ld_104 = iATR(Symbol(), PERIOD_D1, 20, 0) / Point / 10.0;
      ld_112 = (iHigh(Symbol(), PERIOD_D1, 0) - iLow(Symbol(), PERIOD_D1, 0)) / Point / 10.0;
      l_dbl2str_24 = DoubleToStr(ld_88, 1);
      l_dbl2str_32 = DoubleToStr(ld_96, 1);
      l_dbl2str_40 = DoubleToStr(ld_104, 1);
      l_dbl2str_48 = DoubleToStr(ld_112, 1);
      l_dbl2str_56 = DoubleToStr((l_ihigh_164 - Close[0]) / Point / 10.0, 1);
      l_dbl2str_64 = DoubleToStr((Close[0] - l_ilow_172) / Point / 10.0, 1);
   } else {
      ld_88 = iATR(Symbol(), PERIOD_D1, 5, 0) / Point;
      ld_96 = iATR(Symbol(), PERIOD_D1, 10, 0) / Point;
      ld_104 = iATR(Symbol(), PERIOD_D1, 20, 0) / Point;
      ld_112 = (iHigh(Symbol(), PERIOD_D1, 0) - iLow(Symbol(), PERIOD_D1, 0)) / Point;
      l_dbl2str_24 = DoubleToStr(ld_88, 0);
      l_dbl2str_32 = DoubleToStr(ld_96, 0);
      l_dbl2str_40 = DoubleToStr(ld_104, 0);
      l_dbl2str_48 = DoubleToStr(ld_112, 0);
      l_dbl2str_56 = DoubleToStr((l_ihigh_164 - Close[0]) / Point, 0);
      l_dbl2str_64 = DoubleToStr((Close[0] - l_ilow_172) / Point, 0);
   }
   if (ld_112 > 1.1 * ((ld_88 + ld_96 + ld_104) / 3.0)) {
      ls_0 = "20 Day ATR:  " + l_dbl2str_40 
         + "\n" 
         + "10 Day ATR:  " + l_dbl2str_32 
         + "\n" 
         + "5 Day ATR:  " + l_dbl2str_24 
         + "\n" 
         + "Today\'s Range:  " + l_dbl2str_48 + "  +++++ " 
         + "\n" 
         + "Today\'s Open:  " + DoubleToStr(l_iopen_156, Digits) 
         + "\n" 
         + "Pips from Today\\s High:  " + l_dbl2str_56 
         + "\n" 
         + "Pips from Today\\s Low:  " + l_dbl2str_64 
         + "\n" 
         + LinesReversal + "- Bar Stop Level:  " + DoubleToStr(l_icustom_120, Digits) 
         + "\n" 
      + ls_8;
   } else {
      ls_0 = "20 Day ATR:  " + l_dbl2str_40 
         + "\n" 
         + "10 Day ATR:  " + l_dbl2str_32 
         + "\n" 
         + "5 Day ATR:  " + l_dbl2str_24 
         + "\n" 
         + "Today\'s Range:  " + l_dbl2str_48 
         + "\n" 
         + "Today\'s Open:  " + DoubleToStr(l_iopen_156, Digits) 
         + "\n" 
         + "Pips from Today\\s High:  " + l_dbl2str_56 
         + "\n" 
         + "Pips from Today\\s Low:  " + l_dbl2str_64 
         + "\n" 
         + LinesReversal + "- Bar Stop Level:  " + DoubleToStr(l_icustom_120, Digits) 
         + "\n" 
      + ls_8;
   }
   if (Show_News) {
      ls_0 = ls_0 
         + "\n" 
      + "Next News in: " + ls_16;
   }
   Comment(ls_0);
}

void DrawArrow(int ai_0, string as_4, double ad_12) {
   g_count_484++;
   string l_str_concat_20 = StringConcatenate("FDB_Signal_v1.0", g_count_484);
   if (ArrowSize < 1 || ArrowSize > 5) ArrowSize = 3;
   ObjectCreate(l_str_concat_20, OBJ_ARROW, 0, Time[ai_0], 0);
   if (as_4 == "down" && g_time_520 == 0 || g_time_520 < Time[ai_0]) {
      ObjectSet(l_str_concat_20, OBJPROP_PRICE1, ad_12);
      ObjectSet(l_str_concat_20, OBJPROP_ARROWCODE, 234);
      ObjectSet(l_str_concat_20, OBJPROP_COLOR, DnArrow);
      ObjectSet(l_str_concat_20, OBJPROP_WIDTH, ArrowSize);
      g_time_520 = Time[ai_0];
      return;
   }
   if (as_4 == "up" && g_time_524 == 0 || g_time_524 < Time[ai_0]) {
      ObjectSet(l_str_concat_20, OBJPROP_PRICE1, ad_12);
      ObjectSet(l_str_concat_20, OBJPROP_ARROWCODE, 233);
      ObjectSet(l_str_concat_20, OBJPROP_COLOR, UpArrow);
      ObjectSet(l_str_concat_20, OBJPROP_WIDTH, ArrowSize);
      g_time_524 = Time[ai_0];
      return;
   }
   if (as_4 == "shortexit" && g_time_528 == 0 || g_time_528 < Time[ai_0]) {
      ObjectSet(l_str_concat_20, OBJPROP_PRICE1, ad_12);
      ObjectSet(l_str_concat_20, OBJPROP_ARROWCODE, 119);
      ObjectSet(l_str_concat_20, OBJPROP_COLOR, ShortXit);
      ObjectSet(l_str_concat_20, OBJPROP_WIDTH, ArrowSize);
      g_time_528 = Time[ai_0];
      return;
   }
   if (as_4 == "longexit" && g_time_532 == 0 || g_time_532 < Time[ai_0]) {
      ObjectSet(l_str_concat_20, OBJPROP_PRICE1, ad_12);
      ObjectSet(l_str_concat_20, OBJPROP_ARROWCODE, 119);
      ObjectSet(l_str_concat_20, OBJPROP_COLOR, LongXit);
      ObjectSet(l_str_concat_20, OBJPROP_WIDTH, ArrowSize);
      g_time_532 = Time[ai_0];
   }
}

void DeleteArrows() {
   while (g_count_484 > 0) {
      ObjectDelete(StringConcatenate("FDB_Signal_v1.0", g_count_484));
      g_count_484--;
   }
}

/*int CheckKey() {
   double ld_0;
   double ld_8;
   double ld_16;
   int l_month_24 = TimeMonth(TimeCurrent());
   if (IsDemo()) {
      ld_0 = NormalizeDouble(MathAbs(AccountNumber() << 2 - 3912671 * l_month_24), 0);
      ld_16 = NormalizeDouble(MathAbs(g_str2dbl_432), 0);
   } else {
      ld_0 = NormalizeDouble(MathAbs(AccountNumber() << 2 + 10110110 - 5382974 * l_month_24), 0);
      ld_16 = NormalizeDouble(MathAbs(g_str2dbl_428), 0);
   }
   if (TimeMonth(TimeCurrent() - 259200) == l_month_24 - 1 && ld_16 > 0.0) {
      if (IsDemo()) ld_8 = NormalizeDouble(MathAbs(AccountNumber() << 2 - 3912671 * (l_month_24 - 1)), 0);
      else ld_8 = NormalizeDouble(MathAbs(AccountNumber() << 2 + 10110110 - 5382974 * (l_month_24 - 1)), 0);
   }
   if (gi_424 && ld_16 == ld_8) {
      Print("Registration Key expires on the 3rd at Midnite.  Login and generate a new key.");
      gi_424 = FALSE;
   }
   if (ld_16 == ld_0 || ld_16 == ld_8 && ld_16 > 0.0) return (1);
   return (0);
} */

void DoAlert(int ai_0, string as_4) {
   if (g_time_536 == 0 || g_time_536 < Time[0] && ai_0 == 0) {
      if (Use_Alerts) Alert(as_4);
      if (Send_Email) SendMail("FDB", as_4);
      g_time_536 = Time[0];
   }
}

void watermark() {
   ObjectCreate("FDB_Signal_v1.0", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("FDB_Signal_v1.0", "Forex Deal Butler", 11, "Lucida Handwriting", RoyalBlue);
   ObjectSet("FDB_Signal_v1.0", OBJPROP_CORNER, 2);
   ObjectSet("FDB_Signal_v1.0", OBJPROP_XDISTANCE, 5);
   ObjectSet("FDB_Signal_v1.0", OBJPROP_YDISTANCE, 10);
}

int PreviousMonday(int ai_0) {
   int li_ret_4 = ai_0 - 60 * (60 * (24 * (TimeDayOfWeek(ai_0) - 1)));
   return (li_ret_4);
}

int ToDate(string as_0, string as_8) {
   string ls_16 = StringSubstr(as_0, 0, 3);
   int li_24 = 0;
   if (ls_16 == "Mon") li_24 = 0;
   if (ls_16 == "Tue") li_24 = 1;
   if (ls_16 == "Wed") li_24 = 2;
   if (ls_16 == "Thu") li_24 = 3;
   if (ls_16 == "Fri") li_24 = 4;
   if (ls_16 == "Sat") li_24 = 5;
   if (ls_16 == "Sun") li_24 = -1;
   int li_ret_28 = PreviousMonday(GetTimeGMT()) + 60 * (60 * (24 * li_24));
   int l_str2time_32 = StrToTime(as_8);
   li_ret_28 = li_ret_28 + 60 * (60 * TimeHour(l_str2time_32)) + 60 * TimeMinute(l_str2time_32) + TimeSeconds(l_str2time_32) - 60 * (60 * TimeHour(li_ret_28)) - 60 * TimeMinute(li_ret_28) - TimeSeconds(li_ret_28);
   if (StringFind(as_8, "PM") >= 0 && StringFind(as_8, "12:") < 0) li_ret_28 += 43200;
   if (StringFind(as_8, "AM") >= 0 && StringFind(as_8, "12:") >= 0) li_ret_28 -= 43200;
   if (IsConnected()) li_ret_28 -= GetShiftGMT();
   return (li_ret_28);
}

void GrabNews() {
   string ls_0;
   string ls_8;
   string ls_16;
   string ls_24;
   string ls_32;
   string ls_40;
   string ls_48;
   int li_56;
   int l_datetime_60;
   int li_68;
   int l_style_72;
   color l_color_88;
   bool l_datetime_64 = FALSE;
   int l_count_76 = 0;
   int l_width_80 = 1;
   bool l_color_84 = Black;
   int l_file_92 = FileOpen(g_name_392, FILE_CSV|FILE_READ, ',');
   if (l_file_92 == -1 || FileSize(l_file_92) == 0) {
      Print("Can\'t open file, the last GrabNews error is ", ErrorDescription(GetLastError()));
      if (l_file_92 != -1) FileClose(l_file_92);
   } else {
      ls_8 = StringSubstr(Symbol(), 0, 3);
      ls_16 = StringSubstr(Symbol(), 3, 3);
      for (int l_count_96 = 0; !FileIsEnding(l_file_92); l_count_96++) {
         for (string ls_100 = ""; !FileIsEnding(l_file_92) && ls_100 == ""; ls_100 = FileReadString(l_file_92)) {
         }
         ls_24 = FileReadString(l_file_92);
         ls_0 = FileReadString(l_file_92);
         ls_0 = FileReadString(l_file_92);
         ls_32 = FileReadString(l_file_92);
         ls_40 = FileReadString(l_file_92);
         ls_0 = FileReadString(l_file_92);
         ls_0 = FileReadString(l_file_92);
         ls_0 = FileReadString(l_file_92);
         ls_48 = StringSubstr(ls_100, 0, 3);
         li_56 = 0;
         if (ls_48 == "Mon") li_56 = 0;
         if (ls_48 == "Tue") li_56 = 1;
         if (ls_48 == "Wed") li_56 = 2;
         if (ls_48 == "Thu") li_56 = 3;
         if (ls_48 == "Fri") li_56 = 4;
         if (ls_48 == "Sat") li_56 = 5;
         if (ls_48 == "Sun") li_56 = -1;
         if (ls_100 == "Date") l_count_96++;
         else {
            if (ls_32 == "") l_count_96++;
            else {
               l_datetime_60 = ToDate(ls_100, ls_24);
               Print("                                                                 str = " + ls_100 + ", line1 = " + ls_24);
               li_68 = PreviousMonday(GetTimeGMT()) + 60 * (60 * (24 * li_56));
               l_color_88 = Green;
               if (ls_40 != "Low") {
                  if (ls_40 == "Medium") l_color_88 = Orange;
                  if (ls_40 == "High") l_color_88 = Red;
                  if (l_datetime_64 == l_datetime_60) {
                     if (l_color_88 != Red && l_color_84 == Red) continue;
                     if (l_color_88 == Red) l_count_76++;
                     ls_32 = l_count_76 + " Events + " + ls_32;
                  } else {
                     l_count_76 = 0;
                     l_color_84 = Black;
                  }
                  l_style_72 = 2;
                  if (StringFind(ls_32, ls_8, 0) > -1 || StringFind(ls_32, ls_16, 0) > -1) l_style_72 = 0;
                  if (l_count_76 > 0) l_width_80 = 2;
                  else l_width_80 = 1;
                  ObjectCreate("EventMark" + l_count_96, OBJ_VLINE, 0, l_datetime_60, Close[0]);
                  ObjectSet("EventMark" + l_count_96, OBJPROP_COLOR, l_color_88);
                  ObjectSet("EventMark" + l_count_96, OBJPROP_STYLE, l_style_72);
                  ObjectSet("EventMark" + l_count_96, OBJPROP_BACK, TRUE);
                  ObjectSet("EventMark" + l_count_96, OBJPROP_WIDTH, l_width_80);
                  ObjectSetText("EventMark" + l_count_96, ls_32, 8);
                  l_datetime_64 = l_datetime_60;
                  l_color_84 = l_color_88;
               }
            }
         }
      }
      gi_488 = l_count_96;
      if (l_file_92 != -1) FileClose(l_file_92);
   }
}

void GetNews() {
   int lia_0[] = {1};
   string ls_4 = "x";
   bool li_12 = FALSE;
   int li_16 = PreviousMonday(GetTimeGMT());
   string l_time2str_20 = TimeToStr(li_16 - 86400, TIME_DATE);
   string ls_28 = StringSubstr(l_time2str_20, 0, 4);
   string ls_36 = StringSubstr(l_time2str_20, 5, 2) + StringSubstr(l_time2str_20, 8, 2);
   string ls_44 = "http://www.dailyfx.com/calendar/Dailyfx_Global_Economic_Calendar.csv?currentWeek=/events-calendar/" + ls_28 + "/" + ls_36 + "/&direction=none&collector=allInFolderDateDesc&view=week&timezone=GMT&currencyFilter=|&importanceFilter=|";
   int li_52 = InternetOpenUrlA(hSession(0), ls_44, "0", 0, 67108864, 0);
   int li_56 = InternetReadFile(li_52, ls_4, gi_512, lia_0);
   if (li_12) {
      Print("hInternet: " + li_52);
      Print("iResult: " + li_56);
      Print("lReturn: " + lia_0[0]);
      Print("sBuffer: " + ls_4);
      Comment("sBuffer: " + ls_4);
   }
   string ls_60 = StringSubstr(ls_4, 0, lia_0[0]);
   for (ls_60 = StringSubstr(ls_4, 0, lia_0[0]); lia_0[0] != 0; ls_60 = ls_60 + StringSubstr(ls_4, 0, lia_0[0])) {
      li_56 = InternetReadFile(li_52, ls_4, gi_512, lia_0);
      if (lia_0[0] == 0) break;
   }
   if (li_12) Print("sData: " + ls_60);
   li_56 = InternetCloseHandle(li_52);
   if (li_12) Print("iResult: " + li_56);
   int l_file_68 = FileOpen(g_name_392, FILE_BIN|FILE_WRITE);
   if (l_file_68 < 1) {
      Print("Can\'t open file, the last GetNews error is ", ErrorDescription(GetLastError()));
      if (l_file_68 != -1) FileClose(l_file_68);
   } else {
      FileWriteString(l_file_68, ls_60, StringLen(ls_60));
      FileClose(l_file_68);
   }
}

int fnMakeMagicNumber() {
   if (Symbol() == "AUDCAD" || Symbol() == "AUDCADm") return (1);
   if (Symbol() == "AUDJPY" || Symbol() == "AUDJPYm") return (2);
   if (Symbol() == "AUDNZD" || Symbol() == "AUDNZDm") return (3);
   if (Symbol() == "AUDUSD" || Symbol() == "AUDUSDm") return (4);
   if (Symbol() == "CHFJPY" || Symbol() == "CHFJPYm") return (5);
   if (Symbol() == "EURAUD" || Symbol() == "EURAUDm") return (6);
   if (Symbol() == "EURCAD" || Symbol() == "EURCADm") return (7);
   if (Symbol() == "EURCHF" || Symbol() == "EURCHFm") return (8);
   if (Symbol() == "EURGBP" || Symbol() == "EURGBPm") return (9);
   if (Symbol() == "EURJPY" || Symbol() == "EURJPYm") return (10);
   if (Symbol() == "EURUSD" || Symbol() == "EURUSDm") return (11);
   if (Symbol() == "GBPCHF" || Symbol() == "GBPCHFm") return (12);
   if (Symbol() == "GBPJPY" || Symbol() == "GBPJPYm") return (13);
   if (Symbol() == "GBPUSD" || Symbol() == "GBPUSDm") return (14);
   if (Symbol() == "NZDJPY" || Symbol() == "NZDJPYm") return (15);
   if (Symbol() == "NZDUSD" || Symbol() == "NZDUSDm") return (16);
   if (Symbol() == "USDCAD" || Symbol() == "USDCADm") return (17);
   if (Symbol() == "USDCHF" || Symbol() == "USDCHFm") return (18);
   if (Symbol() == "USDJPY" || Symbol() == "USDJPYm") return (19);
   return (0);
}