#property copyright "Copyright © 2009, FX Tool Lab." #property link "http://www.investtoollab.com/fx" #include #import "pair01.dll" string ExchangeRate1(string a0, string a1, string a2); #import string gs_76 = "PAIR01_121UJ01"; string gs_84 = "PAIR01_121UJ01"; int gi_92 = 1; string gs_96 = "121 Lab Co., Ltd"; string gs_usdjpy_104 = "USDJPY"; bool gi_112 = FALSE; double gd_116 = 0.1; bool gi_124 = TRUE; int gi_128 = 50; int gi_132 = 0; int gi_136 = 0; double gd_140 = 0.2; int gi_148 = 3; bool gi_152 = TRUE; bool gi_156 = TRUE; bool gi_160 = TRUE; int gi_164 = 60; bool gi_168 = TRUE; bool gi_unused_172 = TRUE; int gi_unused_176 = 30; string gs_180 = "07:00-24:00"; string gs_188 = "00:00-01:00"; string gs_196 = "12:00-12:00"; bool gi_204 = TRUE; int gi_208 = 0; int gi_212 = 10; int gi_216 = 10; int gi_220 = 1; int gi_unused_224 = 1000; string gs_228 = "C:\\pairpra1.txt"; string gs_236 = "C:\\pairpra2.txt"; bool gi_244 = TRUE; bool gi_248 = TRUE; bool gi_252 = TRUE; int gi_256 = 4; int gi_260 = 100; int gi_264 = 1; int gi_268 = 5; int gi_272 = 1; double gd_276 = 7.0; double gd_284 = 6.0; double gd_292 = 7.0; double gd_300 = 6.0; double gd_308 = 5.0; double gd_316 = 4.0; double gd_324 = 5.0; double gd_332 = 4.0; double gd_340 = 5.0; double gd_348 = 3.0; double gd_356 = 5.0; double gd_364 = 3.0; double gd_372 = 4.0; double gd_380 = 3.0; double gd_388 = 4.0; double gd_396 = 3.0; double gd_404 = 3.0; double ts_0 = 2.0; double gd_420 = 3.0; double gd_428 = 2.0; double gd_436 = 5.0; double gd_444 = 4.0; double gd_452 = 5.0; double gd_460 = 4.0; double gd_468 = 5.0; double gd_476 = 4.0; double gd_484 = 5.0; double gd_492 = 4.0; double gd_500 = 5.0; double gd_508 = 4.0; double gd_516 = 5.0; double gd_524 = 4.0; double gd_532 = 6.0; double gd_540 = 5.0; double gd_548 = 6.0; double gd_556 = 5.0; double gd_564 = 7.0; double gd_572 = 6.0; double gd_580 = 7.0; double gd_588 = 6.0; int gi_596 = 10; int gi_600 = 10; int gi_604 = 10; int gi_608 = 10; int gi_612 = 10; int gi_616 = 10; int gi_620 = 10; int gi_624 = 10; int gi_628 = 10; int gi_632 = 10; int gi_636 = 10; int gi_640 = 10; int gi_644 = 10; int gi_648 = 10; int gi_652 = 10; int gi_656 = 10; int gi_660 = 10; int gi_664 = 10; int gi_668 = 10; int gi_672 = 10; int gi_676 = 10; int gi_680 = 10; int gi_684 = 10; int gi_688 = 10; int gi_692 = 10; int gi_696 = 10; int gi_700 = 10; int gi_704 = 10; int gi_708 = 10; int gi_712 = 10; int gi_716 = 10; int gi_720 = 10; int gi_724 = 10; int gi_728 = 10; int gi_732 = 10; int gi_736 = 10; int gi_740 = 10; int gi_744 = 10; int gi_748 = 10; int gi_752 = 10; string gs_756 = "PAIR01_121UJ01"; int gi_764 = D'01.10.2009 04:29'; int gi_768; int gi_772; int g_count_776; int g_count_780; int g_count_784; int g_count_788; int g_count_792; int g_count_796; int g_ticket_800 = 0; int g_ticket_804 = 0; int g_datetime_808 = 0; int g_datetime_812 = 0; int g_datetime_816 = 0; int g_datetime_820 = 0; int g_datetime_824 = 0; int g_datetime_828 = 0; int gi_unused_832 = 0; int gi_unused_836 = 0; bool gi_840 = FALSE; double gd_844 = 0.0; int gi_852 = 1; bool gi_856 = TRUE; int gi_860 = 0; double gd_864 = 0.0; int gi_872 = 1; int g_file_876 = 0; int g_file_880 = 0; int g_file_884 = 0; int g_file_888 = 0; string g_name_892; bool gi_unused_900 = FALSE; int gi_unused_904 = 0; int gi_908 = 0; int gi_912 = 0; bool gi_916 = FALSE; bool gi_920 = FALSE; bool gi_924 = FALSE; int g_datetime_928 = 0; int g_datetime_932 = 0; int g_datetime_936 = 0; int g_datetime_940 = 0; int g_datetime_944 = 0; int g_datetime_948 = 0; bool gi_952 = FALSE; double g_bid_956 = 0.0; int g_datetime_964 = 0; double gd_968 = 0.0; double gd_976 = 0.0; double gd_984 = 0.0; double g_minlot_992 = 0.0; int gi_1000 = 0; int gi_1004 = 0; int g_count_1008 = 0; int g_count_1012 = 0; int gi_1016 = 19; int gia_1020[20]; int gia_1024[20]; int gia_1028[20]; int gia_1032[20]; int gia_1036[20]; int gia_1040[20]; int gi_unused_1044; int gi_unused_1048; int gia_1052[3][2]; int gia_1056[3][2]; bool gi_1060; int gi_1064 = 9; double gda_1068[10]; double gda_1072[10]; double gda_1076[10]; double gda_1080[10]; int gia_1084[10]; int gia_1088[10]; int gia_1092[10]; int gia_1096[10]; int gia_1100[10]; int gia_1104[10]; int gia_1108[10]; int gia_1112[10]; int gia_1116[10]; int gia_1120[10]; double gda_1124[10]; double gda_1128[10]; int init() { int li_0 = init_common(); return (0); } int start() { int li_0 = start_common(); return (0); } int deinit() { int li_0 = deinit_common(); return (0); } int init_common() { int l_error_0; int l_mb_code_8; double ld_60; string l_dbl2str_68; int li_80; double ld_96; double ld_104; double ld_112; double ld_120; double ld_128; double ld_136; string lsa_144[3]; string lsa_148[3]; bool li_156; string ls_160; int l_acc_number_168; int l_acc_number_172; int l_acc_number_176; int l_acc_number_180; int l_acc_number_184; int l_acc_number_188; int l_acc_number_192; int l_acc_number_196; int l_acc_number_200; int l_acc_number_204; int l_acc_number_208; int l_acc_number_212; int l_acc_number_216; int l_acc_number_220; gi_852 = TRUE; int l_count_4 = 0; if (!GlobalVariableCheck("ThreadBusy_SEM")) GlobalVariableSet("ThreadBusy_SEM", 0); if (TimeLocal() > gi_764) { Print("Error (ExpireDate : ", gi_764, " 000 ", "Script Expired", ")"); l_mb_code_8 = MessageBox("Error! [Script doesnt work!!] (ExpireDate : " + TimeToStr(gi_764, TIME_DATE) + ") (errcode : 000) (description : EA Expired. )", "Error Message", 0); l_mb_code_8 = MessageBox("Please access <<< http://www.investtoollab.com/u/emtic001_expired.htm >>> for user support.", "Error Message", 0); l_count_4++; return (0); } if (gs_96 != "" && AccountCompany() != gs_96) { Print("Error (AccountCompany() : ", AccountCompany(), " 000 ", "AccountCompany Must Be ", gs_96, ")"); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (AccountCompany() : " + AccountCompany() + ") (errcode : 000) (description : AccountCompany Must Be " + gs_96 + ". )", "Error Message", 0); l_count_4++; return (0); } if (gs_usdjpy_104 != "" && StringSubstr(Symbol(), 0, 6) != gs_usdjpy_104) { Print("Error (Symbol() : ", Symbol(), " 000 ", "Symbol Must Be ", gs_usdjpy_104, ")"); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (Symbol() : " + Symbol() + ") (errcode : 000) (description : Symbol Must Be " + gs_usdjpy_104 + ". )", "Error Message", 0); l_count_4++; return (0); } if (gi_112 == TRUE && IsDemo() == FALSE) { Print("Error (IsDemo() : ", IsDemo(), " 000 ", "Account Must Be Demo Account)"); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (IsDemo() : " + IsDemo() + ") (errcode : 000) (description : Account Must Be Demo Account)", "Error Message", 0); l_count_4++; return (0); } gi_856 = TRUE; gi_860 = 0; gd_864 = 0; gi_872 = 1; g_minlot_992 = MarketInfo(Symbol(), MODE_MINLOT); if (AccountCompany() == "ODL Securities") { gi_856 = FALSE; gi_860 = 9; l_acc_number_168 = AccountNumber(); if (l_acc_number_168 == 21732) gd_864 = 0; } if (AccountCompany() == "FXDirectDealer") { if (StringSubstr(Symbol(), 6, 1) == "x") g_minlot_992 = 0.01; gi_856 = FALSE; gi_860 = 6; l_acc_number_172 = AccountNumber(); if (l_acc_number_172 == 517692) gd_864 = 1; } if (AccountCompany() == "Alpari (UK) Ltd.") { gi_856 = FALSE; gi_860 = 7; gi_872 = 10; l_acc_number_176 = AccountNumber(); if (l_acc_number_176 == 517692) gd_864 = 0; } if (AccountCompany() == "Interbank FX, LLC") { gi_856 = FALSE; gi_860 = 9; gi_872 = 10; l_acc_number_180 = AccountNumber(); if (l_acc_number_180 == 517692) gd_864 = 0; } if (AccountCompany() == "MIG Investments SA") { gi_856 = FALSE; gi_860 = 7; l_acc_number_184 = AccountNumber(); if (l_acc_number_184 == 517692) gd_864 = 0; } if (AccountCompany() == "BroCo Investments Inc.") { gi_856 = FALSE; gi_860 = 7; l_acc_number_188 = AccountNumber(); if (l_acc_number_188 == 66189) gd_864 = 10; } if (AccountCompany() == "Crown Forex SA") { gi_856 = FALSE; gi_860 = 9; l_acc_number_192 = AccountNumber(); if (l_acc_number_192 == 517692) gd_864 = 0; } if (AccountCompany() == "EuroOrient Securities&Financial Services Ltd") { gi_856 = FALSE; gi_860 = 6; l_acc_number_196 = AccountNumber(); if (l_acc_number_196 == 517692) gd_864 = 0; } if (AccountCompany() == "IKON GM Royal Division") { gi_856 = FALSE; gi_860 = 6; l_acc_number_200 = AccountNumber(); if (l_acc_number_200 == 517692) gd_864 = 0; } if (AccountCompany() == "GCI Financial Ltd.") { gi_856 = FALSE; gi_860 = 13; l_acc_number_204 = AccountNumber(); if (l_acc_number_204 == 517692) gd_864 = 0; } if (AccountCompany() == "FOREX.com") { gi_856 = FALSE; gi_860 = 9; l_acc_number_208 = AccountNumber(); if (l_acc_number_208 == 10260257) gd_864 = 10; } if (AccountCompany() == "Fortune Capital Co. Ltd") { gi_856 = FALSE; gi_860 = 9; l_acc_number_212 = AccountNumber(); if (l_acc_number_212 == 501208) gd_864 = 10; } if (AccountCompany() == "FXCM Liquidity Connection") { gi_856 = FALSE; gi_860 = 8; gi_872 = 10; l_acc_number_216 = AccountNumber(); if (l_acc_number_216 == 501208) gd_864 = 0; } if (AccountCompany() == "121 Lab Co., Ltd") { gi_856 = FALSE; gi_860 = 0; l_acc_number_220 = AccountNumber(); if (l_acc_number_220 == 210121005) gd_864 = 10; } if (gi_856) { Print("Error (AccountCompany() : ", AccountCompany(), " 000 ", "AccountCompany Not Registered", ")"); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (AccountCompany() : " + AccountCompany() + ") (errcode : 000) (description : AccountCompany Not Registered. )", "Error Message", 0); l_count_4++; return (0); } if (IsDemo() == FALSE) gd_864 = gd_116; else gd_864 = D'09.09.2001 06:16:39'; if (gd_140 < MarketInfo(Symbol(), MODE_MINLOT)) gd_140 = MarketInfo(Symbol(), MODE_MINLOT); if (IsTesting()) gi_204 = TRUE; else { if (IsDemo() == FALSE) { if (gi_204 == TRUE && gd_864 < gd_140) gd_140 = gd_864; } else gi_908 = TRUE; } gd_844 = Point * gi_872; string l_name_24 = "EAInitInfo"; if (ObjectFind(l_name_24) == -1) { if (!ObjectCreate(l_name_24, OBJ_TEXT, 0, TimeCurrent(), Bid)) { l_error_0 = GetLastError(); Print("Error (ObjName : ", l_name_24, " ", l_error_0, " Object Not Created - ", ErrorDescription(l_error_0), ")"); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (ObjName : " + l_name_24 + ") (errcode : " + l_error_0 + ") (description : " + ErrorDescription(l_error_0) + ")", "Error Message", 0); l_count_4++; return (0); } gi_208 = TimeLocal(); ObjectSetText(l_name_24, DoubleToStr(gi_208, 0), 1, "", CLR_NONE); l_error_0 = GetLastError(); if (l_error_0 != 0/* NO_ERROR */) { Print("Error (ObjName : ", l_name_24, " ", l_error_0, " Object Not SetText - ", ErrorDescription(l_error_0), ")"); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (ObjName : " + l_name_24 + ") (errcode : " + l_error_0 + ") (description : " + ErrorDescription(l_error_0) + ")", "Error Message", 0); l_count_4++; return (0); } } else { gi_208 = StrToInteger(ObjectDescription(l_name_24)); l_error_0 = GetLastError(); if (l_error_0 != 0/* NO_ERROR */) { Print("Error (ObjName : ", l_name_24, " ", l_error_0, " Object Not Found - ", ErrorDescription(l_error_0), ")"); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (ObjName : " + l_name_24 + ") (errcode : " + l_error_0 + ") (description : " + ErrorDescription(l_error_0) + ")", "Error Message", 0); l_count_4++; return (0); } } Print("Debug Print P_OrderMagicNo = ", gi_208); string l_time2str_224 = TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS); string ls_232 = StringSubstr(l_time2str_224, 0, 4) + StringSubstr(l_time2str_224, 5, 2) + StringSubstr(l_time2str_224, 8, 2) + StringSubstr(l_time2str_224, 11, 2) + StringSubstr(l_time2str_224, 14, 2) + StringSubstr(l_time2str_224, 17, 2); g_file_888 = 0; string ls_240 = "PAIR01ERR" + ls_232 + StringSubstr(Symbol(), 0, 6) + gi_208; g_name_892 = ls_240 + ".txt"; int l_file_56 = FileOpen(g_name_892, FILE_CSV|FILE_READ, 9); if (l_file_56 < 1) g_file_888 = FileOpen(g_name_892, FILE_CSV|FILE_WRITE, 9); else { ld_60 = 0; while (l_file_56 >= 1 && ld_60 < 30.0) { ld_60++; l_dbl2str_68 = DoubleToStr(ld_60, 0); g_name_892 = ls_240 + "_" + l_dbl2str_68 + ".txt"; l_file_56 = FileOpen(g_name_892, FILE_CSV|FILE_READ, 9); } if (l_file_56 < 1) g_file_888 = FileOpen(g_name_892, FILE_CSV|FILE_WRITE, 9); else { Print("Error opening FILE_WRITE (already exists) : ", ls_240); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (FileName : " + ls_240 + ") (errcode : 000) (description : Error opening FILE_WRITE (already exists) )", "Error Message", 0); l_count_4++; return (0); } } if (g_file_888 < 1) { l_error_0 = GetLastError(); Print("Error opening FILE_WRITE (open command error): ", g_name_892, l_error_0); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (FileName : " + g_name_892 + ") (errcode : " + l_error_0 + ") (description : " + ErrorDescription(l_error_0) + ")", "Error Message", 0); l_count_4++; return (0); } g_file_876 = 0; if (gi_248 == TRUE) { ls_240 = "PAIR01TRADE" + ls_232 + StringSubstr(Symbol(), 0, 6) + gi_208; g_name_892 = ls_240 + ".txt"; l_file_56 = FileOpen(g_name_892, FILE_CSV|FILE_READ, 9); if (l_file_56 < 1) g_file_876 = FileOpen(g_name_892, FILE_CSV|FILE_WRITE, 9); else { ld_60 = 0; while (l_file_56 >= 1 && ld_60 < 30.0) { ld_60++; l_dbl2str_68 = DoubleToStr(ld_60, 0); g_name_892 = ls_240 + "_" + l_dbl2str_68 + ".txt"; l_file_56 = FileOpen(g_name_892, FILE_CSV|FILE_READ, 9); } if (l_file_56 < 1) g_file_876 = FileOpen(g_name_892, FILE_CSV|FILE_WRITE, 9); else { Print("Error opening FILE_WRITE (already exists) : ", ls_240); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (FileName : " + ls_240 + ") (errcode : 000) (description : Error opening FILE_WRITE (already exists) )", "Error Message", 0); l_count_4++; return (0); } } if (g_file_876 < 1) { l_error_0 = GetLastError(); Print("Error opening FILE_WRITE (open command error): ", g_name_892, l_error_0); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (FileName : " + g_name_892 + ") (errcode : " + l_error_0 + ") (description : " + ErrorDescription(l_error_0) + ")", "Error Message", 0); l_count_4++; return (0); } } g_file_880 = 0; if (gi_244 == TRUE) { ls_240 = "PAIR01TICK" + ls_232 + StringSubstr(Symbol(), 0, 6) + gi_208; g_name_892 = ls_240 + ".txt"; l_file_56 = FileOpen(g_name_892, FILE_CSV|FILE_READ, 9); if (l_file_56 < 1) g_file_880 = FileOpen(g_name_892, FILE_CSV|FILE_WRITE, 9); else { ld_60 = 0; while (l_file_56 >= 1 && ld_60 < 30.0) { ld_60++; l_dbl2str_68 = DoubleToStr(ld_60, 0); g_name_892 = ls_240 + "_" + l_dbl2str_68 + ".txt"; l_file_56 = FileOpen(g_name_892, FILE_CSV|FILE_READ, 9); } if (l_file_56 < 1) g_file_880 = FileOpen(g_name_892, FILE_CSV|FILE_WRITE, 9); else { Print("Error opening FILE_WRITE (already exists) : ", ls_240); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (FileName : " + ls_240 + ") (errcode : 000) (description : Error opening FILE_WRITE (already exists) )", "Error Message", 0); l_count_4++; return (0); } } if (g_file_880 < 1) { l_error_0 = GetLastError(); Print("Error opening FILE_WRITE (open command error): ", g_name_892, l_error_0); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (FileName : " + g_name_892 + ") (errcode : " + l_error_0 + ") (description : " + ErrorDescription(l_error_0) + ")", "Error Message", 0); l_count_4++; return (0); } } g_file_884 = 0; if (gi_252 == TRUE) { ls_240 = "PAIR01STAT" + ls_232 + StringSubstr(Symbol(), 0, 6) + gi_208; g_name_892 = ls_240 + ".txt"; l_file_56 = FileOpen(g_name_892, FILE_CSV|FILE_READ, 9); if (l_file_56 < 1) g_file_884 = FileOpen(g_name_892, FILE_CSV|FILE_WRITE, 9); else { ld_60 = 0; while (l_file_56 >= 1 && ld_60 < 30.0) { ld_60++; l_dbl2str_68 = DoubleToStr(ld_60, 0); g_name_892 = ls_240 + "_" + l_dbl2str_68 + ".txt"; l_file_56 = FileOpen(g_name_892, FILE_CSV|FILE_READ, 9); } if (l_file_56 < 1) g_file_884 = FileOpen(g_name_892, FILE_CSV|FILE_WRITE, 9); else { Print("Error opening FILE_WRITE (already exists) : ", ls_240); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (FileName : " + ls_240 + ") (errcode : 000) (description : Error opening FILE_WRITE (already exists) )", "Error Message", 0); l_count_4++; return (0); } } if (g_file_884 < 1) { l_error_0 = GetLastError(); Print("Error opening FILE_WRITE (open command error): ", g_name_892, l_error_0); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (FileName : " + g_name_892 + ") (errcode : " + l_error_0 + ") (description : " + ErrorDescription(l_error_0) + ")", "Error Message", 0); l_count_4++; return (0); } } gda_1068[0] = gd_276; gda_1068[1] = gd_308; gda_1068[2] = gd_340; gda_1068[3] = gd_372; gda_1068[4] = gd_404; gda_1068[5] = gd_436; gda_1068[6] = gd_468; gda_1068[7] = gd_500; gda_1068[8] = gd_532; gda_1068[9] = gd_564; gda_1072[0] = gd_284; gda_1072[1] = gd_316; gda_1072[2] = gd_348; gda_1072[3] = gd_380; gda_1072[4] = ts_0; gda_1072[5] = gd_444; gda_1072[6] = gd_476; gda_1072[7] = gd_508; gda_1072[8] = gd_540; gda_1072[9] = gd_572; gda_1076[0] = gd_292; gda_1076[1] = gd_324; gda_1076[2] = gd_356; gda_1076[3] = gd_388; gda_1076[4] = gd_420; gda_1076[5] = gd_452; gda_1076[6] = gd_484; gda_1076[7] = gd_516; gda_1076[8] = gd_548; gda_1076[9] = gd_580; gda_1080[0] = gd_300; gda_1080[1] = gd_332; gda_1080[2] = gd_364; gda_1080[3] = gd_396; gda_1080[4] = gd_428; gda_1080[5] = gd_460; gda_1080[6] = gd_492; gda_1080[7] = gd_524; gda_1080[8] = gd_556; gda_1080[9] = gd_588; gia_1084[0] = gi_596; gia_1084[1] = gi_612; gia_1084[2] = gi_628; gia_1084[3] = gi_644; gia_1084[4] = gi_660; gia_1084[5] = gi_676; gia_1084[6] = gi_692; gia_1084[7] = gi_708; gia_1084[8] = gi_724; gia_1084[9] = gi_740; gia_1088[0] = gi_600; gia_1088[1] = gi_616; gia_1088[2] = gi_632; gia_1088[3] = gi_648; gia_1088[4] = gi_664; gia_1088[5] = gi_680; gia_1088[6] = gi_696; gia_1088[7] = gi_712; gia_1088[8] = gi_728; gia_1088[9] = gi_744; gia_1092[0] = gi_604; gia_1092[1] = gi_620; gia_1092[2] = gi_636; gia_1092[3] = gi_652; gia_1092[4] = gi_668; gia_1092[5] = gi_684; gia_1092[6] = gi_700; gia_1092[7] = gi_716; gia_1092[8] = gi_732; gia_1092[9] = gi_748; gia_1096[0] = gi_608; gia_1096[1] = gi_624; gia_1096[2] = gi_640; gia_1096[3] = gi_656; gia_1096[4] = gi_672; gia_1096[5] = gi_688; gia_1096[6] = gi_704; gia_1096[7] = gi_720; gia_1096[8] = gi_736; gia_1096[9] = gi_752; for (int l_index_76 = 0; l_index_76 <= gi_1064; l_index_76++) { gia_1116[l_index_76] = 0; gia_1120[l_index_76] = 0; gda_1124[l_index_76] = 0; gda_1128[l_index_76] = 0; } int li_unused_84 = 0; double ld_88 = 0; for (l_index_76 = 0; l_index_76 <= gi_256; l_index_76++) { li_80 = gi_208 + 100000000 * l_index_76; OrderCheck2(li_80, Symbol()); if (g_count_776 != 0) { g_ticket_804 = 0; if (g_count_776 == 1) { OrderTicketCheck2(li_80, Symbol(), OP_BUY); if (g_ticket_804 != 0) { if (OrderSelect(g_ticket_804, SELECT_BY_TICKET, MODE_TRADES)) { gia_1116[l_index_76] = 1; gda_1124[l_index_76] = OrderOpenPrice(); ld_88 += OrderLots(); } } } if (g_count_776 != 1 || g_ticket_804 == 0) { Print("Error (OrderMagicNo : ", li_80, " 000 ", " Unknown Buy Position Exists - G_NoOfOpBuy = ", g_count_776, ")"); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (OrderMagicNo : " + li_80 + ") (errcode : 000) (description : Unknown Buy Position Exists - G_NoOfOpBuy = " + g_count_776 + ")", "Error Message", 0); l_count_4++; return (0); } } OrderCheck2(li_80, Symbol()); if (g_count_780 != 0) { g_ticket_804 = 0; if (g_count_780 == 1) { OrderTicketCheck2(li_80, Symbol(), OP_SELL); if (g_ticket_804 != 0) { if (OrderSelect(g_ticket_804, SELECT_BY_TICKET, MODE_TRADES)) { gia_1120[l_index_76] = 1; gda_1128[l_index_76] = OrderOpenPrice(); ld_88 += OrderLots(); } } } if (g_count_780 != 1 || g_ticket_804 == 0) { Print("Error (OrderMagicNo : ", li_80, " 000 ", " Unknown Sell Position Exists - G_NoOfOpBuy = ", g_count_780, ")"); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (OrderMagicNo : " + li_80 + ") (errcode : 000) (description : Unknown Sell Position Exists - G_NoOfOpSell = " + g_count_780 + ")", "Error Message", 0); l_count_4++; return (0); } } } if (gi_128 >= 10 && gi_128 <= 90) { if (AccountStopoutMode() == 0) ld_128 = AccountStopoutLevel() / 100.0; else ld_128 = 1; gd_968 = gi_128 * ld_128 / 100.0; gd_976 = (gi_128 / 2 + 50) * ld_128 / 100.0; gd_984 = (gi_128 / 10 + 90) * ld_128 / 100.0; } else { Print("Error (P_RiskLevel : ", gi_128, " 000 ", " RiskLevel Must Be Between 10 and 90.)"); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (P_RiskLevel : " + gi_128 + ") (errcode : 000) (description : RiskLevel Must Be Between 10 and 90.)", "Error Message", 0); l_count_4++; return (0); } if (gi_124 == TRUE) { ld_96 = MathMax(MathAbs(AccountFreeMargin() - AccountFreeMarginCheck(Symbol(), OP_BUY, MarketInfo(Symbol(), MODE_MINLOT))), MathAbs(AccountFreeMargin() - AccountFreeMarginCheck(Symbol(), OP_SELL, MarketInfo(Symbol(), MODE_MINLOT)))); if (MarketInfo(Symbol(), MODE_MINLOT) == 0.0) Print("Debug Print Zero Divide : MarketInfo(Symbol(), MODE_MINLOT) = ", MarketInfo(Symbol(), MODE_MINLOT)); ld_104 = AccountMargin() - ld_96 * ld_88 / MarketInfo(Symbol(), MODE_MINLOT); ld_112 = AccountEquity() * gd_968; if (MarketInfo(Symbol(), MODE_MINLOT) == g_minlot_992) { if (ld_96 == 0.0 || gi_256 + 1 == 0) Print("Debug Print Zero Divide : MinimumMargin = ", ld_96, " (P_PosArrayIdxMax + 1) = ", gi_256 + 1, " AccountFreeMargin() = ", AccountFreeMargin(), " AccountFreeMarginCheck(Symbol(), OP_BUY, MarketInfo(Symbol(), MODE_MINLOT)) = ", AccountFreeMarginCheck(Symbol(), OP_BUY, MarketInfo(Symbol(), MODE_MINLOT)), " AccountFreeMarginCheck(Symbol(), OP_SELL, MarketInfo(Symbol(), MODE_MINLOT)) = ", AccountFreeMarginCheck(Symbol(), OP_SELL, MarketInfo(Symbol(), MODE_MINLOT))); ld_120 = MathFloor((ld_112 - ld_104) / ld_96 / (gi_256 + 1)) * MarketInfo(Symbol(), MODE_MINLOT); } else { if (g_minlot_992 == 0.0) Print("Debug Print Zero Divide : G_MinimumLotIncrement = ", g_minlot_992); ld_136 = MarketInfo(Symbol(), MODE_MINLOT) / g_minlot_992; if (ld_96 == 0.0 || gi_256 + 1 == 0) Print("Debug Print Zero Divide : MinimumMargin = ", ld_96, " (P_PosArrayIdxMax + 1 = ", gi_256 + 1, " (x = ", ld_136); ld_120 = MathFloor(ld_136 * (ld_112 - ld_104) / ld_96 / (gi_256 + 1)) * MarketInfo(Symbol(), MODE_MINLOT) / ld_136; } if (IsDemo() == FALSE && ld_120 > gd_864) ld_120 = gd_864; if (ld_120 >= MarketInfo(Symbol(), MODE_MINLOT)) gd_140 = ld_120; else { Print("Error (P_AutoLotSize : ", gi_124, " 000 ", " CAN NOT Caluculate LotSize.)"); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (P_AutoLotSize : " + gi_124 + ") (errcode : 000) (description : CAN NOT Caluculate LotSize.)", "Error Message", 0); l_count_4++; return (0); } } int li_20 = MarginLevelCheck(); lsa_144[0] = gs_180; lsa_148[0] = "P_MailTime1"; lsa_144[1] = gs_188; lsa_148[1] = "P_MailTime2"; lsa_144[2] = gs_196; lsa_148[2] = "P_MailTime3"; for (l_index_76 = 0; l_index_76 <= 2; l_index_76++) { if (lsa_144[l_index_76] != "") { li_156 = FALSE; if (StringLen(lsa_144[l_index_76]) != 11) li_156 = TRUE; if (li_156 == FALSE) { for (int li_152 = 0; li_152 <= 10; li_152++) { ls_160 = StringSubstr(lsa_144[l_index_76], li_152, 1); if (li_152 == 0 || li_152 == 1 || li_152 == 3 || li_152 == 4 || li_152 == 6 || li_152 == 7 || li_152 == 9 || li_152 == 10) if (ls_160 < "0" || ls_160 > "9") li_156 = TRUE; if (li_152 == 2 || li_152 == 8) if (ls_160 != ":") li_156 = TRUE; if (li_152 == 5) if (ls_160 != "-") li_156 = TRUE; } } if (li_156 == FALSE) { gia_1052[l_index_76][0] = StrToInteger(StringSubstr(lsa_144[l_index_76], 0, 2)); gia_1056[l_index_76][0] = StrToInteger(StringSubstr(lsa_144[l_index_76], 3, 2)); gia_1052[l_index_76][1] = StrToInteger(StringSubstr(lsa_144[l_index_76], 6, 2)); gia_1056[l_index_76][1] = StrToInteger(StringSubstr(lsa_144[l_index_76], 9, 2)); for (li_152 = 0; li_152 <= 1; li_152++) { if (gia_1052[l_index_76][li_152] < 0 || gia_1052[l_index_76][li_152] > 24 || gia_1056[l_index_76][li_152] < 0 || gia_1056[l_index_76][li_152] > 59 || 60 * gia_1052[l_index_76][li_152] + gia_1056[l_index_76][li_152] > 1440) li_156 = TRUE; } } if (li_156 == FALSE) if (60 * gia_1052[l_index_76][0] + gia_1056[l_index_76][0] > 60 * gia_1052[l_index_76][1] + gia_1056[l_index_76][1]) li_156 = TRUE; if (li_156 == TRUE) { Print("Error (" + lsa_148[l_index_76] + " : ", lsa_144[l_index_76], " 000 ", "Time Format Not HH:MM-HH:MM", ")"); l_mb_code_8 = MessageBox("Error! [EA doesnt work!!] (" + lsa_148[l_index_76] + " : " + lsa_144[l_index_76] + ") (errcode : 000) (description : Time Format Not HH:MM-HH:MM)", "Error Message", 0); l_count_4++; } } else { gia_1052[l_index_76][0] = 0; gia_1056[l_index_76][0] = 0; gia_1052[l_index_76][1] = 0; gia_1056[l_index_76][1] = 0; } } g_bid_956 = Bid; gi_1004 = 0; if (l_count_4 == 0) { gi_852 = FALSE; start(); } return (0); } int start_common() { string ls_unused_8; int l_error_16; int li_20; string ls_24; string ls_32; int li_48; int li_52; bool li_56; string lsa_60[49]; string lsa_64[49]; string ls_72; double l_str2dbl_88; double l_str2dbl_96; int li_104; double ld_108; double ld_116; int li_124; int li_128; int l_minute_132; int li_68 = 48; while (IsStopped() == FALSE) { gi_1060 = FALSE; gi_840 = FALSE; for (int l_index_40 = 0; l_index_40 <= 2; l_index_40++) { li_128 = TimeHour(TimeLocal()); l_minute_132 = TimeMinute(TimeLocal()); if (li_128 > 23) li_128 -= 24; if (60 * gia_1052[l_index_40][0] + gia_1056[l_index_40][0] <= 60 * li_128 + l_minute_132 && 60 * li_128 + l_minute_132 <= 60 * gia_1052[l_index_40][1] + gia_1056[l_index_40][1]) { gi_1060 = TRUE; gi_840 = TRUE; } } if (gi_852 != FALSE) { ls_32 = ExchangeRate1(gs_228, gs_236, " "); ls_72 = "\n"; ls_72 = ls_72 + "Script : " + gs_756 + " Stopped due to ERROR \n"; Comment(ls_72); } else { gi_912 = FALSE; if (IsConnected() == FALSE) { gi_912 = TRUE; ls_32 = ExchangeRate1(gs_228, gs_236, " "); ls_72 = "\n"; ls_72 = ls_72 + "Script : " + gs_756 + " Stopped due to NoConnection \n"; Comment(ls_72); for (l_index_40 = 0; l_index_40 <= gi_256; l_index_40++) { gia_1100[l_index_40] = 0; gia_1108[l_index_40] = 0; gia_1104[l_index_40] = 0; gia_1112[l_index_40] = 0; } if (gi_1060 == TRUE && gi_160 == TRUE && g_datetime_928 + 60 * gi_164 < TimeLocal()) { SendMail("Error_" + gs_76, "Error_NoConnection_" + AccountCompany() + "_" + StringSubstr(Symbol(), 0, 6) + "_" + gi_208 + "_" + gs_84); g_datetime_928 = TimeLocal(); } } else { if (MathAbs(g_bid_956 - Bid) >= 5.0) g_datetime_964 = TimeLocal(); if (g_datetime_964 + 60 * gi_272 > TimeLocal()) { gi_912 = TRUE; ls_32 = ExchangeRate1(gs_228, gs_236, " "); ls_72 = "\n"; ls_72 = ls_72 + "Script : " + gs_756 + " Stopped due to Rapid Price Change \n"; Comment(ls_72); for (l_index_40 = 0; l_index_40 <= gi_256; l_index_40++) { gia_1100[l_index_40] = 0; gia_1108[l_index_40] = 0; gia_1104[l_index_40] = 0; gia_1112[l_index_40] = 0; } } } g_bid_956 = Bid; if (gi_912 == FALSE) { gi_924 = FALSE; if (MathAbs(TimeLocal() - TimeCurrent() - 60 * (60 * gi_860)) >= gi_260) { gi_924 = TRUE; ls_32 = ExchangeRate1(gs_228, gs_236, " "); ls_72 = "\n"; ls_72 = ls_72 + "Script : " + gs_756 + " Stopped due to Quote Error \n"; Comment(ls_72); for (l_index_40 = 0; l_index_40 <= gi_256; l_index_40++) { gia_1100[l_index_40] = 0; gia_1108[l_index_40] = 0; gia_1104[l_index_40] = 0; gia_1112[l_index_40] = 0; } if (gi_1060 == TRUE && gi_160 == TRUE && g_datetime_932 + 60 * gi_164 < TimeLocal()) { SendMail("Error_" + gs_76, "Error_QuoteError_" + AccountCompany() + "_" + StringSubstr(Symbol(), 0, 6) + "_" + gi_208 + "_" + gs_84); g_datetime_932 = TimeLocal(); } } else { RefreshRates(); li_124 = MarginLevelCheck(); lsa_60[0] = AccountCompany(); lsa_60[1] = TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS); lsa_60[2] = DoubleToStr(TimeLocal(), 0); lsa_60[3] = Symbol(); lsa_60[4] = DoubleToStr(gi_908, 0); lsa_60[5] = DoubleToStr(gd_140, 5); lsa_60[6] = DoubleToStr(gi_1000, 0); lsa_60[7] = DoubleToStr(Bid, 5); lsa_60[8] = DoubleToStr(Ask, 5); for (l_index_40 = 0; l_index_40 <= gi_1064; l_index_40++) { lsa_60[l_index_40 << 2 + 9] = DoubleToStr(gia_1116[l_index_40], 0); lsa_60[l_index_40 << 2 + 10] = DoubleToStr(gda_1124[l_index_40], 5); lsa_60[l_index_40 << 2 + 11] = DoubleToStr(gia_1120[l_index_40], 0); lsa_60[l_index_40 << 2 + 12] = DoubleToStr(gda_1128[l_index_40], 5); } ls_24 = ""; for (l_index_40 = 0; l_index_40 <= li_68; l_index_40++) ls_24 = ls_24 + lsa_60[l_index_40] + "|"; ls_32 = ""; ls_32 = ExchangeRate1(gs_228, gs_236, ls_24); for (l_index_40 = 0; l_index_40 <= li_68; l_index_40++) lsa_64[l_index_40] = ""; if (StringSubstr(ls_32, 0, 1) == "-") Print("Error Exchange Rate: StrInfo2 = ", ls_32); else { li_56 = FALSE; li_52 = 0; for (l_index_40 = 0; l_index_40 <= li_68 && li_56 == FALSE; l_index_40++) { li_48 = StringFind(ls_32, "|", li_52); if (li_48 == -1) { lsa_64[l_index_40] = StringSubstr(ls_32, li_52, 0); li_56 = TRUE; } else { if (li_48 - li_52 == 0) lsa_64[l_index_40] = ""; else lsa_64[l_index_40] = StringSubstr(ls_32, li_52, li_48 - li_52); if (li_48 + 1 < StringLen(ls_32)) li_52 = li_48 + 1; else li_56 = TRUE; } } } if (gi_244 == TRUE) { li_20 = FileWrite(g_file_880, ls_24 + "|" + ls_32); if (li_20 < 0) { l_error_16 = GetLastError(); Print("Error writing FILE: ", g_name_892, l_error_16); } } ls_72 = "\n"; ls_72 = ls_72 + "Script : " + gs_756 + " Working \n"; ls_72 = ls_72 + "\n"; ls_72 = ls_72 + "AccountCompany : " + lsa_60[0] + " & " + lsa_64[0] + "\n"; ls_72 = ls_72 + "TickTime : " + lsa_60[1] + " & " + lsa_64[1] + "\n"; ls_72 = ls_72 + "TickTimeInt : " + lsa_60[2] + " & " + lsa_64[2] + "\n"; ls_72 = ls_72 + "Symbol : " + lsa_60[3] + " & " + lsa_64[3] + "\n"; ls_72 = ls_72 + "Demo : " + lsa_60[4] + " & " + lsa_64[4] + "\n"; ls_72 = ls_72 + "Lot : " + lsa_60[5] + " & " + lsa_64[5] + "\n"; ls_72 = ls_72 + "MarginLevel : " + lsa_60[6] + " & " + lsa_64[6] + "\n"; ls_72 = ls_72 + "Bid : " + lsa_60[7] + " & " + lsa_64[7] + "\n"; ls_72 = ls_72 + "Ask : " + lsa_60[8] + " & " + lsa_64[8] + "\n"; if ((lsa_60[0] == lsa_64[0] && lsa_60[3] == lsa_64[3]) || MathAbs(StrToInteger(lsa_60[2]) - StrToInteger(lsa_64[2])) >= gi_268 || StringSubstr(lsa_60[3], 0, 6) != StringSubstr(lsa_64[3], 0, 6) || lsa_60[4] != lsa_64[4] || lsa_60[5] != lsa_64[5]) { gi_916 = TRUE; for (l_index_40 = 0; l_index_40 <= gi_256; l_index_40++) { gia_1100[l_index_40] = 0; gia_1108[l_index_40] = 0; gia_1104[l_index_40] = 0; gia_1112[l_index_40] = 0; } ls_72 = ls_72 + "\n"; ls_72 = ls_72 + "CAN NOT Trade due to Pair Unmatch. " + "\n"; if (gi_124 == TRUE && !((lsa_60[0] == lsa_64[0] && lsa_60[3] == lsa_64[3]) || MathAbs(StrToInteger(lsa_60[2]) - StrToInteger(lsa_64[2])) >= gi_268 || StringSubstr(lsa_60[3], 0, 6) != StringSubstr(lsa_64[3], 0, 6) || lsa_60[4] != lsa_64[4]) && lsa_60[5] != lsa_64[5]) { if (StrToDouble(lsa_60[5]) > StrToDouble(lsa_64[5])) { if (StrToDouble(lsa_64[5]) >= MarketInfo(Symbol(), MODE_MINLOT)) { if (g_minlot_992 == 0.0) Print("Debug Print Zero Divide : G_MinimumLotIncrement = ", g_minlot_992); gd_140 = MathFloor(StrToDouble(lsa_64[5]) / g_minlot_992) * g_minlot_992; } } } } else { if (StrToDouble(lsa_60[6]) >= 1.0 || StrToDouble(lsa_64[6]) >= 1.0) { gi_916 = FALSE; gi_920 = TRUE; ls_72 = ls_72 + "\n"; ls_72 = ls_72 + "CAN NOT Open due to Margin Level. (Close Trade Working)" + "\n"; } else { gi_916 = FALSE; gi_920 = FALSE; ls_72 = ls_72 + "\n"; ls_72 = ls_72 + "Auto Trade Working. " + "\n"; } } if (g_datetime_948 + 60 * gi_264 < TimeLocal()) { g_datetime_948 = TimeLocal(); gi_952 = FALSE; for (l_index_40 = 0; l_index_40 <= gi_256; l_index_40++) { li_104 = gi_208 + 100000000 * l_index_40; OrderCheck2(li_104, Symbol()); if (g_count_776 == 0) if (gia_1116[l_index_40] != 0) gi_952 = TRUE; if (g_count_776 == 1) if (gia_1116[l_index_40] != 1) gi_952 = TRUE; if (g_count_776 != 0 && g_count_776 != 1) gi_952 = TRUE; if (g_count_780 == 0) if (gia_1120[l_index_40] != 0) gi_952 = TRUE; if (g_count_780 == 1) if (gia_1120[l_index_40] != 1) gi_952 = TRUE; if (g_count_780 != 0 && g_count_780 != 1) gi_952 = TRUE; } if (gi_952 == TRUE) { if (gi_1060 == TRUE && gi_152 == TRUE && g_datetime_936 + 60 * gi_164 < TimeLocal()) { SendMail("Error_" + gs_76, "Error_PositionStatusUnmatch_" + AccountCompany() + "_" + StringSubstr(Symbol(), 0, 6) + "_" + gi_208 + "_" + gs_84); g_datetime_936 = TimeLocal(); } } } if (gi_952 == TRUE) { ls_72 = ls_72 + "Error : Position Status Unmatch. " + "\n"; } Comment(ls_72); if (gi_916 == FALSE) { l_str2dbl_88 = StrToDouble(lsa_64[7]); l_str2dbl_96 = StrToDouble(lsa_64[8]); for (l_index_40 = 0; l_index_40 <= gi_256; l_index_40++) { if (gi_92 == 1 && gia_1116[l_index_40] == 0 && l_str2dbl_88 - Ask >= gda_1068[l_index_40] * gd_844) gia_1100[l_index_40]++; else gia_1100[l_index_40] = 0; if (gi_92 == 1 && gia_1120[l_index_40] == 0 && Bid - l_str2dbl_96 >= gda_1076[l_index_40] * gd_844) gia_1104[l_index_40]++; else gia_1104[l_index_40] = 0; if ((gi_92 == 1 && gia_1116[l_index_40] == 0 && gia_1100[l_index_40] >= gia_1084[l_index_40] && gi_920 == FALSE) || (gi_92 == 2 && gia_1116[l_index_40] == 0 && StrToInteger(lsa_64[l_index_40 << 2 + 11]) == 1)) { li_104 = gi_208 + 100000000 * l_index_40; g_ticket_800 = 0; li_20 = BuyProcess2(gd_140, gi_220, gi_148, gi_136, gi_132, li_104, gs_756, gd_844, gi_212, 0, OP_BUY, 0, Symbol(), g_file_888, 0, gi_160, gi_164); if (li_20 == 0 && OrderSelect(g_ticket_800, SELECT_BY_TICKET, MODE_TRADES)) { gia_1116[l_index_40] = 1; gda_1124[l_index_40] = OrderOpenPrice(); lsa_60[l_index_40 << 2 + 9] = DoubleToStr(gia_1116[l_index_40], 0); lsa_60[l_index_40 << 2 + 10] = DoubleToStr(gda_1124[l_index_40], 5); ls_24 = ""; for (int l_index_44 = 0; l_index_44 <= li_68; l_index_44++) ls_24 = ls_24 + lsa_60[l_index_44] + "|"; ls_32 = ""; ls_32 = ExchangeRate1(gs_228, gs_236, ls_24); for (l_index_44 = 0; l_index_44 <= gi_256; l_index_44++) { gia_1100[l_index_44] = 0; gia_1104[l_index_44] = 0; } if (gi_248 == TRUE) { li_20 = FileWrite(g_file_876, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), Symbol(), DoubleToStr(li_104, 0), " Buy Open ", " Ask = ", DoubleToStr(Ask, 5), " CtBid = ", DoubleToStr(l_str2dbl_88, 5), " BuyOpenPrice = ", OrderOpenPrice()); if (li_20 < 0) { l_error_16 = GetLastError(); Print("Error writing FILE: ", g_name_892, l_error_16); } } if (gi_1060 == TRUE && gi_168 == TRUE) SendMail("Buy_" + gs_76, "Buy_" + AccountCompany() + "_" + StringSubstr(Symbol(), 0, 6) + "_" + li_104 + "_" + gs_84 + "_BuyOpenPrice=" + DoubleToStr(gda_1124[l_index_40], 5)); } } if ((gi_92 == 1 && gia_1120[l_index_40] == 0 && gia_1104[l_index_40] >= gia_1092[l_index_40] && gi_920 == FALSE) || (gi_92 == 2 && gia_1120[l_index_40] == 0 && StrToInteger(lsa_64[l_index_40 << 2 + 9]) == 1)) { li_104 = gi_208 + 100000000 * l_index_40; g_ticket_800 = 0; li_20 = SellProcess2(gd_140, gi_220, gi_148, gi_136, gi_132, li_104, gs_756, gd_844, gi_212, 0, OP_SELL, 0, Symbol(), g_file_888, 0, gi_160, gi_164); if (li_20 == 0 && OrderSelect(g_ticket_800, SELECT_BY_TICKET, MODE_TRADES)) { gia_1120[l_index_40] = 1; gda_1128[l_index_40] = OrderOpenPrice(); lsa_60[l_index_40 << 2 + 11] = DoubleToStr(gia_1120[l_index_40], 0); lsa_60[l_index_40 << 2 + 12] = DoubleToStr(gda_1128[l_index_40], 5); ls_24 = ""; for (l_index_44 = 0; l_index_44 <= li_68; l_index_44++) ls_24 = ls_24 + lsa_60[l_index_44] + "|"; ls_32 = ""; ls_32 = ExchangeRate1(gs_228, gs_236, ls_24); for (l_index_44 = 0; l_index_44 <= gi_256; l_index_44++) { gia_1100[l_index_44] = 0; gia_1104[l_index_44] = 0; } if (gi_248 == TRUE) { li_20 = FileWrite(g_file_876, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), Symbol(), DoubleToStr(li_104, 0), " Sell Open ", " Bid = ", DoubleToStr(Bid, 5), " CtAsk = ", DoubleToStr(l_str2dbl_96, 5), " SellOpenPrice = ", OrderOpenPrice()); if (li_20 < 0) { l_error_16 = GetLastError(); Print("Error writing FILE: ", g_name_892, l_error_16); } } if (gi_1060 == TRUE && gi_168 == TRUE) SendMail("Sell_" + gs_76, "Sell_" + AccountCompany() + "_" + StringSubstr(Symbol(), 0, 6) + "_" + li_104 + "_" + gs_84 + "_SellOpenPrice=" + DoubleToStr(gda_1128[l_index_40], 5)); } } } for (l_index_40 = 0; l_index_40 <= gi_256; l_index_40++) { if (gi_92 == 1 && StrToInteger(lsa_60[l_index_40 << 2 + 9]) == 1 && StrToInteger(lsa_64[l_index_40 << 2 + 11]) == 1 && StrToDouble(lsa_64[l_index_40 << 2 + 12]) - StrToDouble(lsa_60[l_index_40 << 2 + 10]) + Bid - l_str2dbl_96 >= gda_1072[l_index_40] * gd_844 || (StrToDouble(lsa_60[6]) >= 2.0 || StrToDouble(lsa_64[6]) >= 2.0 && StrToDouble(lsa_64[l_index_40 << 2 + 12]) - StrToDouble(lsa_60[l_index_40 << 2 + 10]) + Bid - l_str2dbl_96 >= 0.0) || StrToDouble(lsa_60[6]) >= 3.0 || StrToDouble(lsa_64[6]) >= 3.0) gia_1108[l_index_40]++; else gia_1108[l_index_40] = 0; if (gi_92 == 1 && StrToInteger(lsa_60[l_index_40 << 2 + 11]) == 1 && StrToInteger(lsa_64[l_index_40 << 2 + 9]) == 1 && StrToDouble(lsa_60[l_index_40 << 2 + 12]) - StrToDouble(lsa_64[l_index_40 << 2 + 10]) + l_str2dbl_88 - Ask >= gda_1080[l_index_40] * gd_844 || (StrToDouble(lsa_60[6]) >= 2.0 || StrToDouble(lsa_64[6]) >= 2.0 && StrToDouble(lsa_64[l_index_40 << 2 + 12]) - StrToDouble(lsa_60[l_index_40 << 2 + 10]) + Bid - l_str2dbl_96 >= 0.0) || StrToDouble(lsa_60[6]) >= 3.0 || StrToDouble(lsa_64[6]) >= 3.0) gia_1112[l_index_40]++; else gia_1112[l_index_40] = 0; if ((gi_92 == 1 && StrToInteger(lsa_60[l_index_40 << 2 + 9]) == 1 && StrToInteger(lsa_64[l_index_40 << 2 + 11]) == 1 && gia_1108[l_index_40] >= gia_1088[l_index_40]) || (gi_92 == 2 && StrToInteger(lsa_60[l_index_40 << 2 + 9]) == 1 && StrToInteger(lsa_64[l_index_40 << 2 + 11]) == 0)) { li_104 = gi_208 + 100000000 * l_index_40; ld_108 = 0; g_ticket_800 = 0; BuyCloseAllProcess2(li_104, gi_148, gs_756, Symbol(), g_file_888, gi_216, gi_160, gi_164); if (OrderSelect(g_ticket_800, SELECT_BY_TICKET, MODE_HISTORY)) ld_108 = OrderClosePrice(); OrderCheck2(li_104, Symbol()); if (g_count_776 == 0) { gia_1116[l_index_40] = 0; gda_1124[l_index_40] = 0; lsa_60[l_index_40 << 2 + 9] = DoubleToStr(gia_1116[l_index_40], 0); lsa_60[l_index_40 << 2 + 10] = DoubleToStr(gda_1124[l_index_40], 5); ls_24 = ""; for (l_index_44 = 0; l_index_44 <= li_68; l_index_44++) ls_24 = ls_24 + lsa_60[l_index_44] + "|"; ls_32 = ""; ls_32 = ExchangeRate1(gs_228, gs_236, ls_24); for (l_index_44 = 0; l_index_44 <= gi_256; l_index_44++) { gia_1108[l_index_44] = 0; gia_1112[l_index_44] = 0; } if (gi_248 == TRUE) { li_20 = FileWrite(g_file_876, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), Symbol(), DoubleToStr(li_104, 0), " Buy Close ", " Bid = ", DoubleToStr(Bid, 5), " CtAsk = ", DoubleToStr(l_str2dbl_96, 5), " BuyClosePrice = ", ld_108); if (li_20 < 0) { l_error_16 = GetLastError(); Print("Error writing FILE: ", g_name_892, l_error_16); } } if (gi_1060 == TRUE && gi_168 == TRUE) SendMail("BuyClose_" + gs_76, "BuyClose_" + AccountCompany() + "_" + StringSubstr(Symbol(), 0, 6) + "_" + li_104 + "_" + gs_84 + "_BuyClosePrice=" + DoubleToStr(ld_108, 5)); } } if ((gi_92 == 1 && StrToInteger(lsa_60[l_index_40 << 2 + 11]) == 1 && StrToInteger(lsa_64[l_index_40 << 2 + 9]) == 1 && gia_1112[l_index_40] >= gia_1096[l_index_40]) || (gi_92 == 2 && StrToInteger(lsa_60[l_index_40 << 2 + 11]) == 1 && StrToInteger(lsa_64[l_index_40 << 2 + 9]) == 0)) { li_104 = gi_208 + 100000000 * l_index_40; ld_116 = 0; g_ticket_800 = 0; SellCloseAllProcess2(li_104, gi_148, gs_756, Symbol(), g_file_888, gi_216, gi_160, gi_164); if (OrderSelect(g_ticket_800, SELECT_BY_TICKET, MODE_HISTORY)) ld_116 = OrderClosePrice(); OrderCheck2(li_104, Symbol()); if (g_count_780 == 0) { gia_1120[l_index_40] = 0; gda_1128[l_index_40] = 0; lsa_60[l_index_40 << 2 + 11] = DoubleToStr(gia_1120[l_index_40], 0); lsa_60[l_index_40 << 2 + 12] = DoubleToStr(gda_1128[l_index_40], 5); ls_24 = ""; for (l_index_44 = 0; l_index_44 <= li_68; l_index_44++) ls_24 = ls_24 + lsa_60[l_index_44] + "|"; ls_32 = ""; ls_32 = ExchangeRate1(gs_228, gs_236, ls_24); for (l_index_44 = 0; l_index_44 <= gi_256; l_index_44++) { gia_1108[l_index_44] = 0; gia_1112[l_index_44] = 0; } if (gi_248 == TRUE) { li_20 = FileWrite(g_file_876, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), Symbol(), DoubleToStr(li_104, 0), " Sell Close ", " Ask = ", DoubleToStr(Ask, 5), " CtBid = ", DoubleToStr(l_str2dbl_88, 5), " SellClosePrice = ", ld_116); if (li_20 < 0) { l_error_16 = GetLastError(); Print("Error writing FILE: ", g_name_892, l_error_16); } } if (gi_1060 == TRUE && gi_168 == TRUE) SendMail("SellClose_" + gs_76, "SellClose_" + AccountCompany() + "_" + StringSubstr(Symbol(), 0, 6) + "_" + li_104 + "_" + gs_84 + "_SellClosePrice=" + DoubleToStr(ld_116, 5)); } } } } } } } if (gi_252 == TRUE) SaveStatistics(0, TimeLocal(), l_str2dbl_88, l_str2dbl_96); Sleep(900); } return (0); } int deinit_common() { if (gi_252 == TRUE) SaveStatistics(1, TimeLocal(), 0, 0); FileClose(g_file_888); if (gi_248 == TRUE) FileClose(g_file_876); if (gi_244 == TRUE) FileClose(g_file_880); if (gi_252 == TRUE) FileClose(g_file_884); Comment(""); return (0); } int MarginLevelCheck() { int l_error_36; int li_40; int li_24 = gi_1000; if (AccountEquity() == 0.0) Print("Debug Print Zero Divide : AccountEquity() = ", AccountEquity()); double ld_0 = AccountMargin() / AccountEquity(); double ld_16 = MathAbs(AccountFreeMargin() - AccountFreeMarginCheck(Symbol(), OP_BUY, gd_140)); double ld_8 = (AccountMargin() + ld_16) / AccountEquity(); bool li_32 = FALSE; if (AccountFreeMarginCheck(Symbol(), OP_BUY, gd_140) <= 0.0 || GetLastError() == 134/* NOT_ENOUGH_MONEY */) li_32 = TRUE; if (AccountFreeMarginCheck(Symbol(), OP_SELL, gd_140) <= 0.0 || GetLastError() == 134/* NOT_ENOUGH_MONEY */) li_32 = TRUE; if (gi_1000 == 0) { if (ld_0 >= gd_984) gi_1000 = 3; else { if (ld_0 >= gd_976) gi_1000 = 2; else if (ld_0 >= gd_968 || li_32 == TRUE) gi_1000 = 1; } } else { if (gi_1000 == 1) { if (ld_0 >= gd_984) gi_1000 = 3; else { if (ld_0 >= gd_976) gi_1000 = 2; else if (ld_8 < gd_968 && li_32 == FALSE) gi_1000 = 0; } } else { if (gi_1000 == 2) { if (ld_0 >= gd_984) gi_1000 = 3; else { if (ld_8 < gd_968 && li_32 == FALSE) gi_1000 = 0; else if (ld_8 < gd_976) gi_1000 = 1; } } else { if (gi_1000 == 3) { if (ld_8 < gd_968 && li_32 == FALSE) gi_1000 = 0; else { if (ld_8 < gd_976) gi_1000 = 1; else if (ld_8 < gd_984) gi_1000 = 2; } } } } } if (li_24 < 2 && gi_1000 == 2) { if (gi_1060 == TRUE && gi_156 == TRUE && g_datetime_940 + 60 * gi_164 < TimeLocal()) { SendMail("Warning_" + gs_76, "Warning_MarginLevel_2_" + AccountCompany() + "_" + StringSubstr(Symbol(), 0, 6) + "_" + gi_208 + "_" + gs_84); g_datetime_940 = TimeLocal(); } li_40 = FileWrite(g_file_888, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), Symbol(), "Warning MarginLevel", "2"); if (li_40 < 0) { l_error_36 = GetLastError(); Print("Error writing FILE: ", g_name_892, l_error_36); } } if (li_24 < 3 && gi_1000 == 3) { if (gi_1060 == TRUE && gi_156 == TRUE && g_datetime_944 + 60 * gi_164 < TimeLocal()) { SendMail("Warning_" + gs_76, "Warning_MarginLevel_3_" + AccountCompany() + "_" + StringSubstr(Symbol(), 0, 6) + "_" + gi_208 + "_" + gs_84); g_datetime_944 = TimeLocal(); } li_40 = FileWrite(g_file_888, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), Symbol(), "Warning MarginLevel", "3"); if (li_40 < 0) { l_error_36 = GetLastError(); Print("Error writing FILE: ", g_name_892, l_error_36); } } return (0); } int SaveStatistics(int ai_0, int ai_4, double ad_8, double ad_16) { int li_40; int li_44; int li_52; int l_error_56; string ls_60; string ls_24 = StringSubstr(TimeToStr(gi_1004, TIME_DATE|TIME_SECONDS), 0, 13); string ls_32 = StringSubstr(TimeToStr(ai_4, TIME_DATE|TIME_SECONDS), 0, 13); if (gi_1004 == 0) { g_count_1008 = 0; g_count_1012 = 0; for (int l_index_48 = 0; l_index_48 <= gi_1016; l_index_48++) { gia_1020[l_index_48] = 0; gia_1036[l_index_48] = 0; gia_1024[l_index_48] = 0; gia_1040[l_index_48] = 0; } } if (gi_1004 != 0 && ls_24 != ls_32 || ai_0 == 1) { ls_60 = ""; ls_60 = ls_60 + AccountCompany() + "\t"; ls_60 = ls_60 + TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS) + "\t"; ls_60 = ls_60 + DoubleToStr(TimeLocal(), 0) + "\t"; ls_60 = ls_60 + Symbol() + "\t"; ls_60 = ls_60 + ls_24 + "\t"; ls_60 = ls_60 + DoubleToStr(g_count_1008, 0) + "\t"; ls_60 = ls_60 + DoubleToStr(g_count_1012, 0) + "\t"; for (l_index_48 = 0; l_index_48 <= gi_1016; l_index_48++) ls_60 = ls_60 + DoubleToStr(gia_1020[l_index_48], 0) + "\t"; for (l_index_48 = 0; l_index_48 <= gi_1016; l_index_48++) ls_60 = ls_60 + DoubleToStr(gia_1036[l_index_48], 0) + "\t"; for (l_index_48 = 0; l_index_48 <= gi_1016; l_index_48++) ls_60 = ls_60 + DoubleToStr(gia_1024[l_index_48], 0) + "\t"; for (l_index_48 = 0; l_index_48 <= gi_1016; l_index_48++) ls_60 = ls_60 + DoubleToStr(gia_1040[l_index_48], 0) + "\t"; li_52 = FileWrite(g_file_884, ls_60); if (li_52 < 0) { l_error_56 = GetLastError(); Print("Error writing FILE: ", "PAIR01STAT", l_error_56); } g_count_1008 = 0; g_count_1012 = 0; for (l_index_48 = 0; l_index_48 <= gi_1016; l_index_48++) { gia_1020[l_index_48] = 0; gia_1036[l_index_48] = 0; gia_1024[l_index_48] = 0; gia_1040[l_index_48] = 0; } } if (ai_0 == 1) return (0); g_count_1008++; if (gi_852 != FALSE || gi_912 != FALSE || gi_924 == TRUE || gi_916 == TRUE) g_count_1012++; else { li_40 = MathFloor((ad_8 - Ask) / gd_844) + 10.0; if (li_40 < 0) li_40 = 0; if (li_40 > gi_1016) li_40 = gi_1016; gia_1020[li_40]++; for (l_index_48 = 0; l_index_48 <= li_40; l_index_48++) { gia_1028[l_index_48]++; if (gia_1036[l_index_48] < gia_1028[l_index_48]) gia_1036[l_index_48] = gia_1028[l_index_48]; } for (l_index_48 = gi_1016; l_index_48 > li_40; l_index_48--) gia_1028[l_index_48] = 0; gi_unused_1044 = li_40; li_44 = MathFloor((Bid - ad_16) / gd_844) + 10.0; if (li_44 < 0) li_44 = 0; if (li_44 > gi_1016) li_44 = gi_1016; gia_1024[li_44]++; for (l_index_48 = 0; l_index_48 <= li_44; l_index_48++) { gia_1032[l_index_48]++; if (gia_1040[l_index_48] < gia_1032[l_index_48]) gia_1040[l_index_48] = gia_1032[l_index_48]; } for (l_index_48 = gi_1016; l_index_48 > li_44; l_index_48--) gia_1032[l_index_48] = 0; gi_unused_1048 = li_44; } gi_1004 = ai_4; return (0); } int OrderCheck2(int a_magic_0, string a_symbol_4) { gi_768 = 0; gi_772 = 0; g_count_776 = 0; g_count_780 = 0; g_count_784 = 0; g_count_788 = 0; g_count_792 = 0; g_count_796 = 0; int l_ord_total_12 = OrdersTotal(); for (int l_pos_16 = l_ord_total_12 - 1; l_pos_16 >= 0; l_pos_16--) { if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == a_symbol_4 || a_symbol_4 == "" && OrderMagicNumber() == a_magic_0 && OrderType() == OP_BUY) g_count_776++; if (OrderSymbol() == a_symbol_4 || a_symbol_4 == "" && OrderMagicNumber() == a_magic_0 && OrderType() == OP_SELL) g_count_780++; if (OrderSymbol() == a_symbol_4 || a_symbol_4 == "" && OrderMagicNumber() == a_magic_0 && OrderType() == OP_BUYSTOP) g_count_784++; if (OrderSymbol() == a_symbol_4 || a_symbol_4 == "" && OrderMagicNumber() == a_magic_0 && OrderType() == OP_SELLSTOP) g_count_788++; if (OrderSymbol() == a_symbol_4 || a_symbol_4 == "" && OrderMagicNumber() == a_magic_0 && OrderType() == OP_BUYLIMIT) g_count_792++; if (OrderSymbol() == a_symbol_4 || a_symbol_4 == "" && OrderMagicNumber() == a_magic_0 && OrderType() == OP_SELLLIMIT) g_count_796++; } } gi_768 = g_count_776 + g_count_780; gi_772 = g_count_784 + g_count_788 + g_count_792 + g_count_796; return (0); } int OrderTicketCheck2(int a_magic_0, string a_symbol_4, int a_cmd_12) { g_ticket_804 = 0; int l_ord_total_16 = OrdersTotal(); for (int l_pos_20 = l_ord_total_16 - 1; l_pos_20 >= 0; l_pos_20--) { if (OrderSelect(l_pos_20, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == a_symbol_4 || a_symbol_4 == "" && OrderMagicNumber() == a_magic_0 && OrderType() == a_cmd_12) { g_ticket_804 = OrderTicket(); break; } } } return (0); } int BuyProcess2(double a_lots_0, int ai_8, int a_slippage_12, int ai_16, int ai_20, int a_magic_24, string as_28, double ad_36, int ai_44, int ai_48, int a_cmd_52, double ad_56, string a_symbol_64, int ai_72, int ai_76, int ai_80, int ai_84) { int l_ticket_92; int l_error_100; int li_104; double l_price_112; double l_price_120; int li_128; double l_ask_136; int l_count_108 = 0; int l_ord_total_96 = OrdersTotal(); for (int l_pos_88 = l_ord_total_96 - 1; l_pos_88 >= 0; l_pos_88--) { if (OrderSelect(l_pos_88, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == a_symbol_64 && OrderMagicNumber() == a_magic_24 && OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT) l_count_108++; } else { l_error_100 = GetLastError(); Print("Error selecting MODE_TRADES order : ", l_error_100, l_pos_88); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error selecting MODE_TRADES order : ", l_error_100, l_pos_88); return (-1); } } if (l_count_108 >= ai_44) { Print("Error buy orders exceed MaxNoOfPos : ", ai_44); if (gi_840 == TRUE && ai_80 == 1 && g_datetime_808 + 60 * ai_84 < TimeLocal()) { SendMail("BuyError_" + a_symbol_64 + Period() + "_" + gs_76, "BuyError_Exceed_MaxNoOfPos_" + a_symbol_64 + Period() + "_" + gs_84 + "_CurrentBid=" + Bid); g_datetime_808 = TimeLocal(); } if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error buy orders exceed MaxNoOfPos : ", ai_44); return (-2); } RefreshRates(); if (a_cmd_52 == OP_BUY) l_ask_136 = MarketInfo(a_symbol_64, MODE_ASK); if (a_cmd_52 == OP_BUYLIMIT || a_cmd_52 == OP_BUYSTOP) l_ask_136 = ad_56; if (ai_16 == 0) l_price_112 = 0; else l_price_112 = l_ask_136 - ai_16 * ad_36; if (ai_20 == 0) l_price_120 = 0; else l_price_120 = l_ask_136 + ai_20 * ad_36; if (ai_8 > ai_44 - l_count_108) { li_128 = ai_44 - l_count_108; Print("Warning buy orders exceed MaxNoOfPos : ", ai_44); if (gi_840 == TRUE && ai_80 == 1 && g_datetime_808 + 60 * ai_84 < TimeLocal()) { SendMail("BuyError_" + a_symbol_64 + Period() + "_" + gs_76, "BuyError_Exceed_MaxNoOfPos_" + a_symbol_64 + Period() + "_" + gs_84 + "_CurrentBid=" + Bid); g_datetime_808 = TimeLocal(); } if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Warning buy orders exceed MaxNoOfPos : ", ai_44); } else li_128 = ai_8; if (li_128 >= 1) { for (l_pos_88 = 1; l_pos_88 <= li_128; l_pos_88++) { while (!IsStopped()) { if (GlobalVariableSetOnCondition("ThreadBusy_SEM", 1, 0) == TRUE) break; l_error_100 = GetLastError(); if (l_error_100 == 4058/* GLOBAL_VARIABLE_NOT_FOUND */) { Print("Error locking the THREAD : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error locking the THREAD : ", l_error_100); return (-1); } Sleep(500); } l_ticket_92 = OrderSend(a_symbol_64, a_cmd_52, a_lots_0, l_ask_136, a_slippage_12, l_price_112, l_price_120, "Magic=" + a_magic_24 + "_" + as_28, a_magic_24, 0, Green); if (l_ticket_92 > 0) { l_error_100 = 0; g_ticket_800 = l_ticket_92; } else { l_error_100 = GetLastError(); if (l_error_100 == 129/* INVALID_PRICE */ || l_error_100 == 130/* INVALID_STOPS */ || l_error_100 == 138/* REQUOTE */ || l_error_100 == 136/* OFF_QUOTES */ || l_error_100 == 133/* TRADE_DISABLED */) { for (int li_132 = 1; li_132 <= ai_48; li_132++) { if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error placing BUY order : ", l_error_100); Sleep(ai_76); RefreshRates(); if (l_error_100 == 129/* INVALID_PRICE */ || l_error_100 == 138/* REQUOTE */ || l_error_100 == 136/* OFF_QUOTES */ || l_error_100 == 133/* TRADE_DISABLED */) { if (a_cmd_52 == OP_BUY) l_ask_136 = MarketInfo(a_symbol_64, MODE_ASK); if (a_cmd_52 == OP_BUYLIMIT || a_cmd_52 == OP_BUYSTOP) l_ask_136 += ad_36; if (ai_16 == 0) l_price_112 = 0; else l_price_112 = l_ask_136 - ai_16 * ad_36; if (ai_20 == 0) l_price_120 = 0; else l_price_120 = l_ask_136 + ai_20 * ad_36; } if (l_error_100 == 130/* INVALID_STOPS */) { if (l_price_112 != 0.0) l_price_112 -= ad_36; if (l_price_120 != 0.0) l_price_120 += ad_36; } l_ticket_92 = OrderSend(a_symbol_64, a_cmd_52, a_lots_0, l_ask_136, a_slippage_12, l_price_112, l_price_120, "Magic=" + a_magic_24 + "_" + as_28, a_magic_24, 0, Green); if (l_ticket_92 > 0) { l_error_100 = 0; g_ticket_800 = l_ticket_92; break; } l_error_100 = GetLastError(); if (l_error_100 == 129/* INVALID_PRICE */ || l_error_100 == 130/* INVALID_STOPS */ || l_error_100 == 138/* REQUOTE */ || l_error_100 == 136/* OFF_QUOTES */ || l_error_100 == 133/* TRADE_DISABLED */) continue; Print("Error placing BUY order : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error placing BUY order : ", l_error_100); GlobalVariableSet("ThreadBusy_SEM", 0); l_error_100 = GetLastError(); if (l_error_100 != 0/* NO_ERROR */) { Print("Error unlocking the THREAD : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error unlocking the THREAD : ", l_error_100); } return (-1); } if (l_error_100 == 129/* INVALID_PRICE */ || l_error_100 == 130/* INVALID_STOPS */ || l_error_100 == 138/* REQUOTE */ || l_error_100 == 136/* OFF_QUOTES */ || l_error_100 == 133/* TRADE_DISABLED */) { Print("Error placing BUY order(exceed RetryNo) : ", l_error_100); if (gi_840 == TRUE && ai_80 == 1 && g_datetime_812 + 60 * ai_84 < TimeLocal()) { SendMail("BuyError_" + a_symbol_64 + Period() + "_" + gs_76, "BuyError_Exceed_RetryNo_" + a_symbol_64 + Period() + "_" + gs_84 + "_CurrentBid=" + Bid); g_datetime_812 = TimeLocal(); } if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error placing BUY order(exceed RetryNo) : ", l_error_100); GlobalVariableSet("ThreadBusy_SEM", 0); l_error_100 = GetLastError(); if (l_error_100 != 0/* NO_ERROR */) { Print("Error unlocking the THREAD : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error unlocking the THREAD : ", l_error_100); } return (-3); } } Print("Error placing BUY order : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error placing BUY order : ", l_error_100); GlobalVariableSet("ThreadBusy_SEM", 0); l_error_100 = GetLastError(); if (l_error_100 != 0/* NO_ERROR */) { Print("Error unlocking the THREAD : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error unlocking the THREAD : ", l_error_100); } return (-1); } GlobalVariableSet("ThreadBusy_SEM", 0); l_error_100 = GetLastError(); if (l_error_100 != 0/* NO_ERROR */) { Print("Error unlocking the THREAD : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error unlocking the THREAD : ", l_error_100); return (-1); } } } return (0); } int SellProcess2(double a_lots_0, int ai_8, int a_slippage_12, int ai_16, int ai_20, int a_magic_24, string as_28, double ad_36, int ai_44, int ai_48, int a_cmd_52, double ad_56, string a_symbol_64, int ai_72, int ai_76, int ai_80, int ai_84) { int l_ticket_92; int l_error_100; int li_104; double l_price_112; double l_price_120; int li_128; double l_bid_136; int l_count_108 = 0; int l_ord_total_96 = OrdersTotal(); for (int l_pos_88 = l_ord_total_96 - 1; l_pos_88 >= 0; l_pos_88--) { if (OrderSelect(l_pos_88, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == a_symbol_64 && OrderMagicNumber() == a_magic_24 && OrderType() == OP_SELL || OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT) l_count_108++; } else { l_error_100 = GetLastError(); Print("Error selecting MODE_TRADES order : ", l_error_100, l_pos_88); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error selecting MODE_TRADES order : ", l_error_100, l_pos_88); return (-1); } } if (l_count_108 >= ai_44) { Print("Error sell orders exceed MaxNoOfPos : ", ai_44); if (gi_840 == TRUE && ai_80 == 1 && g_datetime_816 + 60 * ai_84 < TimeLocal()) { SendMail("SellError_" + a_symbol_64 + Period() + "_" + gs_76, "SellError_Exceed_MaxNoOfPos_" + a_symbol_64 + Period() + "_" + gs_84 + "_CurrentBid=" + Bid); g_datetime_816 = TimeLocal(); } if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error sell orders exceed MaxNoOfPos : ", ai_44); return (-2); } RefreshRates(); if (a_cmd_52 == OP_SELL) l_bid_136 = MarketInfo(a_symbol_64, MODE_BID); if (a_cmd_52 == OP_SELLLIMIT || a_cmd_52 == OP_SELLSTOP) l_bid_136 = ad_56; if (ai_16 == 0) l_price_112 = 0; else l_price_112 = l_bid_136 + ai_16 * ad_36; if (ai_20 == 0) l_price_120 = 0; else l_price_120 = l_bid_136 - ai_20 * ad_36; if (ai_8 > ai_44 - l_count_108) { li_128 = ai_44 - l_count_108; Print("Warning sell orders exceed MaxNoOfPos : ", ai_44); if (gi_840 == TRUE && ai_80 == 1 && g_datetime_816 + 60 * ai_84 < TimeLocal()) { SendMail("SellError_" + a_symbol_64 + Period() + "_" + gs_76, "SellError_Exceed_MaxNoOfPos_" + a_symbol_64 + Period() + "_" + gs_84 + "_CurrentBid=" + Bid); g_datetime_816 = TimeLocal(); } if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Warning sell orders exceed MaxNoOfPos : ", ai_44); } else li_128 = ai_8; if (li_128 >= 1) { for (l_pos_88 = 1; l_pos_88 <= li_128; l_pos_88++) { while (!IsStopped()) { if (GlobalVariableSetOnCondition("ThreadBusy_SEM", 1, 0) == TRUE) break; l_error_100 = GetLastError(); if (l_error_100 == 4058/* GLOBAL_VARIABLE_NOT_FOUND */) { Print("Error locking the THREAD : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error locking the THREAD : ", l_error_100); return (-1); } Sleep(500); } l_ticket_92 = OrderSend(a_symbol_64, a_cmd_52, a_lots_0, l_bid_136, a_slippage_12, l_price_112, l_price_120, "Magic=" + a_magic_24 + "_" + as_28, a_magic_24, 0, Red); if (l_ticket_92 > 0) { l_error_100 = 0; g_ticket_800 = l_ticket_92; } else { l_error_100 = GetLastError(); if (l_error_100 == 129/* INVALID_PRICE */ || l_error_100 == 130/* INVALID_STOPS */ || l_error_100 == 138/* REQUOTE */ || l_error_100 == 136/* OFF_QUOTES */ || l_error_100 == 133/* TRADE_DISABLED */) { for (int li_132 = 1; li_132 <= ai_48; li_132++) { if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error placing SELL order : ", l_error_100); Sleep(ai_76); RefreshRates(); if (l_error_100 == 129/* INVALID_PRICE */ || l_error_100 == 138/* REQUOTE */ || l_error_100 == 136/* OFF_QUOTES */ || l_error_100 == 133/* TRADE_DISABLED */) { if (a_cmd_52 == OP_SELL) l_bid_136 = MarketInfo(a_symbol_64, MODE_BID); if (a_cmd_52 == OP_SELLLIMIT || a_cmd_52 == OP_SELLSTOP) l_bid_136 -= ad_36; if (ai_16 == 0) l_price_112 = 0; else l_price_112 = l_bid_136 + ai_16 * ad_36; if (ai_20 == 0) l_price_120 = 0; else l_price_120 = l_bid_136 - ai_20 * ad_36; } if (l_error_100 == 130/* INVALID_STOPS */) { if (l_price_112 != 0.0) l_price_112 += ad_36; if (l_price_120 != 0.0) l_price_120 -= ad_36; } l_ticket_92 = OrderSend(a_symbol_64, a_cmd_52, a_lots_0, l_bid_136, a_slippage_12, l_price_112, l_price_120, "Magic=" + a_magic_24 + "_" + as_28, a_magic_24, 0, Red); if (l_ticket_92 > 0) { l_error_100 = 0; g_ticket_800 = l_ticket_92; break; } l_error_100 = GetLastError(); if (l_error_100 == 129/* INVALID_PRICE */ || l_error_100 == 130/* INVALID_STOPS */ || l_error_100 == 138/* REQUOTE */ || l_error_100 == 136/* OFF_QUOTES */ || l_error_100 == 133/* TRADE_DISABLED */) continue; Print("Error placing SELL order : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error placing SELL order : ", l_error_100); GlobalVariableSet("ThreadBusy_SEM", 0); l_error_100 = GetLastError(); if (l_error_100 != 0/* NO_ERROR */) { Print("Error unlocking the THREAD : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error unlocking the THREAD : ", l_error_100); } return (-1); } if (l_error_100 == 129/* INVALID_PRICE */ || l_error_100 == 130/* INVALID_STOPS */ || l_error_100 == 138/* REQUOTE */ || l_error_100 == 136/* OFF_QUOTES */ || l_error_100 == 133/* TRADE_DISABLED */) { Print("Error placing SELL order(exceed RetryNo) : ", l_error_100); if (gi_840 == TRUE && ai_80 == 1 && g_datetime_820 + 60 * ai_84 < TimeLocal()) { SendMail("SellError_" + a_symbol_64 + Period() + "_" + gs_76, "SellError_Exceed_RetryNo_" + a_symbol_64 + Period() + "_" + gs_84 + "_CurrentBid=" + Bid); g_datetime_820 = TimeLocal(); } if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error placing SELL order(exceed RetryNo) : ", l_error_100); GlobalVariableSet("ThreadBusy_SEM", 0); l_error_100 = GetLastError(); if (l_error_100 != 0/* NO_ERROR */) { Print("Error unlocking the THREAD : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error unlocking the THREAD : ", l_error_100); } return (-3); } } Print("Error placing SELL order : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error placing SELL order : ", l_error_100); GlobalVariableSet("ThreadBusy_SEM", 0); l_error_100 = GetLastError(); if (l_error_100 != 0/* NO_ERROR */) { Print("Error unlocking the THREAD : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error unlocking the THREAD : ", l_error_100); } return (-1); } GlobalVariableSet("ThreadBusy_SEM", 0); l_error_100 = GetLastError(); if (l_error_100 != 0/* NO_ERROR */) { Print("Error unlocking the THREAD : ", l_error_100); if (ai_72 >= 1) li_104 = FileWrite(ai_72, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_64, "Error unlocking the THREAD : ", l_error_100); return (-1); } } } return (0); } int BuyCloseAllProcess2(int a_magic_0, int ai_4, string as_8, string a_symbol_16, int ai_24, int ai_28, int ai_32, int ai_36) { int l_error_48; int li_52; int l_ord_total_44 = OrdersTotal(); for (int l_pos_40 = l_ord_total_44 - 1; l_pos_40 >= 0; l_pos_40--) { if (OrderSelect(l_pos_40, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == a_symbol_16 && OrderMagicNumber() == a_magic_0 && OrderType() == OP_BUY) BuyCloseProcess2(OrderTicket(), OrderLots(), ai_4, as_8, a_symbol_16, ai_24, ai_28, ai_32, ai_36); } else { l_error_48 = GetLastError(); Print("Error selecting MODE_TRADES order : ", l_error_48, l_pos_40); if (ai_24 >= 1) li_52 = FileWrite(ai_24, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_16, "Error selecting MODE_TRADES order : ", l_error_48, l_pos_40); return (-1); } } return (0); } int BuyCloseProcess2(int a_ticket_0, double a_lots_4, int a_slippage_12, string as_unused_16, string a_symbol_24, int ai_32, int ai_36, int ai_40, int ai_44) { int l_error_48; int li_52; int li_56; while (!IsStopped()) { if (GlobalVariableSetOnCondition("ThreadBusy_SEM", 1, 0) == TRUE) break; l_error_48 = GetLastError(); if (l_error_48 == 4058/* GLOBAL_VARIABLE_NOT_FOUND */) { Print("Error locking the THREAD : ", l_error_48); if (ai_32 >= 1) li_52 = FileWrite(ai_32, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_24, "Error locking the THREAD : ", l_error_48); return (-1); } Sleep(500); } if (!OrderClose(a_ticket_0, a_lots_4, MarketInfo(a_symbol_24, MODE_BID), a_slippage_12, Yellow)) { l_error_48 = GetLastError(); li_56 = 1; while (li_56 <= ai_36) { if (ai_32 >= 1) li_52 = FileWrite(ai_32, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_24, "Error closing BUY order : ", l_error_48); RefreshRates(); if (!OrderClose(a_ticket_0, a_lots_4, MarketInfo(a_symbol_24, MODE_BID), a_slippage_12, Yellow)) { l_error_48 = GetLastError(); li_56++; } else { l_error_48 = 0; g_ticket_800 = a_ticket_0; break; } } if (l_error_48 != 0/* NO_ERROR */) { Print("Error closing BUY order(exceed RetryNo) : ", l_error_48); if (gi_840 == TRUE && ai_40 == 1 && g_datetime_824 + 60 * ai_44 < TimeLocal()) { SendMail("CloseBuyError_" + a_symbol_24 + Period() + "_" + gs_76, "CloseBuyError_Unkown_" + a_symbol_24 + Period() + "_" + gs_84 + "_CurrentBid=" + Bid); g_datetime_824 = TimeLocal(); } if (ai_32 >= 1) li_52 = FileWrite(ai_32, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_24, "Error closing BUY order(exceed RetryNo) : ", l_error_48); } } else g_ticket_800 = a_ticket_0; GlobalVariableSet("ThreadBusy_SEM", 0); return (0); } int SellCloseAllProcess2(int a_magic_0, int ai_4, string as_8, string a_symbol_16, int ai_24, int ai_28, int ai_32, int ai_36) { int l_error_48; int li_52; int l_ord_total_44 = OrdersTotal(); for (int l_pos_40 = l_ord_total_44 - 1; l_pos_40 >= 0; l_pos_40--) { if (OrderSelect(l_pos_40, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == a_symbol_16 && OrderMagicNumber() == a_magic_0 && OrderType() == OP_SELL) SellCloseProcess2(OrderTicket(), OrderLots(), ai_4, as_8, a_symbol_16, ai_24, ai_28, ai_32, ai_36); } else { l_error_48 = GetLastError(); Print("Error selecting MODE_TRADES order : ", l_error_48, l_pos_40); if (ai_24 >= 1) li_52 = FileWrite(ai_24, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_16, "Error selecting MODE_TRADES order : ", l_error_48, l_pos_40); return (-1); } } return (0); } int SellCloseProcess2(int a_ticket_0, double a_lots_4, int a_slippage_12, string as_unused_16, string a_symbol_24, int ai_32, int ai_36, int ai_40, int ai_44) { int l_error_48; int li_52; int li_56; while (!IsStopped()) { if (GlobalVariableSetOnCondition("ThreadBusy_SEM", 1, 0) == TRUE) break; l_error_48 = GetLastError(); if (l_error_48 == 4058/* GLOBAL_VARIABLE_NOT_FOUND */) { Print("Error locking the THREAD : ", l_error_48); if (ai_32 >= 1) li_52 = FileWrite(ai_32, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_24, "Error locking the THREAD : ", l_error_48); return (0); } Sleep(500); } if (!OrderClose(a_ticket_0, a_lots_4, MarketInfo(a_symbol_24, MODE_ASK), a_slippage_12, Yellow)) { l_error_48 = GetLastError(); li_56 = 1; while (li_56 <= ai_36) { if (ai_32 >= 1) li_52 = FileWrite(ai_32, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_24, "Error closing SELL order : ", l_error_48); RefreshRates(); if (!OrderClose(a_ticket_0, a_lots_4, MarketInfo(a_symbol_24, MODE_ASK), a_slippage_12, Yellow)) { l_error_48 = GetLastError(); li_56++; } else { l_error_48 = 0; g_ticket_800 = a_ticket_0; break; } } if (l_error_48 != 0/* NO_ERROR */) { Print("Error closing SELL order(exceed RetryNo) : ", l_error_48); if (gi_840 == TRUE && ai_40 == 1 && g_datetime_828 + 60 * ai_44 < TimeLocal()) { SendMail("CloseSellError_" + a_symbol_24 + Period() + "_" + gs_76, "CloseSellError_Unkown_" + a_symbol_24 + Period() + "_" + gs_84 + "_CurrentBid=" + Bid); g_datetime_828 = TimeLocal(); } if (ai_32 >= 1) li_52 = FileWrite(ai_32, AccountCompany(), TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS), DoubleToStr(TimeLocal(), 0), a_symbol_24, "Error closing SELL order(exceed RetryNo) : ", l_error_48); } } else g_ticket_800 = a_ticket_0; GlobalVariableSet("ThreadBusy_SEM", 0); return (0); }