#property copyright "Version 007.00 Copyright © 2011, Greg Spinner"
#property link "mailto:greg@globeplus.co.uk"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Fuchsia
#property indicator_color2 Fuchsia
#property indicator_color3 Black
#property indicator_color4 Blue
#property indicator_color5 Red
#property indicator_color6 Red
#property indicator_color7 Green
#import "kernel32.dll"
int FindFirstFileA(string a0, int& a1[]);
bool FindNextFileA(int a0, int& a1[]);
bool FindClose(int a0);
bool FileTimeToSystemTime(int& a0[], int& a1[]);
int GetTimeZoneInformation(int& a0[]);
#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
string gs_v007_76 = "v007";
int gi_84;
int gi_88;
int gi_92;
int gi_96;
int gi_100;
int gi_104;
int gia_112[43];
extern string Choose = "Type = Forex, FTSE, Gold or Brent";
extern string type = "Forex";
extern bool BigRoundNumberCheck = TRUE;
extern bool checkOpenSignal = TRUE;
extern bool cancelOpenSignalAtEoD = TRUE;
bool gi_144 = TRUE;
bool gi_148 = FALSE;
extern bool waitForNewCrossoverAtDaySt = TRUE;
extern string DayStServerHHMM = "01:00";
extern int channelTolerancePips = 2;
extern int openSignalProfit = 50;
extern int openSignalLoss = 25;
extern bool screen_alert = TRUE;
extern bool email_alert = FALSE;
extern bool infoText = TRUE;
extern color buyTextColor = Blue;
extern color sellTextColor = Red;
extern int arrowSize = 2;
extern color buyArrowColor = Blue;
extern color sellArrowColor = Red;
extern bool showTradeLevels = TRUE;
extern bool removeLevelsOnTradeClose = TRUE;
extern string ANPhd = "News avoidance parameters";
extern bool avoidNews = TRUE;
extern int brokerOffset = 1;
extern bool stopIfNewsFails = FALSE;
extern bool newsDebugLevel = FALSE;
extern int newsUpdateInterval = 15;
extern int minutesBeforeNews = 30;
extern int minutesAfterNews = 30;
extern bool IncludeHigh = TRUE;
extern bool IncludeMedium = TRUE;
extern bool IncludeLow = FALSE;
extern bool IncludeSpeaks = TRUE;
extern int OffsetHours = 0;
extern bool ReportAllForUSD = TRUE;
extern bool ReportAllForEUR = FALSE;
extern bool ReportAllForGBP = FALSE;
extern bool ReportAllForNZD = FALSE;
extern bool ReportAllForJPY = FALSE;
extern bool ReportAllForAUD = FALSE;
extern bool ReportAllForCHF = FALSE;
extern bool ReportAllForCAD = FALSE;
extern bool ReportAllForCNY = FALSE;
extern string ANPtr = "++++++++++";
int gi_316 = 1;
bool gi_320 = FALSE;
int g_shift_324 = 0;
int g_shift_328 = 0;
int gi_332 = 1306326660;
int gi_336 = 1306331280;
int g_period_340 = 50;
int g_ma_method_344 = MODE_EMA;
int g_applied_price_348 = PRICE_HIGH;
int g_period_352 = 50;
int g_ma_method_356 = MODE_EMA;
int g_applied_price_360 = PRICE_LOW;
int g_period_364 = 15;
int g_ma_method_368 = MODE_EMA;
int g_applied_price_372 = PRICE_CLOSE;
int g_period_376 = 8;
int g_ma_method_380 = MODE_EMA;
int g_applied_price_384 = PRICE_CLOSE;
int g_period_388 = 5;
int g_ma_method_392 = MODE_EMA;
int g_applied_price_396 = PRICE_CLOSE;
double gd_400;
double gd_408;
int gi_416;
int gi_420;
double g_ibuf_424[];
double g_ibuf_428[];
double g_ibuf_432[];
double g_ibuf_436[];
double g_ibuf_440[];
double g_ibuf_444[];
double g_ibuf_448[];
string gs_452;
string gs_460;
string gsa_468[256];
int gi_472 = 1307577600;
int gi_476;
string gsa_480[2];
bool g_str2time_484;
datetime gt_unused_488;
int g_str2time_492;
int gi_496;
string g_str_concat_500;
string g_str_concat_508;
string gs_dummy_516;
double gd_524;
bool gi_532;
bool gi_536;
bool gi_540;
bool gi_544;
double gd_548;
double gd_556;
double gd_564;
double gd_572;
double g_price_580;
double g_price_588;
double g_price_596;
double gd_604;
int g_datetime_612;
string gs_dummy_616;
bool g_bool_624;
bool g_bool_628;
string gs_632 = "http://www.forexfactory.com/ffcal_week_this.xml";
int g_file_640;
int g_file_644 = -1;
int gi_648;
int gi_656;
int g_index_660;
int gi_664;
string gsa_668[100][7];
string gsa_672[7] = {"
", "", "", "", "", "", "", "", "", ""};
bool gi_680 = FALSE;
int gi_unused_684 = -1;
int gi_unused_688 = 0;
int gi_unused_692 = 0;
string g_name_696;
string gs_704 = "";
int gi_unused_712;
int gi_716;
double gda_724[500];
int gia_728[500];
int gi_unused_732;
int gi_unused_736;
int gi_unused_740;
int gi_unused_744;
string gs_unused_748;
string gs_unused_756;
string gs_unused_764;
string gs_unused_772;
string gs_unused_780;
string gs_unused_788;
string gs_unused_796;
string gs_unused_804;
string gs_unused_812;
string gs_unused_820;
string gs_unused_828;
string gs_unused_836;
bool gi_844 = TRUE;
bool gi_848 = FALSE;
bool gi_unused_852 = FALSE;
int gia_856[500];
bool gi_864 = FALSE;
int gi_868;
int gi_872;
int gi_876 = 0;
int gi_880 = 1;
int gi_unused_884 = 3;
int gi_888 = 80;
int gia_892[43];
int getProgramCreationDate(string as_0) {
int lia_8[82];
int lia_12[2];
int lia_16[4];
string ls_52;
int l_str2time_60;
int li_20 = 0;
int li_24 = GetTimeZoneInformation(gia_112);
if (li_24 != 0) li_20 = gia_112[0];
if (li_24 == 2) li_20 += gia_112[42];
int li_28 = FindFirstFileA(TerminalPath() + as_0, lia_8);
string ls_32 = bufferToString(lia_8);
for (string ls_40 = getExpertName(ls_32); ls_40 != WindowExpertName(); ls_40 = getExpertName(ls_32)) {
ArrayInitialize(lia_8, 0);
if (!(FindNextFileA(li_28, lia_8))) break;
ls_32 = bufferToString(lia_8);
}
int l_str2time_48 = -1;
if (ls_40 == WindowExpertName()) {
Print("expert name = " + ls_40);
lia_12[0] = lia_8[1];
lia_12[1] = lia_8[2];
if (FileTimeToSystemTime(lia_12, lia_16)) {
gi_84 = lia_16[0] & 65535;
gi_88 = lia_16[0] >> 16;
gi_92 = lia_16[1] >> 16;
gi_96 = lia_16[2] & 65535;
gi_100 = lia_16[2] >> 16;
gi_104 = lia_16[3] & 65535;
ls_52 = FormatDateTime(gi_84, gi_88, gi_92, gi_96, gi_100, gi_104);
l_str2time_60 = StrToTime(ls_52);
}
l_str2time_48 = l_str2time_60;
}
ArrayInitialize(lia_8, 0);
if (li_28 > 0) FindClose(li_28);
return (l_str2time_48);
}
string FormatDateTime(int ai_0, int ai_4, int ai_8, int ai_12, int ai_16, int ai_20) {
string ls_24 = ai_4 + 100;
ls_24 = StringSubstr(ls_24, 1);
string ls_32 = ai_8 + 100;
ls_32 = StringSubstr(ls_32, 1);
string ls_40 = ai_12 + 100;
ls_40 = StringSubstr(ls_40, 1);
string ls_48 = ai_16 + 100;
ls_48 = StringSubstr(ls_48, 1);
string ls_56 = ai_20 + 100;
ls_56 = StringSubstr(ls_56, 1);
return (StringConcatenate(ai_0, ".", ls_24, ".", ls_32, " ", ls_40, ":", ls_48, ":", ls_56));
}
string bufferToString(int aia_0[82]) {
int li_20;
string ls_ret_4 = "";
int li_12 = 10;
for (int l_count_16 = 0; l_count_16 < 64; l_count_16++) {
li_12++;
li_20 = aia_0[li_12];
ls_ret_4 = ls_ret_4 + CharToStr(li_20 & 255) + CharToStr(li_20 >> 8 & 255) + CharToStr(li_20 >> 16 & 255) + CharToStr(li_20 >> 24 & 255);
}
return (ls_ret_4);
}
string getExpertName(string as_0) {
string ls_unused_12;
int li_8 = StringFind(as_0, ".ex4");
return (StringSubstr(as_0, 0, li_8));
}
int getNewsTimes() {
int li_4;
string ls_8;
bool li_16;
int l_str2time_20;
int li_68;
int li_72;
double ld_76;
int l_index_0 = 0;
g_name_696 = GetXmlFileName();
gd_604 = (TimeCurrent() - g_datetime_612) / 60;
if (gd_604 >= newsUpdateInterval) {
FileDelete(g_name_696);
g_datetime_612 = TimeCurrent();
}
g_file_640 = FileOpen(g_name_696, FILE_BIN|FILE_READ);
if (g_file_640 >= 0) {
FileClose(g_file_640);
gi_680 = FALSE;
} else gi_680 = TRUE;
if (gi_680) {
if (newsDebugLevel > TRUE) Print("sUrl == ", gs_632);
if (newsDebugLevel > FALSE) Print("Grabbing Web, url = ", gs_632);
GrabWeb(gs_632, gs_704);
g_file_640 = FileOpen(g_name_696, FILE_BIN|FILE_WRITE);
if (g_file_640 < 0) {
if (newsDebugLevel > FALSE) Print("Can\'t open new xml file, the last error is ", GetLastError());
return (0);
}
FileWriteString(g_file_640, gs_704, StringLen(gs_704));
FileClose(g_file_640);
if (newsDebugLevel > FALSE) Print("Wrote XML file...\n");
gi_656 = StringFind(gs_704, "", 0);
if (gi_656 <= 0) {
if (!gi_848) {
if (g_bool_624) {
Alert("NewsReader Error - Web page download was not complete!");
gi_848 = TRUE;
}
if (g_bool_628) SendMail(StringConcatenate(WindowExpertName(), " (", Symbol(), ") Problem reading news..."), StringConcatenate("NewsReader Error - Web page download was not complete! Check AFFTrader on ", Symbol()));
}
return (0);
}
GlobalVariableSet("LastUpdateTime", TimeCurrent());
}
OpenLog("NewsReader");
g_file_640 = FileOpen(g_name_696, FILE_BIN|FILE_READ);
if (g_file_640 < 0) {
Print("Can\'t open xml file: ", g_name_696, ". The last error is ", GetLastError());
if (!gi_848) {
if (g_bool_624) {
Alert(StringConcatenate("Can\'t open xml file: ", g_name_696, ". The last error is ", GetLastError()));
gi_848 = TRUE;
}
if (g_bool_628) SendMail(StringConcatenate(WindowExpertName(), " (", Symbol(), ") Problem reading news..."), StringConcatenate("Can\'t open xml file: ", g_name_696, ". The last error is ", GetLastError(), "AFFTrader has been disabled on ", Symbol()));
}
gi_unused_732 = 99999;
gi_unused_736 = 99999;
return (0);
}
if (newsDebugLevel > FALSE) Print("XML file open must be okay");
gs_704 = FileReadString(g_file_640, 65536);
if (StringLen(gs_704) < FileSize(g_file_640)) gs_704 = gs_704 + FileReadString(g_file_640, FileSize(g_file_640));
if (g_file_640 > 0) FileClose(g_file_640);
string ls_24 = Symbol();
string ls_32 = StringSubstr(ls_24, 0, 3);
string ls_40 = StringSubstr(ls_24, 3, 3);
if (newsDebugLevel > FALSE) Print("cntry1 = ", ls_32, " cntry2 = ", ls_40);
if (newsDebugLevel > FALSE) {
Log("\nWeekly calendar for " + ls_24
+ "\n");
}
gi_unused_712 = 10080;
gi_648 = 0;
ArrayInitialize(gda_724, -1);
ArrayInitialize(gia_728, -1);
ArrayInitialize(gia_856, 0);
int li_48 = -1;
int li_52 = -1;
int l_index_56 = 0;
bool li_60 = FALSE;
bool li_64 = FALSE;
while (true) {
gi_648 = StringFind(gs_704, "", gi_648);
if (gi_648 == -1) break;
gi_648 += 7;
li_4 = StringFind(gs_704, "", gi_648);
if (li_4 == -1) break;
ls_8 = StringSubstr(gs_704, gi_648, li_4 - gi_648);
gi_648 = li_4;
gi_664 = 0;
li_16 = FALSE;
for (g_index_660 = 0; g_index_660 < 7; g_index_660++) {
gsa_668[l_index_0][g_index_660] = "";
li_4 = StringFind(ls_8, gsa_672[g_index_660], gi_664);
if (li_4 != -1) {
gi_664 = li_4 + StringLen(gsa_672[g_index_660]);
gi_656 = StringFind(ls_8, gsa_676[g_index_660], gi_664);
if (gi_656 > gi_664 && gi_656 != -1) {
gsa_668[l_index_0][g_index_660] = StringSubstr(ls_8, gi_664, gi_656 - gi_664);
if (StringFind(gsa_668[l_index_0][g_index_660], "CDATA") > -1) {
li_68 = 9;
li_72 = StringFind(gsa_668[l_index_0][g_index_660], "]") - li_68;
gsa_668[l_index_0][g_index_660] = StringSubstr(gsa_668[l_index_0][g_index_660], li_68, li_72);
}
}
}
}
if (ls_32 != gsa_668[l_index_0][1] && ls_40 != gsa_668[l_index_0][1] && (!ReportAllForUSD || gsa_668[l_index_0][1] != "USD" && !ReportAllForEUR || gsa_668[l_index_0][1] != "EUR" &&
!ReportAllForGBP || gsa_668[l_index_0][1] != "GBP" && !ReportAllForNZD || gsa_668[l_index_0][1] != "NZD" && !ReportAllForJPY || gsa_668[l_index_0][1] != "JPY" && !ReportAllForAUD ||
gsa_668[l_index_0][1] != "AUD" && !ReportAllForCAD || gsa_668[l_index_0][1] != "CAD" && !ReportAllForCHF || gsa_668[l_index_0][1] != "CHF" && !ReportAllForCNY || gsa_668[l_index_0][1] != "CNY")) li_16 = TRUE;
if (!IncludeHigh && gsa_668[l_index_0][4] == "High") li_16 = TRUE;
if (!IncludeMedium && gsa_668[l_index_0][4] == "Medium") li_16 = TRUE;
if (!IncludeLow && gsa_668[l_index_0][4] == "Low") li_16 = TRUE;
if (!IncludeSpeaks && StringFind(gsa_668[l_index_0][0], "speaks") != -1 || StringFind(gsa_668[l_index_0][0], "Speaks") != -1) li_16 = TRUE;
if (gsa_668[l_index_0][3] == "All Day" || gsa_668[l_index_0][3] == "Tentative" || gsa_668[l_index_0][3] == "") li_16 = TRUE;
if (!(!li_16)) continue;
l_str2time_20 = StrToTime(MakeDateTime(gsa_668[l_index_0][2], gsa_668[l_index_0][3]));
ld_76 = TimeCurrent() - TimeGMT();
gia_856[l_index_56] = l_str2time_20 + ld_76;
l_index_56++;
gi_716 = (l_str2time_20 - TimeGMT()) / 60;
if (newsDebugLevel > FALSE) Log("(" + l_index_0 + ") Title: " + gsa_668[l_index_0][0] + "mins til news = " + gi_716);
if (gi_716 < 0) {
li_52 = l_index_0;
li_60 = MathAbs(gi_716);
} else {
li_48 = l_index_0;
li_64 = gi_716;
break;
}
l_index_0++;
}
int li_unused_84 = 1;
gi_unused_732 = 99999;
gi_unused_736 = 99999;
gi_unused_740 = 0;
gi_unused_744 = 0;
if (li_52 >= 0) {
gi_unused_732 = li_60;
gi_unused_740 = ImpactToNumber(gsa_668[li_52][4]);
gs_unused_748 = gsa_668[li_52][0];
gs_unused_756 = gsa_668[li_52][1];
gs_unused_764 = gsa_668[li_52][4];
gs_unused_772 = gsa_668[li_52][5];
gs_unused_780 = gsa_668[li_52][6];
gs_unused_788 = gsa_668[li_52][3];
}
if (li_48 >= 0) {
gi_unused_736 = li_64;
gi_unused_740 = ImpactToNumber(gsa_668[li_48][4]);
gs_unused_796 = gsa_668[li_48][0];
gs_unused_804 = gsa_668[li_48][1];
gs_unused_812 = gsa_668[li_48][4];
gs_unused_820 = gsa_668[li_48][5];
gs_unused_828 = gsa_668[li_48][6];
gs_unused_836 = gsa_668[li_48][3];
}
if (g_file_644 > 0) {
FileClose(g_file_644);
g_file_644 = -1;
}
g_name_696 = GetXmlFileName();
g_file_640 = FileOpen(g_name_696, FILE_BIN|FILE_WRITE|FILE_READ);
if (g_file_640 >= 0) FileClose(g_file_640);
return (1);
}
string GetXmlFileName() {
return (Month() + "-" + Day() + "-" + Year() + "-" + Symbol() + Period() + "-" + "FFCal.xml");
}
string MakeDateTime(string as_0, string as_8) {
int li_16 = StringFind(as_0, "-");
int li_20 = StringFind(as_0, "-", li_16 + 1);
string ls_24 = StringSubstr(as_0, 0, 2);
string ls_32 = StringSubstr(as_0, 3, 2);
string ls_40 = StringSubstr(as_0, 6, 4);
int li_48 = StringFind(as_8, ":");
string ls_52 = StringSubstr(as_8, 0, li_48);
string ls_60 = StringSubstr(as_8, li_48 + 1, 2);
string ls_68 = StringSubstr(as_8, StringLen(as_8) - 2);
int li_76 = StrToInteger(ls_52);
if (ls_68 == "pm" || ls_68 == "PM" && li_76 != 12) li_76 += 12;
if (ls_68 == "am" || ls_68 == "AM" && li_76 == 12) li_76 = 0;
string ls_80 = "";
if (li_76 < 10) ls_80 = "0";
return (StringConcatenate(ls_40, ".", ls_24, ".", ls_32, " ", ls_80, li_76, ":", ls_60));
}
double ImpactToNumber(string as_0) {
if (as_0 == "High") return (3);
if (as_0 == "Medium") return (2);
if (as_0 == "Low") return (1);
return (0);
}
int hSession(bool ai_0) {
string ls_4 = "";
if (gi_868 == 0) {
ls_4 = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)";
gi_868 = InternetOpenA(ls_4, gi_876, "0", "0", 0);
gi_872 = InternetOpenA(ls_4, gi_880, "0", "0", 0);
}
if (ai_0) return (gi_872);
return (gi_868);
}
int GrabWeb(string as_0, string &as_8) {
int lia_24[] = {1};
string ls_28 = " ";
int li_16 = InternetOpenUrlA(hSession(0), as_0, "0", 0, -2080374528, 0);
if (gi_864) Log("hInternet: " + li_16);
if (li_16 == 0) return (0);
if (newsDebugLevel > FALSE) Print("Reading URL: " + as_0);
int li_20 = InternetReadFile(li_16, ls_28, gi_888, lia_24);
if (gi_864) Log("iResult: " + li_20);
if (gi_864) Log("lReturn: " + lia_24[0]);
if (gi_864) Log("iResult: " + li_20);
if (gi_864) Log("sBuffer: " + ls_28);
if (li_20 == 0) return (0);
int li_36 = lia_24[0];
for (as_8 = StringSubstr(ls_28, 0, lia_24[0]); lia_24[0] != 0; as_8 = as_8 + StringSubstr(ls_28, 0, lia_24[0])) {
li_20 = InternetReadFile(li_16, ls_28, gi_888, lia_24);
if (lia_24[0] == 0) break;
li_36 += lia_24[0];
}
if (newsDebugLevel > FALSE) Print("Closing URL web connection");
li_20 = InternetCloseHandle(li_16);
if (li_20 == 0) return (0);
return (1);
}
void OpenLog(string as_0) {
string ls_8;
string ls_16;
string l_str_concat_24;
if (gi_844) {
if (g_file_644 <= 0) {
ls_8 = "";
ls_16 = "";
if (Month() < 10) ls_8 = "0";
if (Day() < 10) ls_16 = "0";
l_str_concat_24 = StringConcatenate(as_0, "_", Year(), ls_8, Month(), ls_16, Day(), "_log.txt");
g_file_644 = FileOpen(l_str_concat_24, FILE_CSV|FILE_WRITE|FILE_READ);
if (newsDebugLevel > FALSE) Print("logHandle =================================== ", g_file_644);
}
if (g_file_644 > 0) {
FileFlush(g_file_644);
FileSeek(g_file_644, 0, SEEK_END);
}
}
}
void Log(string as_0) {
if (gi_844) {
if (g_file_644 > 0) {
as_0 = TimeToStr(TimeCurrent(), TIME_DATE|TIME_MINUTES|TIME_SECONDS) + " " + as_0;
FileWrite(g_file_644, as_0);
}
}
}
int TimeGMT() {
int li_0 = GetTimeZoneInformation(gia_892);
if (li_0 == 1) li_0 = 3600;
else li_0 = 0;
return (TimeLocal() + li_0 + 3600 * OffsetHours + 60 * (gia_892[0] + gia_892[42]));
}
int init() {
string l_str_concat_24;
string ls_32;
int li_40;
g_str_concat_500 = StringConcatenate(WindowExpertName(), "cyLabel");
g_str_concat_508 = StringConcatenate(WindowExpertName(), "infoLabel");
gt_unused_488 = Time[0];
IndicatorBuffers(7);
SetIndexStyle(0, DRAW_LINE, EMPTY, 2);
SetIndexBuffer(0, g_ibuf_424);
SetIndexLabel(0, StringConcatenate("Moving average (", g_period_340, ")"));
SetIndexStyle(1, DRAW_LINE, EMPTY, 2);
SetIndexBuffer(1, g_ibuf_428);
SetIndexLabel(1, StringConcatenate("Moving average (", g_period_352, ")"));
SetIndexStyle(2, DRAW_LINE, EMPTY, 2);
SetIndexBuffer(2, g_ibuf_432);
SetIndexLabel(2, StringConcatenate("Moving average (", g_period_364, ")"));
SetIndexStyle(3, DRAW_LINE, EMPTY, 2);
SetIndexBuffer(3, g_ibuf_440);
SetIndexLabel(3, StringConcatenate("Moving average (", g_period_376, ")"));
SetIndexStyle(4, DRAW_LINE, EMPTY, 2);
SetIndexBuffer(4, g_ibuf_436);
SetIndexLabel(4, StringConcatenate("Moving average (", g_period_388, ")"));
SetIndexStyle(5, DRAW_ARROW, EMPTY, arrowSize, sellArrowColor);
SetIndexArrow(5, 234);
SetIndexBuffer(5, g_ibuf_448);
SetIndexLabel(5, "Sell signal");
SetIndexStyle(6, DRAW_ARROW, EMPTY, arrowSize, buyArrowColor);
SetIndexArrow(6, 233);
SetIndexBuffer(6, g_ibuf_444);
SetIndexLabel(6, "Buy signal");
IndicatorDigits(Digits);
deleteObjects();
ObjectDelete(g_str_concat_500);
ObjectDelete(g_str_concat_508);
Print("sym=" + Symbol(), ", point=", DoubleToStr(Point, Digits), ", Digits=", Digits);
gd_400 = Point;
gi_416 = Digits;
if (type == "Forex") {
if (Digits >= 5 || Digits == 3 || Digits == 1 && Point * MathPow(10, Digits) == 1.0) {
gd_400 = 10.0 * gd_400;
gi_416--;
}
}
if (type == "FTSE")
if (Digits == 1 && Point * MathPow(10, Digits) == 1.0) gd_400 = 10.0 * gd_400;
if (type == "Scalper") {
if (Digits >= 5 || Digits == 3 && Point * MathPow(10, Digits) == 1.0) {
gd_400 = 10.0 * gd_400;
gi_416--;
}
}
if (type == "Brent") {
}
if (type == "Gold") {
if (Digits == 2 && Point * MathPow(10, Digits) == 1.0) {
gd_400 = 10.0 * gd_400;
gi_416--;
}
}
double l_ask_0 = MarketInfo(Symbol(), MODE_ASK);
double l_bid_8 = MarketInfo(Symbol(), MODE_BID);
gd_408 = l_ask_0 - l_bid_8;
gsa_480[0] = "Buy";
gsa_480[1] = "Sell";
g_str2time_484 = FALSE;
gt_unused_488 = 0;
for (int l_index_16 = 0; l_index_16 < 256; l_index_16++) gsa_468[l_index_16] = CharToStr(l_index_16);
gs_452 = gsa_468[40] + gsa_468[99] + gsa_468[111] + gsa_468[112] + gsa_468[121] + gsa_468[114] + gsa_468[105] + gsa_468[103] + gsa_468[104] + gsa_468[116] + gsa_468[32] +
gsa_468[64] + gsa_468[32] + gsa_468[50] + gsa_468[48] + gsa_468[49] + gsa_468[49] + gsa_468[32] + gsa_468[71] + gsa_468[114] + gsa_468[101] + gsa_468[103] + gsa_468[32] +
gsa_468[83] + gsa_468[112] + gsa_468[105] + gsa_468[110] + gsa_468[110] + gsa_468[101] + gsa_468[114] + gsa_468[41];
gs_460 = WindowExpertName();
Print("iname=" + gs_460);
int li_20 = 0;
if (li_20 > 0) {
ls_32 = "\\experts\\indicators\\*.ex4";
li_40 = getProgramCreationDate(ls_32);
gi_476 = li_40 + li_20;
l_str_concat_24 = StringConcatenate(" ----> Program will work from ", TimeToStr(li_40), " until ", TimeToStr(gi_476, TIME_DATE), " 23:59");
} else {
l_str_concat_24 = "Non-expiring version";
gi_476 = 0;
}
Print(gs_460, " ", gs_452, ".", l_str_concat_24);
for (int l_index_44 = 0; l_index_44 < Bars; l_index_44++) {
g_ibuf_424[l_index_44] = 0.0;
g_ibuf_428[l_index_44] = 0.0;
g_ibuf_432[l_index_44] = 0.0;
g_ibuf_440[l_index_44] = 0.0;
g_ibuf_436[l_index_44] = 0.0;
g_ibuf_444[l_index_44] = 0.0;
g_ibuf_448[l_index_44] = 0.0;
}
showDebug("About to deleteLines from init", 0);
deleteLines(0);
gi_544 = TRUE;
g_bool_624 = screen_alert;
g_bool_628 = email_alert;
return (0);
}
int deinit() {
deleteObjects();
ObjectDelete(g_str_concat_500);
ObjectDelete(g_str_concat_508);
for (int l_index_0 = 0; l_index_0 < Bars; l_index_0++) {
g_ibuf_424[l_index_0] = 0.0;
g_ibuf_428[l_index_0] = 0.0;
g_ibuf_432[l_index_0] = 0.0;
g_ibuf_440[l_index_0] = 0.0;
g_ibuf_436[l_index_0] = 0.0;
g_ibuf_444[l_index_0] = 0.0;
g_ibuf_448[l_index_0] = 0.0;
}
showDebug("About to deleteLines from deinit", 0);
deleteLines(0);
return (0);
}
bool nextBRNOk(int ai_unused_0, double ad_4, int ai_12) {
if (!BigRoundNumberCheck) return (TRUE);
double ld_16 = ad_4 / gd_400;
double ld_24 = NormalizeDouble(ld_16, 0);
string l_dbl2str_32 = DoubleToStr(ld_24, 0);
int l_str_len_40 = StringLen(l_dbl2str_32);
string ls_44 = StringSubstr(l_dbl2str_32, l_str_len_40 - 2);
int l_str2int_52 = StrToInteger(ls_44);
int li_56 = MathAbs(100 - l_str2int_52);
showDebug("pips=" + ld_16 + ", lesspips=" + ld_24 + ", stringpips=" + l_dbl2str_32 + ", stringlength=" + l_str_len_40 + ", endtwo=" + ls_44 + ",end2=" + l_str2int_52 +
", difference=" + li_56, ai_12);
if (li_56 <= 5 || li_56 >= 95) return (FALSE);
return (TRUE);
}
int getXTime(int ai_0, int ai_4) {
datetime l_time_8 = 0;
for (int li_12 = ai_4; li_12 < Bars; li_12++) {
if (ai_0 == 0) {
if (!(g_ibuf_436[li_12] >= g_ibuf_440[li_12] && g_ibuf_440[li_12] >= g_ibuf_432[li_12] && g_ibuf_436[li_12] >= g_ibuf_432[li_12])) {
l_time_8 = Time[li_12];
break;
}
}
if (ai_0 == 1) {
if (!(g_ibuf_436[li_12] <= g_ibuf_440[li_12] && g_ibuf_440[li_12] <= g_ibuf_432[li_12] && g_ibuf_436[li_12] <= g_ibuf_432[li_12])) {
l_time_8 = Time[li_12];
break;
}
}
}
return (l_time_8);
}
double calculateProfits(int ai_0, double ad_4, int ai_12) {
int li_16 = MathMax(ai_0 - ai_12, 1);
int l_highest_20 = iHighest(Symbol(), 0, MODE_HIGH, li_16, ai_12);
double ld_24 = NormalizeDouble(High[l_highest_20], gi_416);
int l_lowest_32 = iLowest(Symbol(), 0, MODE_LOW, li_16, ai_12);
double ld_36 = NormalizeDouble(Low[l_lowest_32], gi_416);
gd_556 = (ad_4 - ld_36) / gd_400;
gd_572 = (ld_24 - ad_4) / gd_400;
gd_548 = (ld_24 - ad_4) / gd_400;
gd_564 = (ad_4 - ld_36) / gd_400;
return (0.0);
}
double getStartPos(int ai_0, double ad_4, int ai_12) {
double ld_ret_16;
if (ai_0 == 1) {
ld_ret_16 = ad_4;
showDebug("sp=" + ld_ret_16, ai_12);
for (int li_24 = ai_12 + 3; li_24 > MathMax(ai_12 - 3, 1); li_24--) {
ld_ret_16 = MathMax(ld_ret_16, High[li_24]);
if (li_24 >= ai_12) {
ld_ret_16 = MathMax(ld_ret_16, g_ibuf_424[li_24]);
ld_ret_16 = MathMax(ld_ret_16, g_ibuf_436[li_24]);
ld_ret_16 = MathMax(ld_ret_16, g_ibuf_440[li_24]);
ld_ret_16 = MathMax(ld_ret_16, g_ibuf_432[li_24]);
}
}
ld_ret_16 += gd_524 * gd_400;
}
if (ai_0 == 0) {
ld_ret_16 = ad_4;
for (li_24 = ai_12 + 3; li_24 > MathMax(ai_12 - 3, 1); li_24--) {
ld_ret_16 = MathMin(ld_ret_16, Low[li_24]);
if (li_24 >= ai_12) {
ld_ret_16 = MathMin(ld_ret_16, g_ibuf_428[li_24]);
ld_ret_16 = MathMin(ld_ret_16, g_ibuf_436[li_24]);
ld_ret_16 = MathMin(ld_ret_16, g_ibuf_440[li_24]);
ld_ret_16 = MathMin(ld_ret_16, g_ibuf_432[li_24]);
}
}
ld_ret_16 -= gd_524 * gd_400;
}
return (ld_ret_16);
}
void createLines(double a_price_0, double a_price_8, double a_price_16, int ai_24) {
double ld_28 = 0;
double ld_36 = 0;
double ld_44 = 0;
if (ObjectFind("eline") > -1) ld_28 = ObjectGet("eline", OBJPROP_PRICE1);
if (ObjectFind("pline") > -1) ld_36 = ObjectGet("pline", OBJPROP_PRICE1);
if (ObjectFind("sline") > -1) ld_44 = ObjectGet("sline", OBJPROP_PRICE1);
if (ld_28 == a_price_0 && ld_36 == a_price_16 && ld_44 == a_price_8) return;
showDebug("In createLines: about to call deleteLines", ai_24);
deleteLines(ai_24);
ObjectCreate("eline", OBJ_HLINE, 0, 0, a_price_0);
ObjectSet("eline", OBJPROP_COLOR, Blue);
ObjectSet("eline", OBJPROP_STYLE, STYLE_DASH);
ObjectCreate("sline", OBJ_HLINE, 0, 0, a_price_8);
ObjectSet("sline", OBJPROP_COLOR, Red);
ObjectSet("sline", OBJPROP_STYLE, STYLE_DASH);
ObjectCreate("pline", OBJ_HLINE, 0, 0, a_price_16);
ObjectSet("pline", OBJPROP_COLOR, Green);
ObjectSet("pline", OBJPROP_STYLE, STYLE_DASH);
}
void deleteLines(int ai_unused_0) {
if (ObjectFind("eline") >= 0) ObjectDelete("eline");
if (ObjectFind("sline") >= 0) ObjectDelete("sline");
if (ObjectFind("pline") >= 0) ObjectDelete("pline");
}
void createThumbsDown(int ai_0, double ad_4, int ai_12, int ai_unused_16) {
string ls_24;
int li_32;
int l_time_20 = Time[ai_12];
if (ObjectFind(StringConcatenate("buyloss", l_time_20)) > -1 || ObjectFind(StringConcatenate("sellloss", l_time_20)) > -1 || ObjectFind(StringConcatenate("buyprof", l_time_20)) > -1 ||
ObjectFind(StringConcatenate("sellprof", l_time_20)) > -1) return;
if (ai_0 == 0) {
ls_24 = "buyloss";
li_32 = -1;
} else {
ls_24 = "sellloss";
li_32 = 1;
}
ObjectCreate(StringConcatenate(ls_24, l_time_20), OBJ_ARROW, 0, l_time_20, ad_4 + 2.0 * (li_32 * gd_524) * gd_400);
ObjectSet(StringConcatenate(ls_24, l_time_20), OBJPROP_ARROWCODE, SYMBOL_THUMBSDOWN);
ObjectSet(StringConcatenate(ls_24, l_time_20), OBJPROP_WIDTH, arrowSize);
}
void createThumbsUp(int ai_0, double ad_4, int ai_12, int ai_unused_16) {
string ls_24;
int li_32;
int l_time_20 = Time[ai_12];
if (ObjectFind(StringConcatenate("buyloss", l_time_20)) > -1 || ObjectFind(StringConcatenate("sellloss", l_time_20)) > -1 || ObjectFind(StringConcatenate("buyprof", l_time_20)) > -1 ||
ObjectFind(StringConcatenate("sellprof", l_time_20)) > -1) return;
if (ai_0 == 0) {
ls_24 = "buyprof";
li_32 = -1;
} else {
ls_24 = "sellprof";
li_32 = 1;
}
ObjectCreate(StringConcatenate(ls_24, l_time_20), OBJ_ARROW, 0, l_time_20, ad_4 + 2.0 * (li_32 * gd_524) * gd_400);
ObjectSet(StringConcatenate(ls_24, l_time_20), OBJPROP_ARROWCODE, SYMBOL_THUMBSUP);
ObjectSet(StringConcatenate(ls_24, l_time_20), OBJPROP_WIDTH, arrowSize);
ObjectSet(StringConcatenate(ls_24, l_time_20), OBJPROP_COLOR, Green);
}
void deleteObjects() {
string lsa_0[1];
int l_index_4;
int l_objs_total_8;
string l_name_12;
if (infoText) {
l_index_4 = 0;
l_objs_total_8 = ObjectsTotal();
ArrayResize(lsa_0, l_objs_total_8);
for (int li_20 = 0; li_20 < l_objs_total_8; li_20++) {
l_name_12 = ObjectName(li_20);
if (StringFind(l_name_12, "buy") >= 0 || StringFind(l_name_12, "sell") >= 0) {
lsa_0[l_index_4] = l_name_12;
l_index_4++;
}
}
for (li_20 = 0; li_20 < l_index_4; li_20++) ObjectDelete(lsa_0[li_20]);
}
}
bool signalDuringNewsWindow(int ai_0, int ai_4) {
int li_12;
int li_16;
int li_20;
if (!avoidNews) return (FALSE);
for (int l_index_8 = 0; l_index_8 < 500; l_index_8++) {
li_12 = gia_856[l_index_8];
if (li_12 == 0) return (FALSE);
li_16 = li_12 - 60 * minutesBeforeNews;
li_20 = li_12 + 60 * minutesAfterNews;
showDebug("signal time=" + TimeToStr(ai_0) + ", newstime=" + TimeToStr(li_12) + ", ws=" + TimeToStr(li_16) + ", we=" + TimeToStr(li_20), ai_4);
if (ai_0 >= li_16 && ai_0 <= li_20) {
showDebug("returning true", ai_4);
return (TRUE);
}
}
return (FALSE);
}
void showDebug(string as_0, int ai_8) {
if (gi_320) {
if (gi_332 != 0) g_shift_324 = iBarShift(Symbol(), 0, gi_332);
if (gi_336 != 0) g_shift_328 = iBarShift(Symbol(), 0, gi_336);
if (ai_8 <= g_shift_324 && ai_8 >= g_shift_328) Print(WindowExpertName(), ": ", Symbol(), Period(), " ", TimeToStr(Time[ai_8]), " Bar:", ai_8, " ", as_0);
}
}
int start() {
double ld_48;
int li_56;
int li_60;
double ld_68;
int l_shift_76;
double ld_84;
string l_str_concat_92;
double ld_100;
double ld_108;
int li_unused_116;
string l_time2str_124;
string l_time2str_132;
int li_unused_140;
if (ObjectFind(g_str_concat_500) < 0) {
ObjectCreate(g_str_concat_500, OBJ_LABEL, 0, 0, 0);
ObjectSet(g_str_concat_500, OBJPROP_CORNER, 3);
ObjectSet(g_str_concat_500, OBJPROP_XDISTANCE, 10);
ObjectSet(g_str_concat_500, OBJPROP_YDISTANCE, 5);
ObjectSetText(g_str_concat_500, StringConcatenate(gs_v007_76, " ", gs_452), 8, "Gungsuh", FireBrick);
}
if (ObjectFind(g_str_concat_508) < 0) {
ObjectCreate(g_str_concat_508, OBJ_LABEL, 0, 0, 0);
ObjectSet(g_str_concat_508, OBJPROP_CORNER, 3);
ObjectSet(g_str_concat_508, OBJPROP_XDISTANCE, 10);
ObjectSet(g_str_concat_508, OBJPROP_YDISTANCE, 20);
ObjectSetText(g_str_concat_508, StringConcatenate(gs_460, " (" + TimeToStr(gi_472, TIME_DATE), "): waiting for tick"), 8, "Gungsuh", Blue);
}
/*
if (TimeLocal() >= gi_476 && gi_476 > 0) {
ObjectSetText(g_str_concat_508, StringConcatenate(gs_460, ": Indicator trial period has expired"), 8, "Gungsuh", Blue);
return (0);
}
*/
int li_8 = IndicatorCounted();
if (li_8 < 0) return (-1);
if (li_8 > 0) li_8--;
int l_bars_0 = Bars;
double ld_12 = (WindowPriceMax() - WindowPriceMin()) / gd_400;
gd_524 = 3.0 * ld_12 / 125.0;
if (!IsDllsAllowed()) {
ObjectSetText(g_str_concat_508, StringConcatenate(gs_460, " (" + TimeToStr(gi_472, TIME_DATE), "): please allow DLL imports"), 8, "Gungsuh", Blue);
return (0);
}
int l_str2time_20 = StrToTime(TimeToStr(Time[0], TIME_MINUTES));
int l_str2time_24 = StrToTime(TimeToStr(TimeCurrent(), TIME_MINUTES));
if (!gi_544) ObjectSetText(g_str_concat_508, StringConcatenate(gs_460, " (" + TimeToStr(gi_472, TIME_DATE), "): active"), 8, "Gungsuh", Blue);
gi_544 = FALSE;
if (g_str2time_484 == l_str2time_20) return (0);
g_str2time_484 = l_str2time_20;
if (avoidNews) {
if (!getNewsTimes())
if (stopIfNewsFails) Print("Error accessing news");
for (int l_index_28 = 0; l_index_28 < 500; l_index_28++)
if (gia_856[l_index_28] == 0) break;
}
for (int l_index_4 = 0; l_index_4 < l_bars_0; l_index_4++) {
g_ibuf_424[l_index_4] = 0.0;
g_ibuf_428[l_index_4] = 0.0;
g_ibuf_432[l_index_4] = 0.0;
g_ibuf_440[l_index_4] = 0.0;
g_ibuf_436[l_index_4] = 0.0;
g_ibuf_444[l_index_4] = 0.0;
g_ibuf_448[l_index_4] = 0.0;
}
deleteObjects();
bool li_32 = FALSE;
bool li_36 = FALSE;
bool li_40 = FALSE;
bool li_44 = FALSE;
for (int l_bars_64 = l_bars_0; l_bars_64 >= 0; l_bars_64--) {
g_ibuf_424[l_bars_64] = iMA(Symbol(), 0, g_period_340, 0, g_ma_method_344, g_applied_price_348, l_bars_64);
g_ibuf_428[l_bars_64] = iMA(Symbol(), 0, g_period_352, 0, g_ma_method_356, g_applied_price_360, l_bars_64);
g_ibuf_432[l_bars_64] = iMA(Symbol(), 0, g_period_364, 0, g_ma_method_368, g_applied_price_372, l_bars_64);
g_ibuf_440[l_bars_64] = iMA(Symbol(), 0, g_period_376, 0, g_ma_method_380, g_applied_price_384, l_bars_64);
g_ibuf_436[l_bars_64] = iMA(Symbol(), 0, g_period_388, 0, g_ma_method_392, g_applied_price_396, l_bars_64);
if (l_bars_64 >= gi_316) {
showDebug("chb=" + g_ibuf_424[l_bars_64] + ", clb=" + g_ibuf_428[l_bars_64] + ", close=" + Close[l_bars_64] + ", bsig=" + li_32 + ", ssig=" + li_36 + ", slowma=" +
g_ibuf_432[l_bars_64] + ", mediumMA=" + g_ibuf_440[l_bars_64] + ", fastMA=" + g_ibuf_436[l_bars_64], l_bars_64);
ld_68 = g_ibuf_424[l_bars_64] + channelTolerancePips * gd_400;
if (Close[l_bars_64] > ld_68 && !li_32) {
showDebug("Buy crossover found", l_bars_64);
if (g_ibuf_436[l_bars_64] >= g_ibuf_440[l_bars_64] && g_ibuf_440[l_bars_64] >= g_ibuf_432[l_bars_64] && g_ibuf_436[l_bars_64] >= g_ibuf_432[l_bars_64]) {
showDebug("Buy MAs ok", l_bars_64);
if (nextBRNOk(0, Open[l_bars_64 - 1], l_bars_64)) {
showDebug("Next BRN ok", l_bars_64);
gi_532 = TRUE;
gi_496 = getXTime(0, l_bars_64 - 1);
if (waitForNewCrossoverAtDaySt) {
g_str2time_492 = StrToTime(StringConcatenate(TimeToStr(Time[l_bars_64], TIME_DATE), " ", DayStServerHHMM));
if (gi_496 < g_str2time_492) {
showDebug("setting signalCurrent=false due lastX < DaySt", l_bars_64);
gi_532 = FALSE;
}
}
if (signalDuringNewsWindow(Time[l_bars_64], l_bars_64)) {
showDebug("setting signalCurrent=false due news window", l_bars_64);
gi_532 = FALSE;
}
l_shift_76 = iBarShift(Symbol(), 0, gi_496);
showDebug("lastXBar=" + l_shift_76, l_bars_64);
if (gi_532) {
for (int li_80 = l_shift_76 - 1; li_80 > l_bars_64; li_80--) {
ld_68 = g_ibuf_424[li_80] + channelTolerancePips * gd_400;
if (Close[li_80] > ld_68) {
if (!nextBRNOk(0, Open[li_80 - 1], l_bars_64)) {
showDebug("setting signalCurrent=false due BRN on bar " + li_80, l_bars_64);
gi_532 = FALSE;
break;
}
if (signalDuringNewsWindow(Time[li_80], l_bars_64)) {
showDebug("setting signalCurrent=false due news window", l_bars_64);
gi_532 = FALSE;
break;
}
}
}
}
if (li_36) {
if (!gi_144) gi_532 = FALSE;
else {
if (gi_148) {
showDebug("Last entry was a sell", l_bars_64);
if (Open[l_bars_64] > ld_48) createThumbsDown(1, g_price_580, li_56 + 1, l_bars_64);
else createThumbsUp(1, g_price_580, li_56 + 1, l_bars_64);
}
}
}
if (gi_532) {
showDebug("Buy Signal", l_bars_64);
li_32 = TRUE;
li_36 = FALSE;
li_40 = TRUE;
li_44 = FALSE;
ld_48 = NormalizeDouble(Open[l_bars_64 - 1], gi_416);
li_56 = l_bars_64 - 1;
li_60 = Time[li_56];
ld_84 = getStartPos(0, g_ibuf_428[l_bars_64], l_bars_64);
g_ibuf_444[l_bars_64] = ld_84;
if (infoText) {
g_price_580 = ld_84 - 1.5 * gd_524 * gd_400;
g_price_588 = g_price_580 - gd_524 * gd_400;
g_price_596 = g_price_588 - gd_524 * gd_400;
ObjectCreate(StringConcatenate("buyep", Time[l_bars_64]), OBJ_TEXT, 0, Time[l_bars_64], g_price_580);
ObjectSetText(StringConcatenate("buyep", Time[l_bars_64]), StringConcatenate("EP=", DoubleToStr(ld_48, gi_416)), 8, "Ariel", buyTextColor);
ObjectCreate(StringConcatenate("buysl", Time[l_bars_64]), OBJ_TEXT, 0, Time[l_bars_64], g_price_588);
ObjectSetText(StringConcatenate("buysl", Time[l_bars_64]), StringConcatenate("SL=", DoubleToStr(ld_48 - openSignalLoss * gd_400, gi_416)), 8, "Ariel", buyTextColor);
ObjectCreate(StringConcatenate("buytp", Time[l_bars_64]), OBJ_TEXT, 0, Time[l_bars_64], g_price_596);
ObjectSetText(StringConcatenate("buytp", Time[l_bars_64]), StringConcatenate("TP=", DoubleToStr(ld_48 + openSignalProfit * gd_400, gi_416)), 8, "Ariel", buyTextColor);
}
if (gi_420 != Time[l_bars_64] && l_bars_64 == gi_316) {
l_str_concat_92 = StringConcatenate(" (EP=", DoubleToStr(ld_48, gi_416), ", SL=", DoubleToStr(ld_48 - openSignalLoss * gd_400, gi_416), ", TP=", DoubleToStr(ld_48 +
openSignalProfit * gd_400, gi_416), ")");
if (screen_alert) Alert(StringConcatenate(WindowExpertName(), " (", Symbol(), "): price has closed above channel and EMAs are correctly positioned ", l_str_concat_92));
if (email_alert) SendMail(StringConcatenate(WindowExpertName(), " (", Symbol(), ") BUY..."), StringConcatenate("...has been signalled ", l_str_concat_92));
gi_420 = Time[l_bars_64];
}
}
}
}
}
ld_68 = g_ibuf_428[l_bars_64] - channelTolerancePips * gd_400;
if (Close[l_bars_64] < ld_68 && !li_36) {
showDebug("Sell crossover found", l_bars_64);
if (g_ibuf_436[l_bars_64] <= g_ibuf_440[l_bars_64] && g_ibuf_440[l_bars_64] <= g_ibuf_432[l_bars_64] && g_ibuf_436[l_bars_64] <= g_ibuf_432[l_bars_64]) {
showDebug("Sell MAs ok", l_bars_64);
if (nextBRNOk(1, Open[l_bars_64 - 1], l_bars_64)) {
showDebug("Next BRN ok", l_bars_64);
gi_532 = TRUE;
gi_496 = getXTime(1, l_bars_64 - 1);
if (waitForNewCrossoverAtDaySt) {
g_str2time_492 = StrToTime(StringConcatenate(TimeToStr(Time[l_bars_64], TIME_DATE), " ", DayStServerHHMM));
if (gi_496 < g_str2time_492) gi_532 = FALSE;
}
if (signalDuringNewsWindow(Time[l_bars_64], l_bars_64)) {
showDebug("setting signalCurrent=false", l_bars_64);
gi_532 = FALSE;
}
l_shift_76 = iBarShift(Symbol(), 0, gi_496);
showDebug("lastXBar=" + l_shift_76, l_bars_64);
if (gi_532) {
for (li_80 = l_shift_76 - 1; li_80 > l_bars_64; li_80--) {
ld_68 = g_ibuf_428[li_80] - channelTolerancePips * gd_400;
if (Close[li_80] < ld_68) {
if (!nextBRNOk(1, Open[li_80 - 1], l_bars_64)) {
gi_532 = FALSE;
break;
}
if (signalDuringNewsWindow(Time[li_80], l_bars_64)) {
gi_532 = FALSE;
break;
}
}
}
}
if (li_32) {
if (!gi_144) gi_532 = FALSE;
else {
if (gi_148) {
showDebug("Last entry was a buy", l_bars_64);
if (Open[l_bars_64] < ld_48) createThumbsDown(0, g_price_596, li_56 + 1, l_bars_64);
else createThumbsUp(0, g_price_596, li_56 + 1, l_bars_64);
}
}
}
if (gi_532) {
showDebug("Sell Signal", l_bars_64);
li_36 = TRUE;
li_32 = FALSE;
li_40 = FALSE;
li_44 = TRUE;
ld_48 = NormalizeDouble(Open[l_bars_64 - 1], gi_416);
li_56 = l_bars_64 - 1;
li_60 = Time[li_56];
ld_84 = getStartPos(1, g_ibuf_424[l_bars_64], l_bars_64);
showDebug("displayStart=" + ld_84, l_bars_64);
g_ibuf_448[l_bars_64] = ld_84;
if (infoText) {
g_price_596 = ld_84 + 2.5 * gd_524 * gd_400;
g_price_588 = g_price_596 + gd_524 * gd_400;
g_price_580 = g_price_588 + gd_524 * gd_400;
ObjectCreate(StringConcatenate("sellep", Time[l_bars_64]), OBJ_TEXT, 0, Time[l_bars_64], g_price_580);
ObjectSetText(StringConcatenate("sellep", Time[l_bars_64]), StringConcatenate("EP=", DoubleToStr(ld_48, gi_416)), 8, "Ariel", sellTextColor);
ObjectCreate(StringConcatenate("sellsl", Time[l_bars_64]), OBJ_TEXT, 0, Time[l_bars_64], g_price_588);
ObjectSetText(StringConcatenate("sellsl", Time[l_bars_64]), StringConcatenate("SL=", DoubleToStr(ld_48 + openSignalLoss * gd_400, gi_416)), 8, "Ariel", sellTextColor);
ObjectCreate(StringConcatenate("selltp", Time[l_bars_64]), OBJ_TEXT, 0, Time[l_bars_64], g_price_596);
ObjectSetText(StringConcatenate("selltp", Time[l_bars_64]), StringConcatenate("TP=", DoubleToStr(ld_48 - openSignalProfit * gd_400, gi_416)), 8, "Ariel", sellTextColor);
}
if (gi_420 != Time[l_bars_64] && l_bars_64 == gi_316) {
l_str_concat_92 = StringConcatenate(" (EP=", DoubleToStr(ld_48, gi_416), ", SL=", DoubleToStr(ld_48 + openSignalLoss * gd_400, gi_416), ", TP=", DoubleToStr(ld_48 - openSignalProfit * gd_400, gi_416), ")");
if (screen_alert) Alert(StringConcatenate(WindowExpertName(), " (", Symbol(), "): price has closed below channel and EMAs are correctly positioned ", l_str_concat_92));
if (email_alert) SendMail(StringConcatenate(WindowExpertName(), " (", Symbol(), ") SELL..."), StringConcatenate("...has been signalled ", l_str_concat_92));
gi_420 = Time[l_bars_64];
}
}
}
}
}
ld_100 = 0;
ld_108 = 0;
li_unused_116 = -1;
for (int li_120 = li_56; li_120 >= l_bars_64; li_120--) {
ld_100 = (High[li_120] - ld_48) / gd_400;
ld_108 = (ld_48 - Low[li_120]) / gd_400;
if (li_32) {
if (ld_108 >= openSignalLoss || ld_100 >= openSignalProfit) {
li_unused_116 = li_120;
break;
}
}
if (li_36) {
if (ld_100 >= openSignalLoss || ld_108 >= openSignalProfit) {
li_unused_116 = li_120;
break;
}
}
}
calculateProfits(li_56, ld_48, l_bars_64);
l_time2str_124 = TimeToStr(Time[l_bars_64 - 1], TIME_DATE);
if (l_bars_64 == 0) l_time2str_124 = TimeToStr(Time[l_bars_64], TIME_DATE);
l_time2str_132 = TimeToStr(li_60, TIME_DATE);
if (cancelOpenSignalAtEoD) {
if (l_time2str_124 != l_time2str_132) {
showDebug(" current day=" + l_time2str_124 + ", last signal day=" + l_time2str_132, l_bars_64);
li_36 = FALSE;
li_32 = FALSE;
if (showTradeLevels && removeLevelsOnTradeClose) {
li_40 = FALSE;
li_44 = FALSE;
}
if (!(gi_148)) continue;
if (g_ibuf_448[li_56 + 1] != 0.0) {
showDebug("Last entry was a sell", l_bars_64);
if (Open[l_bars_64] > ld_48) createThumbsDown(1, g_price_580, li_56 + 1, l_bars_64);
else createThumbsUp(1, g_price_580, li_56 + 1, l_bars_64);
}
if (g_ibuf_444[li_56 + 1] == 0.0) continue;
showDebug("Last entry was a buy", l_bars_64);
if (Open[l_bars_64] < ld_48) {
createThumbsDown(0, g_price_596, li_56 + 1, l_bars_64);
continue;
}
createThumbsUp(0, g_price_596, li_56 + 1, l_bars_64);
continue;
}
}
li_unused_140 = -1;
if (li_36) {
li_unused_140 = 1;
if (!(g_ibuf_436[l_bars_64] <= g_ibuf_440[l_bars_64] && g_ibuf_440[l_bars_64] <= g_ibuf_432[l_bars_64] && g_ibuf_436[l_bars_64] <= g_ibuf_432[l_bars_64])) {
if (checkOpenSignal) {
showDebug("sellLoss = " + gd_572 + ", sell profit=" + gd_556, l_bars_64);
if (gd_572 >= openSignalLoss || gd_556 >= openSignalProfit) {
showDebug("Sell signal set to false", l_bars_64);
li_36 = FALSE;
}
} else {
li_36 = FALSE;
if (gi_148) {
showDebug("Last entry was a sell", l_bars_64);
if (Open[l_bars_64] > ld_48) createThumbsDown(1, g_price_580, li_56 + 1, l_bars_64);
else createThumbsUp(1, g_price_580, li_56 + 1, l_bars_64);
}
}
}
if (gi_148) {
if (gd_572 >= openSignalLoss) createThumbsDown(1, g_price_580, li_56 + 1, l_bars_64);
if (gd_556 >= openSignalProfit) createThumbsUp(1, g_price_580, li_56 + 1, l_bars_64);
}
}
if (li_32) {
li_unused_140 = 0;
if (!(g_ibuf_436[l_bars_64] >= g_ibuf_440[l_bars_64] && g_ibuf_440[l_bars_64] >= g_ibuf_432[l_bars_64] && g_ibuf_436[l_bars_64] >= g_ibuf_432[l_bars_64])) {
showDebug("fma=" + g_ibuf_436[l_bars_64] + ", mma=" + g_ibuf_440[l_bars_64] + ", sma=" + g_ibuf_432[l_bars_64] + ", checkOpenSignal=" + checkOpenSignal, l_bars_64);
if (checkOpenSignal) {
showDebug("buyLoss = " + gd_564 + ", buy profit=" + gd_548, l_bars_64);
if (gd_564 >= openSignalLoss || gd_548 >= openSignalProfit) {
showDebug("Buy signal set to false", l_bars_64);
li_32 = FALSE;
}
} else {
li_32 = FALSE;
if (gi_148) {
showDebug("Last entry was a buy", l_bars_64);
if (Open[l_bars_64] < ld_48) createThumbsDown(0, g_price_596, li_56 + 1, l_bars_64);
else createThumbsUp(0, g_price_596, li_56 + 1, l_bars_64);
}
}
}
if (gi_148) {
if (gd_564 >= openSignalLoss) createThumbsDown(0, g_price_596, li_56 + 1, l_bars_64);
if (gd_548 >= openSignalProfit) createThumbsUp(0, g_price_596, li_56 + 1, l_bars_64);
}
}
}
}
double ld_144 = MathAbs(g_ibuf_424[0] - g_ibuf_424[1]) / gd_400;
double ld_152 = MathAbs(g_ibuf_424[1] - g_ibuf_424[2]) / gd_400;
if (ld_144 > 10.0) {
Print(">>>>>>>> Large difference test 1<<<<<<<<");
Print("time=", TimeToStr(TimeCurrent()), ": test diff > 5 pips; 0 val=", DoubleToStr(g_ibuf_424[0], Digits), ", 1 val=", DoubleToStr(g_ibuf_424[1], Digits), 0);
Print("time=", TimeToStr(TimeCurrent()), ": OHLC[0]=", Open[0], ", ", High[0], ", ", Low[0], ", ", Close[0]);
Print("time=", TimeToStr(TimeCurrent()), ": OHLC[1]=", Open[1], ", ", High[1], ", ", Low[1], ", ", Close[1]);
}
if (ld_152 > 10.0) {
Print(">>>>>>>> Large difference test 2<<<<<<<<");
Print("time=", TimeToStr(TimeCurrent()), ": test2 diff > 5 pips; 1 val=", DoubleToStr(g_ibuf_424[1], Digits), ", 2 val=", DoubleToStr(g_ibuf_424[2], Digits), 0);
Print("time=", TimeToStr(TimeCurrent()), ": OHLC[1]=", Open[1], ", ", High[1], ", ", Low[1], ", ", Close[1]);
Print("time=", TimeToStr(TimeCurrent()), ": OHLC[2]=", Open[2], ", ", High[2], ", ", Low[2], ", ", Close[2]);
}
if (g_ibuf_424[0] == EMPTY_VALUE || g_ibuf_424[0] == 0.0 || g_ibuf_428[0] == EMPTY_VALUE || g_ibuf_428[0] == 0.0 || g_ibuf_436[0] == EMPTY_VALUE || g_ibuf_436[0] == 0.0 ||
g_ibuf_440[0] == EMPTY_VALUE || g_ibuf_440[0] == 0.0 || g_ibuf_432[0] == EMPTY_VALUE || g_ibuf_432[0] == 0.0) {
Print(">>>>>>>> Indicator buffer 0 empty <<<<<<<<");
Print("time=", TimeToStr(TimeCurrent()), ": OHLC[1]=", Open[1], ", ", High[1], ", ", Low[1], ", ", Close[1]);
Print("time=", TimeToStr(TimeCurrent()), ": OHLC[2]=", Open[2], ", ", High[2], ", ", Low[2], ", ", Close[2]);
}
if (g_ibuf_424[1] == EMPTY_VALUE || g_ibuf_424[1] == 0.0 || g_ibuf_428[1] == EMPTY_VALUE || g_ibuf_428[1] == 0.0 || g_ibuf_436[1] == EMPTY_VALUE || g_ibuf_436[1] == 0.0 ||
g_ibuf_440[1] == EMPTY_VALUE || g_ibuf_440[1] == 0.0 || g_ibuf_432[1] == EMPTY_VALUE || g_ibuf_432[1] == 0.0) {
Print(">>>>>>>> Indicator buffer 1 empty <<<<<<<<");
Print("time=", TimeToStr(TimeCurrent()), ": OHLC[1]=", Open[1], ", ", High[1], ", ", Low[1], ", ", Close[1]);
Print("time=", TimeToStr(TimeCurrent()), ": OHLC[2]=", Open[2], ", ", High[2], ", ", Low[2], ", ", Close[2]);
}
calculateProfits(li_56, ld_48, 0);
if ((li_40 && gd_564 < openSignalLoss && gd_548 < openSignalProfit) || (li_40 && !removeLevelsOnTradeClose)) {
if (showTradeLevels) {
createLines(ld_48, ld_48 - openSignalLoss * gd_400, ld_48 + openSignalProfit * gd_400, 0);
gi_536 = TRUE;
}
}
if ((li_44 && gd_572 < openSignalLoss && gd_556 < openSignalProfit) || (li_44 && !removeLevelsOnTradeClose)) {
if (showTradeLevels) {
createLines(ld_48, ld_48 + openSignalLoss * gd_400, ld_48 - openSignalProfit * gd_400, 0);
gi_540 = TRUE;
}
}
if (removeLevelsOnTradeClose) {
if (gi_536 && gd_564 >= openSignalLoss || gd_548 >= openSignalProfit) {
showDebug("bs but limits reached: About to deleteLines", 0);
deleteLines(0);
gi_536 = FALSE;
}
if (gi_540 && gd_572 >= openSignalLoss || gd_556 >= openSignalProfit) {
showDebug("ss but limits reached: About to deleteLines", 0);
deleteLines(0);
gi_540 = FALSE;
}
if (cancelOpenSignalAtEoD) {
showDebug(" current day=" + l_time2str_124 + ", last signal day=" + l_time2str_132, l_bars_64);
l_time2str_124 = TimeToStr(Time[0], TIME_DATE);
l_time2str_132 = TimeToStr(li_60, TIME_DATE);
if (l_time2str_124 != l_time2str_132) {
if (ObjectFind("eline") > -1) {
showDebug("delete lines at EOD", 0);
deleteLines(0);
}
}
}
}
return (0);
}