#property copyright "www.rentasignal.com" #property link "http://www.rentasignal.com" #include #import "rentasignal.dll" int ForexTSD_SendGet(string a0); int ForexTSD_StartPost(string a0); int ForexTSD_AddPostData(int a0, string a1, string a2); int ForexTSD_SendPost(int a0); string ForexTSD_GetResult(int a0); string ForexTSD_MD5String(string a0); int ForexTSD_GetStatus(int a0); string ForexTSD_GetError(int a0); #import "kernel32.dll" int _lclose(int a0); int _lopen(string a0, int a1); int _llseek(int a0, int a1, int a2); int _lread(int a0, string a1, int a2); #import bool gi_76 = FALSE; bool gi_80 = FALSE; string gs_84 = "www.rentasignal.com"; string gs_92 = "1.31"; extern string rentasignal_username = ""; extern string rentasignal_password_key = ""; extern int timeout = 20; extern bool buyer = TRUE; extern bool power_on = FALSE; extern bool show_error_as_alert = TRUE; extern double buyer_lots_multiplier = 1.0; extern double buyer_lots_max_per_trade = 9999.0; extern string buyer_opt_filter_signal = ""; extern int buyer_install_version = 1; extern bool buyer_partial_closing = TRUE; extern bool buyer_stp_broker = FALSE; extern int seller_rentasignal_id = 0; extern string seller_opt_filter_magic_number = ""; extern string seller_opt_filter_comment = ""; extern bool use_working_time_limitation = FALSE; extern int working_time_StartHour = 7; extern int working_time_StartMinute = 0; extern int working_time_EndHour = 16; extern int working_time_EndMinute = 0; string gs_208 = ""; int gi_216 = 0; int g_datetime_220 = 0; int gi_224 = 0; bool gi_228 = FALSE; bool gi_232 = FALSE; string gs_unused_236 = ""; int g_datetime_244 = 0; string gs_248 = ""; string gs_256 = ""; string gs_264 = ""; string gs_272 = ""; int g_count_280 = 0; string gs_284 = ""; string gs_292 = ""; string gs_300 = ""; string gsa_308[2000]; int g_index_312 = 0; string gs_316 = ""; string gs_324 = ""; string gs_332 = ""; int g_error_340 = 0/* NO_ERROR */; string gsa_344[150]; bool cmp(string as_0, string as_8) { if (StringLen(as_0) == StringLen(as_8)) return (StringFind(as_0, as_8) != -1); return (FALSE); } string ForexTSD_GetUrl(string as_0) { if (!cmp(as_0, gs_208) || gi_216 == 0) { gi_216 = ForexTSD_SendGet(as_0); gs_208 = as_0; g_datetime_220 = TimeCurrent(); return (""); } int li_8 = ForexTSD_GetStatus(gi_216); int li_12 = gi_216; if (li_8 == 1) { gi_216 = 0; ForexTSD_GetResult(li_12); return; } if (li_8 == 0 && TimeCurrent() - g_datetime_220 > timeout) gi_216 = 0; else { if (li_8 == -1) { gi_216 = 0; ForexTSD_GetError(li_12); return (""); } } return (""); } int init() { return (0); } int deinit() { return (0); } void ErrorAlert(string as_0) { if (show_error_as_alert) { Alert(as_0); return; } Print(as_0); } int time_condition() { bool l_bool_0 = FALSE; int l_str2time_4 = StrToTime(working_time_StartHour + ":" + working_time_StartMinute); int l_str2time_8 = StrToTime(working_time_EndHour + ":" + working_time_EndMinute); if (working_time_StartHour < working_time_EndHour) l_bool_0 = TimeCurrent() >= l_str2time_4 && TimeCurrent() < l_str2time_8; else if (working_time_StartHour > working_time_EndHour) l_bool_0 = (TimeCurrent() >= l_str2time_4 && TimeHour(TimeCurrent()) < 24) || (TimeHour(TimeCurrent()) >= 0 && TimeCurrent() < l_str2time_8); return (l_bool_0); } bool symbol_exists(string a_symbol_0) { if (a_symbol_0 == "") return (FALSE); return (MarketInfo(a_symbol_0, MODE_SPREAD) != 0.0 || MarketInfo(a_symbol_0, MODE_ASK) != 0.0 || MarketInfo(a_symbol_0, MODE_BID) != 0.0); } int get_symbol_list() { string ls_20; int li_0 = 1936; int l_index_4 = 0; int li_8 = _lopen(TerminalPath() + "\\history\\" + AccountServer() + "\\symbols.raw", 0); int li_12 = _llseek(li_8, 0, 2) / li_0; for (int l_count_16 = 0; l_count_16 < li_12; l_count_16++) { ls_20 = "123456789012"; _llseek(li_8, l_count_16 * li_0, 0); _lread(li_8, ls_20, 12); ls_20 = StringSubstr(ls_20, 0); if (MarketInfo(ls_20, MODE_MARGINCALCMODE) == 0.0) { if (l_index_4 < ArraySize(gsa_344)) { gsa_344[l_index_4] = StringSubstr(ls_20, 0); l_index_4++; } } } _lclose(li_8); return (1); } string symbol_find(string as_0) { int li_36; string ls_44; string ls_8 = as_0; int l_str_len_16 = StringLen(ls_8); int li_20 = 0; string ls_ret_24 = ""; int l_count_32 = 0; while (li_20 != -1 && l_count_32 < 30) { l_count_32++; li_36 = StringFind(ls_8, ":", li_20); if (li_36 != -1) { ls_ret_24 = StringSubstr(ls_8, li_20, li_36 - li_20); li_20 = li_36 + 1; } else { ls_ret_24 = StringSubstr(ls_8, li_20, l_str_len_16 - li_20); li_20 = -1; } if (symbol_exists(ls_ret_24)) return (ls_ret_24); } if (StringLen(ls_ret_24) > 6) ls_ret_24 = StringSubstr(ls_ret_24, 0, 6); if (StringLen(ls_ret_24) < 6) return (""); if (StringLen(gsa_344[0]) == 0) get_symbol_list(); for (int li_40 = ArraySize(gsa_344); li_40 > 0; li_40--) { ls_44 = gsa_344[li_40 - 1]; if (StringLen(ls_44) != 0) { if (StringLen(ls_44) > 6) ls_44 = StringSubstr(ls_44, 0, 6); if (ls_ret_24 == ls_44) if (symbol_exists(gsa_344[li_40 - 1])) return (gsa_344[li_40 - 1]); } } return (""); } int AccurateInt(double ad_0) { return (MathRound(ad_0)); } bool str_starts(string as_0, string as_8) { return (cmp(StringSubstr(as_0, 0, StringLen(as_8)), as_8)); } string getErrorDescription(string as_0) { string ls_8; if (cmp(as_0, "ERROR:1001")) return ("1001 - NOT VALID USER ACOUNT."); if (cmp(as_0, "ERROR:1008")) return ("1008 - SIGNAL DOES NOT EXISTS."); if (cmp(as_0, "ERROR:1009")) return ("1009 - SIGNAL ID IS NOT VALID."); if (cmp(as_0, "ERROR:1021")) return ("1021 - NOT A VALID USER ACCOUNT."); if (cmp(as_0, "ERROR:1022")) return ("1022 - NOT A BUYER OF THIS PRODUCT."); if (cmp(as_0, "ERROR:1025")) return ("1025 - BUYER ACCESSING FROM OTHER IP."); if (StringFind(as_0, "ERROR:1026") > -1) { ls_8 = StringSubstr(as_0, 11, 0); return ("1026 - SIGNAL " + ls_8 + " IS SUSPENDED OR NOT ACTIVE."); } if (cmp(as_0, "ERROR:1027")) return ("1027 - you are running very old version of Rentasignal EA, we do not support this version anymore, please update your Rentasignal EA."); return (as_0); } string signal_id_add_to_list(int ai_0) { if (!signal_id_in_list(ai_0)) gs_316 = gs_316 + "@" + ai_0; return (""); } bool signal_id_in_list(int ai_0) { return (StringFind(gs_316, "@" + ai_0) != -1); } void message(string as_0) { gs_284 = gs_284 + as_0 + "\n"; } int priceToPips(string a_symbol_0, double ad_8) { int l_digits_16 = MarketInfo(a_symbol_0, MODE_DIGITS); return (MathPow(10, l_digits_16) * ad_8); } int type_RAS_to_metatrader(int ai_0) { int li_ret_4 = 0; if (ai_0 == 1) li_ret_4 = 0; if (ai_0 == 2) li_ret_4 = 1; if (ai_0 == 11) li_ret_4 = 2; if (ai_0 == 12) li_ret_4 = 4; if (ai_0 == 21) li_ret_4 = 3; if (ai_0 == 22) li_ret_4 = 5; return (li_ret_4); } string type_metatrader_to_RAS(int ai_0) { string ls_ret_4; switch (ai_0) { case 0: ls_ret_4 = "1"; break; case 1: ls_ret_4 = "2"; break; case 2: ls_ret_4 = "11"; break; case 4: ls_ret_4 = "12"; break; case 3: ls_ret_4 = "21"; break; case 5: ls_ret_4 = "22"; } return (ls_ret_4); } string OrderExpirationFormated() { if (OrderExpiration() == 0) return (""); return (formated_date(OrderExpiration())); } string get_csv_url(string as_0, bool ai_8 = TRUE) { double ld_72; double ld_80; double ld_88; string ls_unused_12 = ""; int l_digits_20 = MarketInfo(OrderSymbol(), MODE_DIGITS); string l_dbl2str_24 = ""; string l_dbl2str_32 = ""; string l_dbl2str_40 = ""; string l_dbl2str_48 = ""; string l_dbl2str_56 = ""; string ls_64 = "1"; if (OrderCloseTime() != 0) ls_64 = "0"; if (cmp(ls_64, "0") && OrderType() == OP_BUY || OrderType() == OP_SELL) { l_dbl2str_24 = DoubleToStr(OrderClosePrice(), l_digits_20); l_dbl2str_32 = DoubleToStr(OrderProfit(), 2); if (AccountCurrency() != "USD") l_dbl2str_32 = DoubleToStr(convertProfit(AccountCurrency(), OrderProfit(), OrderType(), OrderCloseTime()), 2); ld_72 = MathPow(10, l_digits_20) * OrderOpenPrice(); ld_80 = MathPow(10, l_digits_20) * OrderClosePrice(); ld_88 = ld_80 - ld_72; if (OrderType() == OP_SELL) ld_88 = -1.0 * ld_88; l_dbl2str_56 = DoubleToStr(ld_88, 0); l_dbl2str_40 = DoubleToStr(OrderCommission(), 4); l_dbl2str_48 = DoubleToStr(OrderSwap(), 4); } string l_ticket_96 = OrderTicket(); string ls_104 = seller_rentasignal_id; string ls_112 = type_metatrader_to_RAS(OrderType()); string l_dbl2str_120 = DoubleToStr(OrderLots(), 4); string l_symbol_128 = OrderSymbol(); string l_dbl2str_136 = DoubleToStr(OrderOpenPrice(), l_digits_20); string l_dbl2str_144 = DoubleToStr(OrderStopLoss(), l_digits_20); string l_dbl2str_152 = DoubleToStr(OrderTakeProfit(), l_digits_20); string ls_160 = OrderComment(); if (as_0 != "") ls_160 = as_0; string ls_168 = OrderExpirationFormated(); string ls_176 = "0"; string ls_184 = ""; if (!ai_8) l_dbl2str_32 = 0; return (l_ticket_96 + ";" + ls_104 + ";" + ls_112 + ";" + l_dbl2str_120 + ";" + l_symbol_128 + ";" + ls_64 + ";" + l_dbl2str_136 + ";" + l_dbl2str_144 + ";" + l_dbl2str_152 + ";" + ls_160 + ";" + ls_168 + ";" + ls_176 + ";" + ls_184 + ";" + l_dbl2str_24 + ";" + l_dbl2str_32 + ";" + l_dbl2str_56 + ";" + l_dbl2str_40 + ";" + l_dbl2str_48); } double convertProfit(string as_0, double ad_8, int ai_16, int ai_20) { int l_applied_price_52; int l_shift_56; string l_symbol_24 = ""; bool li_32 = FALSE; if (StringLen(as_0) > 3) as_0 = StringSubstr(as_0, 0, 3); if (as_0 == "JPY") { l_symbol_24 = "USDJPY"; li_32 = TRUE; } if (as_0 == "GBP") { l_symbol_24 = "GBPUSD"; li_32 = FALSE; } if (as_0 == "EUR") { l_symbol_24 = "EURUSD"; li_32 = FALSE; } if (as_0 == "USD") return (ad_8); if (l_symbol_24 == "") return (0); double ld_ret_36 = 0; double ld_44 = 0; if (TimeCurrent() - ai_20 > 60) { l_applied_price_52 = 4; l_shift_56 = iBarShift(l_symbol_24, PERIOD_M1, ai_20); ld_44 = iMA(l_symbol_24, PERIOD_M1, 1, 0, MODE_SMA, l_applied_price_52, l_shift_56); } else { if (ai_16 == 0) ld_44 = MarketInfo(l_symbol_24, MODE_BID); else ld_44 = MarketInfo(l_symbol_24, MODE_ASK); } if (li_32) { if (ld_44 > 0.0) ld_ret_36 = ad_8 / ld_44; } else ld_ret_36 = ld_44 * ad_8; return (ld_ret_36); } string formated_date(int ai_0) { return (TimeYear(ai_0) + "/" + TimeMonth(ai_0) + "/" + TimeDay(ai_0) + " " + TimeHour(ai_0) + ":" + TimeMinute(ai_0) + ":" + TimeSeconds(ai_0)); } bool file_write_binary(string a_name_0, string as_8) { int l_file_16 = FileOpen(a_name_0, FILE_BIN|FILE_WRITE); if (l_file_16 < 1) { message(a_name_0 + " not opened, the last error is " + GetLastError()); return (FALSE); } if (FileWriteString(l_file_16, as_8, StringLen(as_8)) < 0) { message(a_name_0 + " not opened, the last error is " + GetLastError()); FileClose(l_file_16); return (FALSE); } FileClose(l_file_16); return (TRUE); } void log(string as_0) { string l_name_12 = "ras_report_seller.csv"; if (buyer) l_name_12 = "ras_report_buyer.csv"; int l_file_8 = FileOpen(l_name_12, FILE_CSV|FILE_WRITE|FILE_READ, 9); if (l_file_8 < 1) { message(l_name_12 + " not found, the last error is " + GetLastError()); return; } if (!gi_76 && FileSize(l_file_8) > 2000000) { FileClose(l_file_8); l_file_8 = FileOpen(l_name_12, FILE_CSV|FILE_WRITE, 9); } FileSeek(l_file_8, 0, SEEK_END); FileWrite(l_file_8, formated_date(TimeCurrent()), gs_92, buyer_install_version, as_0); FileClose(l_file_8); } int order_is_filtered() { bool l_bool_0 = FALSE; string ls_4 = "," + seller_opt_filter_magic_number + ","; string ls_12 = "," + seller_opt_filter_comment + ","; if (cmp(seller_opt_filter_comment, "RENTASIGNAL*")) l_bool_0 = l_bool_0 || !str_starts(OrderComment(), "RENTASIGNAL_"); else { if (!cmp(seller_opt_filter_comment, "")) l_bool_0 = l_bool_0 || StringFind(ls_12, "," + OrderComment() + ",") == -1; else if (str_starts(OrderComment(), "RENTASIGNAL")) return (1); } if (!cmp(seller_opt_filter_magic_number, "")) l_bool_0 = l_bool_0 || StringFind(ls_4, "," + OrderMagicNumber() + ",") == -1; return (l_bool_0); } void http_send_orders_list() { string ls_0 = "http://" + gs_84 + "/add3.php"; log(ls_0); gi_216 = ForexTSD_StartPost(ls_0); g_datetime_220 = TimeCurrent(); ForexTSD_AddPostData(gi_216, "username", rentasignal_username); ForexTSD_AddPostData(gi_216, "key", rentasignal_password_key); ForexTSD_AddPostData(gi_216, "TerminalCompany", TerminalCompany()); ForexTSD_AddPostData(gi_216, "TerminalName", TerminalName()); ForexTSD_AddPostData(gi_216, "IsDemo", IsDemo()); ForexTSD_AddPostData(gi_216, "Account", AccountNumber()); ForexTSD_AddPostData(gi_216, "AccountCompany", AccountCompany()); ForexTSD_AddPostData(gi_216, "AccountCurrency", AccountCurrency()); ForexTSD_AddPostData(gi_216, "AccountLeverage", AccountLeverage()); ForexTSD_AddPostData(gi_216, "AccountBalance", AccountBalance()); ForexTSD_AddPostData(gi_216, "AccountEquity", AccountEquity()); ForexTSD_AddPostData(gi_216, "AccountProfit", AccountProfit()); ForexTSD_AddPostData(gi_216, "version", gs_92); ForexTSD_AddPostData(gi_216, "signal_id", seller_rentasignal_id); ForexTSD_AddPostData(gi_216, "date", formated_date(g_datetime_220)); ForexTSD_AddPostData(gi_216, "errors[]", gs_324); if (use_working_time_limitation && !time_condition()) ForexTSD_AddPostData(gi_216, "ea_not_working", 1); string ls_12 = ""; for (int l_index_8 = 0; l_index_8 < g_index_312; l_index_8++) { log("order=" + gsa_308[l_index_8]); ForexTSD_AddPostData(gi_216, "orders[]", gsa_308[l_index_8]); ls_12 = concatenate_md5(ls_12, gsa_308[l_index_8]); } ForexTSD_AddPostData(gi_216, "check", concatenate_md5(ls_12, "RAS")); ForexTSD_SendPost(gi_216); } string concatenate_md5(string as_0, string as_8) { ForexTSD_MD5String(as_0 + as_8); return /*(WARN)*/; } void seller_op() { int l_file_64; string ls_68; string ls_76; int l_str2int_84; int l_str2int_88; int l_str2int_92; string ls_96; int li_108; gs_324 = ""; int l_ind_counted_0 = IndicatorCounted(); int l_count_4 = 0; int l_count_8 = 0; int l_count_12 = 0; int li_16 = OrdersTotal(); int li_20 = li_16; string ls_24 = ""; string ls_32 = ""; string ls_40 = concatenate_md5("", "http://" + gs_84 + "/add3.php?name=" + rentasignal_username + "&pass=" + rentasignal_password_key); int li_48 = 1000; if (cmp(seller_opt_filter_comment, "RENTASIGNAL*")) li_48 = 1000; g_index_312 = 0; int l_count_52 = 0; int l_cmd_56 = 0; for (int l_pos_60 = 0; l_pos_60 < li_16 && l_count_4 < li_48; l_pos_60++) { if (OrderSelect(l_pos_60, SELECT_BY_POS) != FALSE) { l_count_52++; l_cmd_56 = OrderType(); if (!order_is_filtered() && l_cmd_56 == OP_BUY || l_cmd_56 == OP_SELL || l_cmd_56 == OP_BUYLIMIT || l_cmd_56 == OP_SELLLIMIT || l_cmd_56 == OP_BUYSTOP || l_cmd_56 == OP_SELLSTOP) { ls_32 = get_csv_url(""); if (!cmp(ls_32, "")) { l_count_4++; l_count_8++; if (AccountCurrency() != "USD") ls_40 = concatenate_md5(ls_40, "&orders[]=" + get_csv_url("", 0)); else ls_40 = concatenate_md5(ls_40, "&orders[]=" + ls_32); gsa_308[g_index_312] = ls_32; g_index_312++; } ls_24 = ls_24 + ls_32; } } } if (cmp(seller_opt_filter_comment, "RENTASIGNAL*")) { for (l_pos_60 = 1; l_pos_60 <= buyer_install_version; l_pos_60++) { l_file_64 = FileOpen("ras_buyer_partial" + l_pos_60 + ".txt", FILE_CSV|FILE_READ, "|"); if (l_file_64 >= 0) { ls_68 = ""; while (!FileIsEnding(l_file_64)) { ls_68 = FileReadString(l_file_64); ls_76 = StringSubstr(ls_68, 1); l_str2int_84 = StrToInteger(StringSubstr(ls_76, 0, StringFind(ls_76, "+"))); ls_76 = StringSubstr(ls_76, StringFind(ls_76, "+") + 1); l_str2int_88 = StrToInteger(StringSubstr(ls_76, 0, StringFind(ls_76, "-"))); l_str2int_92 = StrToInteger(StringSubstr(ls_76, StringFind(ls_76, "-") + 1)); if (OrderSelect(l_str2int_92, SELECT_BY_TICKET)) { ls_32 = get_csv_url("RENTASIGNAL_" + l_str2int_84 + "_" + l_str2int_88); if (!cmp(ls_32, "")) { l_count_12++; l_count_4++; if (OrderCloseTime() == 0) l_count_8++; if (AccountCurrency() != "USD") ls_40 = concatenate_md5(ls_40, "&orders[]=" + get_csv_url("RENTASIGNAL_" + l_str2int_84 + "_" + l_str2int_88, 0)); else ls_40 = concatenate_md5(ls_40, "&orders[]=" + ls_32); gsa_308[g_index_312] = ls_32; g_index_312++; } ls_24 = ls_24 + ls_32; } } FileClose(l_file_64); } } } li_16 = OrdersHistoryTotal(); li_48 = l_count_4 + 200; log("hist_total=" + li_16 + " open_o=" + l_count_8 + " part_o=" + l_count_12 + " limit=" + li_48); for (l_pos_60 = li_16 - 1; l_pos_60 >= 0 && l_count_4 < li_48; l_pos_60--) { if (OrderSelect(l_pos_60, SELECT_BY_POS, MODE_HISTORY)) { l_count_52++; l_cmd_56 = OrderType(); if (!order_is_filtered() || (str_starts(OrderComment(), "to #") || str_starts(OrderComment(), "from #") && OrderMagicNumber() > 0) && l_cmd_56 == OP_BUY || l_cmd_56 == OP_SELL || l_cmd_56 == OP_BUYLIMIT || l_cmd_56 == OP_SELLLIMIT || l_cmd_56 == OP_BUYSTOP || l_cmd_56 == OP_SELLSTOP) { ls_96 = ""; if (str_starts(OrderComment(), "to #") || str_starts(OrderComment(), "from #") && OrderMagicNumber() > 0) ls_96 = "RENTASIGNAL_" + OrderComment(); ls_32 = get_csv_url(ls_96); ls_24 = ls_24 + ls_32; if (!cmp(ls_32, "")) { l_count_4++; if (AccountCurrency() != "USD") ls_40 = concatenate_md5(ls_40, "&orders[]=" + get_csv_url(ls_96, 0)); else ls_40 = concatenate_md5(ls_40, "&orders[]=" + ls_32); gsa_308[g_index_312] = ls_32; g_index_312++; } } } } li_20 += li_16; if (l_count_52 == li_48 && li_20 > li_48) gs_324 = "Total processed=" + DoubleToStr(l_count_52, 0) + ";Total_orders=" + DoubleToStr(li_20, 0) + "; Limit=" + DoubleToStr(li_48, 0); int li_104 = IsConnected() && IsTradeAllowed() && !IsTradeContextBusy(); if (!cmp(ls_40, gs_272)) { g_count_280 = 0; gs_272 = ls_40; gi_216 = 0; } if (gi_216 == 0 && li_104 && l_count_52 > 0) { g_count_280++; log("http_send_orders_list=" + g_index_312); http_send_orders_list(); gs_332 = ""; } if (gi_216 != 0) { li_108 = ForexTSD_GetStatus(gi_216); if (li_108 == 1) { gs_332 = ForexTSD_GetResult(gi_216); log(gs_332 + "-" + gi_216); if (!cmp(gs_332, "OK")) gi_216 = 0; } if (li_108 == 0 && TimeCurrent() - g_datetime_220 > timeout) gi_216 = 0; if (li_108 == -1) gi_216 = 0; } if (StringLen(gs_332) == 0) { message("Trying to connect: " + gs_264 + " (" + g_count_280 + " times)"); return; } gs_248 = getErrorDescription(gs_332); gs_256 = formated_date(g_datetime_220); message("Result: " + gs_248 + " on " + gs_256 + "\n"); } int order_partial_close_any(int ai_0, int ai_4, double ad_8, string as_16, string as_24) { int l_str2int_32; int li_36; as_16 = StringSubstr(as_16, StringLen("from #")); while (as_16 != "") { l_str2int_32 = StrToInteger(as_16); li_36 = order_partial_close(ai_0, ai_4, ad_8, l_str2int_32, as_24); if (li_36 == 1) return (1); if (StringFind(as_16, "-") != -1) as_16 = StringSubstr(as_16, StringFind(as_16, "-") + 1); else as_16 = ""; } return (0); } int order_partial_close(int ai_0, int ai_4, double ad_8, int ai_16, string as_20) { int l_count_60; int l_ord_total_64; int l_file_72; bool li_28 = ras_select_order(ai_16); if (!li_28) li_28 = ras_select_partial_order(ai_16, as_20); if (!li_28) return (0); ad_8 = lots_normalize(ad_8, OrderSymbol(), 1); double l_ord_lots_32 = OrderLots(); double ld_40 = l_ord_lots_32 - ad_8; bool li_48 = FALSE; if (AccurateInt(100.0 * l_ord_lots_32) == AccurateInt(100.0 * ad_8) || !buyer_partial_closing) { ld_40 = 0; li_48 = TRUE; } if (AccurateInt(100.0 * ld_40) < AccurateInt(100.0 * MarketInfo(OrderSymbol(), MODE_MINLOT))) { ld_40 = 0; li_48 = TRUE; } log("partial_close=" + ld_40 + "(" + ((l_ord_lots_32 - ad_8)) + ")" + " ltzro=" + li_48 + " set=" + buyer_partial_closing); int l_ticket_52 = OrderTicket(); g_error_340 = 0; int li_56 = 0; if (!li_48) li_56 = close_order(l_ticket_52, ld_40); if (li_48 || li_56) { l_count_60 = 0; while (l_count_60 <= 100) { Sleep(100); l_count_60++; l_ord_total_64 = OrdersTotal(); for (int l_pos_68 = 0; l_pos_68 < l_ord_total_64; l_pos_68++) { if (OrderSelect(l_pos_68, SELECT_BY_POS) != FALSE) { if (cmp(OrderComment(), "from #" + l_ticket_52) || (li_48 && OrderTicket() == l_ticket_52)) { l_count_60 = 200; l_file_72 = FileOpen("ras_buyer_partial" + buyer_install_version + ".txt", FILE_WRITE|FILE_READ); if (l_file_72 < 0) { message("Error reading file ras_buyer_partial" + buyer_install_version + ".txt\n" + formated_date(TimeCurrent())); log("order_partial_close: Error reading file ras_buyer_partial" + buyer_install_version + ".txt"); return (0); } as_20 = "-" + ai_0 + "+" + ai_4 + "-" + OrderTicket() + "|"; FileSeek(l_file_72, 0, SEEK_END); FileWrite(l_file_72, as_20); FileClose(l_file_72); return (1); } } } } } return (0); } bool close_order(int a_ticket_0, double a_ord_lots_4 = 0.0) { bool li_ret_12; int l_error_16; if (IsTradeContextBusy() || !IsTradeAllowed()) { gi_228 = TRUE; return (FALSE); } if (OrderSelect(a_ticket_0, SELECT_BY_TICKET) != FALSE) { log("OrderClose ticket=" + a_ticket_0 + " lots=" + a_ord_lots_4 + " comment= " + OrderComment() + " f:" + buyer_opt_filter_signal); li_ret_12 = TRUE; if (AccurateInt(100.0 * a_ord_lots_4) == 0 || AccurateInt(100.0 * a_ord_lots_4) > AccurateInt(100.0 * OrderLots())) { a_ord_lots_4 = OrderLots(); log("OrderClose AccurateInt(lots*100)!= 0 new_lot=" + a_ord_lots_4); } if (OrderType() == OP_BUY) li_ret_12 = OrderClose(a_ticket_0, a_ord_lots_4, MarketInfo(OrderSymbol(), MODE_BID), 100, Red); else { if (OrderType() == OP_SELL) li_ret_12 = OrderClose(a_ticket_0, a_ord_lots_4, MarketInfo(OrderSymbol(), MODE_ASK), 100, Red); else li_ret_12 = OrderDelete(a_ticket_0); } if (!li_ret_12) { gi_228 = TRUE; l_error_16 = GetLastError(); if (l_error_16 != 146/* TRADE_CONTEXT_BUSY */) { ErrorAlert("Order " + a_ticket_0 + " Close Error: " + l_error_16 + " - " + ErrorDescription(l_error_16)); log("Order " + a_ticket_0 + " Close Error: " + l_error_16 + " - " + ErrorDescription(l_error_16)); } g_error_340 = l_error_16; } } return (li_ret_12); } void close_all_orders() { string ls_8; bool li_16; string ls_20; int l_ord_total_0 = OrdersTotal(); for (int l_pos_4 = 0; l_pos_4 < l_ord_total_0; l_pos_4++) { if (OrderSelect(l_pos_4, SELECT_BY_POS) != FALSE) { ls_8 = OrderComment(); if (str_starts(OrderComment(), "RENTASIGNAL")) { li_16 = TRUE; ls_20 = ""; if (!cmp(buyer_opt_filter_signal, "")) { li_16 = FALSE; ls_20 = ls_8; ls_20 = StringSubstr(ls_20, StringLen("RENTASIGNAL_"), StringLen(ls_20) - StringLen("RENTASIGNAL_")); ls_20 = StringSubstr(ls_20, 0, StringFind(ls_20, "_")); if (StringFind("," + buyer_opt_filter_signal + ",", "," + ls_20 + ",") != -1) li_16 = TRUE; else log("close_all: Not Closed, " + ls_8 + " not in filter " + buyer_opt_filter_signal + ": " + OrderTicket()); } if (li_16 && !cmp(gs_292, "")) { li_16 = FALSE; ls_20 = ls_8; ls_20 = StringSubstr(ls_20, StringLen("RENTASIGNAL_"), StringLen(ls_20) - StringLen("RENTASIGNAL_")); ls_20 = StringSubstr(ls_20, 0, StringFind(ls_20, "_")); if (StringFind("," + gs_292 + ",", "," + ls_20 + ",") == -1) li_16 = TRUE; else log("close_all: Not Closed, " + ls_8 + " in NA signals " + gs_292 + ": " + OrderTicket()); } if (li_16 && !cmp(gs_300, "")) { li_16 = FALSE; ls_20 = ls_8; ls_20 = StringSubstr(ls_20, StringLen("RENTASIGNAL_"), StringLen(ls_20) - StringLen("RENTASIGNAL_")); ls_20 = StringSubstr(ls_20, 0, StringFind(ls_20, "_")); if (StringFind("," + gs_300 + ",", "," + ls_20 + "," + OrderSymbol() + ",") == -1 && StringFind("," + gs_300 + ",", "," + ls_20 + ",All,") == -1) li_16 = TRUE; else log("close_all: Not Closed, " + ls_8 + " s=" + OrderSymbol() + " in paused filter " + gs_300 + ": " + OrderTicket()); } if (li_16) { log("close_all: Close " + OrderTicket()); close_order(OrderTicket()); l_pos_4--; } } } } close_partial_orders(""); } int ras_select_order(int a_magic_0) { int l_ord_total_4 = OrdersTotal(); for (int l_pos_8 = 0; l_pos_8 < l_ord_total_4; l_pos_8++) { if (OrderSelect(l_pos_8, SELECT_BY_POS) != FALSE) if (str_starts(OrderComment(), "RENTASIGNAL") && OrderMagicNumber() == a_magic_0) return (1); } return (0); } int ras_select_partial_order(int ai_0, string as_4) { string ls_16; int li_12 = StringFind(as_4, "+" + ai_0 + "-"); if (li_12 != -1) { ls_16 = StringSubstr(as_4, li_12 + StringLen("+" + ai_0 + "-")); ls_16 = StringSubstr(ls_16, 0, StringFind(ls_16, "|")); if (OrderSelect(StrToInteger(ls_16), SELECT_BY_TICKET) && OrderCloseTime() == 0) return (1); } return (0); } int ras_select_order_history(int a_magic_0) { int l_hist_total_4 = OrdersHistoryTotal(); for (int l_pos_8 = l_hist_total_4 - 1; l_pos_8 >= l_hist_total_4 - 15 && l_pos_8 > 0; l_pos_8--) { if (OrderSelect(l_pos_8, SELECT_BY_POS, MODE_HISTORY) != FALSE) { if (str_starts(OrderComment(), "RENTASIGNAL") && OrderMagicNumber() == a_magic_0) { log("RASHISTORY ALREADY EXISTS: " + a_magic_0 + " - " + OrderTicket()); return (1); } } } return (0); } void close_orders_not_in_string(string as_0) { string ls_16; bool li_24; string ls_28; int l_ord_total_8 = OrdersTotal(); for (int l_pos_12 = 0; l_pos_12 < l_ord_total_8; l_pos_12++) { if (OrderSelect(l_pos_12, SELECT_BY_POS) != FALSE) { ls_16 = OrderComment(); if (str_starts(ls_16, "RENTASIGNAL_")) { if (StringFind(as_0, "@" + OrderMagicNumber()) == -1) { li_24 = TRUE; ls_28 = ""; if (!cmp(buyer_opt_filter_signal, "")) { li_24 = FALSE; ls_28 = ls_16; ls_28 = StringSubstr(ls_28, StringLen("RENTASIGNAL_"), StringLen(ls_28) - StringLen("RENTASIGNAL_")); ls_28 = StringSubstr(ls_28, 0, StringFind(ls_28, "_")); if (StringFind("," + buyer_opt_filter_signal + ",", "," + ls_28 + ",") != -1) li_24 = TRUE; else log("Not Closed, " + ls_16 + " not in filter " + buyer_opt_filter_signal + ": " + OrderTicket()); } if (li_24 && !cmp(gs_292, "")) { li_24 = FALSE; ls_28 = ls_16; ls_28 = StringSubstr(ls_28, StringLen("RENTASIGNAL_"), StringLen(ls_28) - StringLen("RENTASIGNAL_")); ls_28 = StringSubstr(ls_28, 0, StringFind(ls_28, "_")); if (StringFind("," + gs_292 + ",", "," + ls_28 + ",") == -1) li_24 = TRUE; else log("close_all: Not Closed, " + ls_16 + " in NA signals " + gs_292 + ": " + OrderTicket()); } if (li_24 && !cmp(gs_300, "")) { li_24 = FALSE; ls_28 = ls_16; ls_28 = StringSubstr(ls_28, StringLen("RENTASIGNAL_"), StringLen(ls_28) - StringLen("RENTASIGNAL_")); ls_28 = StringSubstr(ls_28, 0, StringFind(ls_28, "_")); if (StringFind("," + gs_300 + ",", "," + ls_28 + "," + OrderSymbol() + ",") == -1 && StringFind("," + gs_300 + ",", "," + ls_28 + ",All,") == -1) li_24 = TRUE; else log("close_all: Not Closed, " + ls_16 + " s=" + OrderSymbol() + " in paused filter " + gs_300 + ": " + OrderTicket()); } if (li_24) { log("Close, order " + ls_16 + " not in string " + OrderTicket()); close_order(OrderTicket()); } } } } } close_partial_orders(as_0); } int close_partial_orders(string as_0) { int li_36; string ls_40; int l_str2int_48; int l_str2int_52; int l_str2int_56; string ls_60; bool li_68; int l_file_8 = FileOpen("ras_buyer_partial" + buyer_install_version + ".txt", FILE_BIN|FILE_READ); if (l_file_8 < 0) { log("close_partial_orders: Error reading file ras_buyer_partial" + buyer_install_version + ".txt"); return (0); } FileSeek(l_file_8, 0, SEEK_SET); string ls_12 = ""; if (FileSize(l_file_8) > 0) ls_12 = FileReadString(l_file_8, FileSize(l_file_8)); FileClose(l_file_8); string ls_20 = ""; string ls_28 = ""; while (ls_12 != "") { li_36 = StringFind(ls_12, "-"); ls_12 = StringSubstr(ls_12, li_36); li_36 = StringFind(ls_12, "|"); if (li_36 < 0) { ls_12 = ""; continue; } ls_20 = StringSubstr(ls_12, 0, li_36); if (StringLen(ls_12) > li_36) ls_12 = StringSubstr(ls_12, li_36 + 1); else ls_12 = ""; ls_40 = StringSubstr(ls_20, 1); l_str2int_48 = StrToInteger(StringSubstr(ls_40, 0, StringFind(ls_40, "+"))); ls_40 = StringSubstr(ls_40, StringFind(ls_40, "+") + 1); l_str2int_52 = StrToInteger(StringSubstr(ls_40, 0, StringFind(ls_40, "-"))); l_str2int_56 = StrToInteger(StringSubstr(ls_40, StringFind(ls_40, "-") + 1)); if (StringFind(ls_12, "-" + l_str2int_56 + "|") > 0) continue; if (OrderSelect(l_str2int_56, SELECT_BY_TICKET) && OrderCloseTime() == 0) { ls_60 = "-1"; if (str_starts(OrderComment(), "from #")) ls_60 = StringSubstr(OrderComment(), StringLen("from #")); if (StringFind(as_0, "@" + l_str2int_52) == -1) { li_68 = TRUE; if (!cmp(buyer_opt_filter_signal, "")) { li_68 = FALSE; if (StringFind("," + buyer_opt_filter_signal + ",", "," + l_str2int_48 + ",") != -1) li_68 = TRUE; else log("Partial Not Closed, " + ls_20 + " not in filter " + buyer_opt_filter_signal + ": " + ls_60); } if (li_68 && !cmp(gs_292, "")) { li_68 = FALSE; if (StringFind("," + gs_292 + ",", "," + l_str2int_48 + ",") == -1) li_68 = TRUE; else log("Partial Not Closed, " + ls_20 + " in NA signals " + gs_292 + ": " + ls_60); } if (li_68 && !cmp(gs_300, "")) { li_68 = FALSE; if (StringFind("," + gs_300 + ",", "," + l_str2int_48 + "," + OrderSymbol() + ",") == -1 && StringFind("," + gs_300 + ",", "," + l_str2int_48 + ",All,") == -1) li_68 = TRUE; else log("Partial Not Closed, " + ls_20 + " s=" + OrderSymbol() + " in paused " + gs_300 + ": " + ls_60); } if (li_68) { log("Partial Close, f:" + buyer_opt_filter_signal + " order " + l_str2int_52 + " not in string " + as_0 + " mn:" + ls_60 + " " + OrderTicket()); if (close_order(OrderTicket())) ls_20 = ""; } } } else ls_20 = ""; if (StringLen(ls_20) > 5) ls_28 = ls_28 + ls_20 + "|"; } l_file_8 = FileOpen("ras_buyer_partial" + buyer_install_version + ".txt", FILE_WRITE); if (l_file_8 < 0) { message("Error reading file ras_buyer_partial" + buyer_install_version + ".txt\n" + formated_date(TimeCurrent())); log("close_partial_orders_erite_2: Error reading file ras_buyer_partial" + buyer_install_version + ".txt"); return (0); } if (StringLen(ls_28) > 5) FileWrite(l_file_8, ls_28); FileClose(l_file_8); return (0); } void signal_id_add_all() { int l_ord_total_0 = OrdersTotal(); for (int l_pos_4 = 0; l_pos_4 < l_ord_total_0; l_pos_4++) { if (OrderSelect(l_pos_4, SELECT_BY_POS) != FALSE) if (str_starts(OrderComment(), "RENTASIGNAL_")) signal_id_add_to_list(OrderMagicNumber()); } } double lots_normalize(double ad_0, string a_symbol_8, int ai_16) { ai_16 = 0; int li_20 = 100.0 * (ad_0 * buyer_lots_multiplier); int li_24 = 100.0 * MarketInfo(a_symbol_8, MODE_MINLOT); log(a_symbol_8 + " minlot " + li_24); int li_28 = 100.0 * MarketInfo(a_symbol_8, MODE_LOTSTEP); log("lotstep " + li_28); if (li_20 > 100.0 * buyer_lots_max_per_trade) li_20 = 100.0 * buyer_lots_max_per_trade; if (li_20 < li_24 && !ai_16) li_20 = li_24; int li_32 = 0; if (li_28 != 0 && !ai_16) { li_32 = (li_20 - li_24) / li_28; li_20 = li_24 + li_28 * li_32; } ad_0 = li_20; ad_0 /= 100.0; log("ilots " + li_20); log("lots " + ad_0); return (ad_0); } int order_modify(double a_price_0, double a_price_8, double a_price_16, double ad_24, int a_datetime_32, bool ai_36 = FALSE) { int l_error_52; if (IsTradeContextBusy() || !IsTradeAllowed()) { gi_228 = TRUE; return (0); } double ld_40 = ad_24; ad_24 = lots_normalize(ad_24, OrderSymbol(), ai_36); log("OrderModify Try (" + OrderSymbol() + ") " + OrderTicket() + " -lt_inc:" + ld_40 + " -lt_fix:" + ad_24 + " -lot:" + OrderLots() + "- pr:" + a_price_0 + " - sl:" + a_price_8 + " - tp:" + a_price_16); bool li_ret_48 = FALSE; if (OrderType() == OP_BUY || OrderType() == OP_SELL) { if (AccurateInt(100.0 * OrderLots()) > AccurateInt(100.0 * ad_24)) { log("Order Close Modify orderLots=" + OrderLots() + " lot=" + ad_24); close_order(OrderTicket(), OrderLots() - ad_24); li_ret_48 = TRUE; } if (OrderStopLoss() != a_price_8 || OrderTakeProfit() != a_price_16 || OrderExpiration() != a_datetime_32) { li_ret_48 = TRUE; log("Order Modify Executed - (" + OrderSymbol() + ") " + OrderTicket() + " -pr:" + a_price_0 + " -sl:" + a_price_8 + " -tp:" + a_price_16); if (!OrderModify(OrderTicket(), OrderOpenPrice(), a_price_8, a_price_16, a_datetime_32, CLR_NONE)) { gi_228 = TRUE; li_ret_48 = FALSE; l_error_52 = GetLastError(); if (l_error_52 != 146/* TRADE_CONTEXT_BUSY */) { if (l_error_52 != 1/* NO_RESULT */) ErrorAlert("Order " + OrderTicket() + " Modify Error: " + l_error_52 + " - " + ErrorDescription(l_error_52)); log("OrderModify Error: " + l_error_52 + " - " + ErrorDescription(l_error_52)); } } } } else { if (OrderStopLoss() != a_price_8 || OrderTakeProfit() != a_price_16 || OrderOpenPrice() != a_price_0 || OrderExpiration() != a_datetime_32) { li_ret_48 = TRUE; log("Pending OrderModify Executed - (" + OrderSymbol() + ") " + OrderTicket() + " -pr:" + a_price_0 + " -sl:" + a_price_8 + " -tp:" + a_price_16 + " -ex=" + a_datetime_32); if (!OrderModify(OrderTicket(), a_price_0, a_price_8, a_price_16, a_datetime_32, CLR_NONE)) { gi_228 = TRUE; li_ret_48 = FALSE; l_error_52 = GetLastError(); if (l_error_52 != 146/* TRADE_CONTEXT_BUSY */) { if (l_error_52 != 1/* NO_RESULT */) { ErrorAlert("Pending Order " + OrderTicket() + " Modify Error: " + l_error_52 + " - " + ErrorDescription(l_error_52)); log("Pending OrderModify Error: " + l_error_52 + " - " + ErrorDescription(l_error_52)); } } } } } return (li_ret_48); } int order_create(int ai_0, int a_magic_4, int ai_8, string a_symbol_12, double a_price_20, double a_price_28, double a_price_36, double a_lots_44, int a_datetime_52) { double l_price_100; if (IsTradeContextBusy() || !IsTradeAllowed()) { gi_228 = TRUE; return (0); } a_lots_44 = lots_normalize(a_lots_44, a_symbol_12, 0); int l_cmd_56 = type_RAS_to_metatrader(ai_8); int l_spread_60 = MarketInfo(a_symbol_12, MODE_SPREAD); double ld_64 = priceToPips(a_symbol_12, iHigh(a_symbol_12, PERIOD_M1, iHighest(a_symbol_12, PERIOD_M1, MODE_HIGH, 3))) + l_spread_60; double ld_72 = priceToPips(a_symbol_12, iLow(a_symbol_12, PERIOD_M1, iLowest(a_symbol_12, PERIOD_M1, MODE_LOW, 3))) - l_spread_60; double ld_80 = priceToPips(a_symbol_12, a_price_20); bool li_ret_88 = FALSE; int l_ticket_92 = 0; int l_error_96 = 0; if (l_cmd_56 == OP_BUY || l_cmd_56 == OP_SELL) { if (ld_64 > ld_80 && ld_72 < ld_80) { l_price_100 = 0; if (l_cmd_56 == OP_BUY) l_price_100 = MarketInfo(a_symbol_12, MODE_ASK); else l_price_100 = MarketInfo(a_symbol_12, MODE_BID); if (!buyer_stp_broker || (a_price_28 == 0.0 && a_price_36 == 0.0)) l_ticket_92 = OrderSend(a_symbol_12, l_cmd_56, a_lots_44, l_price_100, 10, a_price_28, a_price_36, "RENTASIGNAL_" + ai_0 + "_" + a_magic_4, a_magic_4, a_datetime_52); else { l_ticket_92 = OrderSend(a_symbol_12, l_cmd_56, a_lots_44, l_price_100, 10, 0, 0, "RENTASIGNAL_" + ai_0 + "_" + a_magic_4, a_magic_4, a_datetime_52); if (l_ticket_92 != -1) if (OrderSelect(l_ticket_92, SELECT_BY_TICKET)) OrderModify(OrderTicket(), OrderOpenPrice(), a_price_28, a_price_36, a_datetime_52, CLR_NONE); } if (l_ticket_92 == -1) { gi_228 = TRUE; l_error_96 = GetLastError(); li_ret_88 = FALSE; if (l_error_96 != 146/* TRADE_CONTEXT_BUSY */) { ErrorAlert("OrderSend Error: " + l_error_96 + " - " + ErrorDescription(l_error_96)); log("OrderSend Error: received=" + l_error_96 + " - " + ErrorDescription(l_error_96) + " " + ld_80 + "max(" + ld_64 + ") min(" + ld_72 + ") in " + a_symbol_12 + " lot=" + a_lots_44 + "c=" + "RENTASIGNAL_" + ai_0 + "_" + a_magic_4); } } else { log("OrderSend sucessfull, lot=" + a_lots_44 + " p=" + l_price_100 + " s=" + a_symbol_12 + " c=RENTASIGNAL_" + ai_0 + "_" + a_magic_4); li_ret_88 = TRUE; } } else log("OrderSend Failed buy, pr_in_pips = " + ld_80 + "max(" + ld_64 + ") min(" + ld_72 + ") in " + a_symbol_12); } else { l_ticket_92 = OrderSend(a_symbol_12, l_cmd_56, a_lots_44, a_price_20, 10, a_price_28, a_price_36, "RENTASIGNAL_" + ai_0 + "_" + a_magic_4, a_magic_4, 0); if (l_ticket_92 == -1) { gi_228 = TRUE; l_error_96 = GetLastError(); if (l_error_96 != 146/* TRADE_CONTEXT_BUSY */) { ErrorAlert("Pending OrderSend Error: " + l_error_96 + " - " + ErrorDescription(l_error_96)); log("Pending OrderSend Error: " + l_error_96 + " - " + ErrorDescription(l_error_96) + " c=" + "RENTASIGNAL_" + ai_0 + "_" + a_magic_4); } } else { log("Pending OrderSend sucessfull: p=" + a_price_20 + " lots=" + a_lots_44 + " sl=" + a_price_28 + " tp=" + a_price_36 + " c=" + "RENTASIGNAL_" + ai_0 + "_" + a_magic_4 + " s=" + a_symbol_12); li_ret_88 = TRUE; } } return (li_ret_88); } void process_error_in_csv(string as_0) { if (StringLen(as_0) != 0) { if (cmp(as_0, "ERROR:1021")) message(gs_84 + ": 1021 - NOT VALID USER ACOUNT"); else { if (cmp(as_0, "ERROR:1022")) message(gs_84 + ": 1022 - YOU ARE NOT A BUYER OF THIS PRODUCT"); else { if (cmp(as_0, "ERROR:1023")) message(gs_84 + ": 1023 - NOT VALID MPID"); else { if (cmp(as_0, "ERROR:1024")) { message(gs_84 + ": 1024 - NO TRADES ACTIVE"); close_all_orders(); } else if (cmp(as_0, "ERROR:1025")) message(gs_84 + ": 1025 - ACCESSING TO THE SAME ACCOUNT FROM MULTIPLE LOCATIONS"); } } } } } int process_buy_orders() { int li_68; int li_72; int li_76; double ld_80; string ls_88; double ld_96; double ld_104; double ld_112; string ls_120; string ls_128; string ls_136; string ls_144; string ls_152; string ls_160; string ls_168; int l_str2time_176; bool l_bool_180; bool li_184; bool l_bool_188; int l_file_192; bool li_196; if (!IsTradeAllowed() || IsTradeContextBusy() || !IsConnected()) return (0); gi_232 = TRUE; gi_228 = FALSE; gs_292 = ""; gs_300 = ""; int l_file_0 = FileOpen("ras_buyer" + buyer_install_version + ".csv", FILE_CSV|FILE_READ, ";"); if (l_file_0 < 0) { message("Error reading file of signals\n" + formated_date(TimeCurrent())); return (0); } if (FileSize(l_file_0) < 30) { process_error_in_csv(FileReadString(l_file_0)); FileClose(l_file_0); return (0); } string ls_unused_4 = ""; int li_unused_12 = 0; string ls_16 = ""; string ls_24 = ""; log("---process_orders fs:" + FileSize(l_file_0) + " tn:" + TerminalName()); int l_count_32 = 0; int l_count_36 = 0; int li_40 = 0; int l_count_44 = 0; int l_count_48 = 0; int l_count_52 = 0; string ls_56 = ""; int l_count_64 = 0; while (!FileIsEnding(l_file_0) && l_count_64 < 1000) { l_count_64++; li_68 = FileReadNumber(l_file_0); li_72 = FileReadNumber(l_file_0); li_76 = FileReadNumber(l_file_0); ld_80 = FileReadNumber(l_file_0); ls_88 = FileReadString(l_file_0); ld_96 = FileReadNumber(l_file_0); ld_104 = FileReadNumber(l_file_0); ld_112 = FileReadNumber(l_file_0); ls_120 = FileReadString(l_file_0); ls_128 = FileReadString(l_file_0); ls_136 = FileReadString(l_file_0); ls_144 = FileReadString(l_file_0); ls_152 = FileReadString(l_file_0); ls_168 = FileReadString(l_file_0); if (ls_152 != "") ls_160 = symbol_find(ls_152); else ls_160 = symbol_find(ls_88); log("New nid=" + li_68 + " sid=" + li_72 + ": Aliases: " + ls_152 + " symbol:" + ls_160 + " ck:" + ls_168); if (cmp(ls_160, "") && !cmp(ls_152, "") && !cmp(ls_168, "RAS")) { if (StringFind(ls_56, ls_88) == -1) { if (StringLen(ls_56) > 0) ls_56 = ls_56 + "," + ls_88; else ls_56 = ls_88; } log("Symbols_error: " + ls_56); } l_str2time_176 = 0; if (StringLen(ls_128) > 0 && !cmp(ls_128, "0000-00-00 00:00:00")) l_str2time_176 = StrToTime(ls_128); l_bool_180 = li_76 == 1 || li_76 == 2 || li_76 == 11 || li_76 == 12 || li_76 == 21 || li_76 == 22; if (!cmp(ls_168, "RAS") || !l_bool_180 || ls_160 == "") { if (cmp(ls_168, "na_subscriptionRAS")) gs_292 = gs_292 + "," + li_68; if (cmp(ls_168, "pausedRAS")) { if (ls_160 != "") gs_300 = gs_300 + "," + li_68 + "," + ls_160; else gs_300 = gs_300 + "," + li_68 + "," + ls_88; } if (cmp(ls_168, "messageRAS")) message(ls_120); if (cmp(ls_168, "errorRAS")) process_error_in_csv(ls_120); } else { log("Processing: " + li_68 + " " + li_72 + " " + li_76 + " lot:" + ld_80 + " si:" + ls_160 + " pr:" + ld_96 + " sl:" + ld_104 + " tp:" + ld_112 + "cm:" + ls_120 + " expr:" + ls_128 + " chk:" + ls_168 + " em:" + ls_136 + " mdev:" + ls_144); l_count_32++; ls_16 = ls_16 + "@" + li_72; li_184 = ras_select_order(li_72); l_bool_188 = !li_184; if (!li_184) { if (ls_24 == "") { l_file_192 = FileOpen("ras_buyer_partial" + buyer_install_version + ".txt", FILE_WRITE|FILE_READ); if (l_file_192 < 0) { message("Error reading file ras_buyer_partial" + buyer_install_version + ".txt\n" + formated_date(TimeCurrent())); log("ras_select_partial_by_MagicNumber: Error reading file ras_buyer_partial" + buyer_install_version + ".txt\n" + formated_date(TimeCurrent())); } else { FileSeek(l_file_192, 0, SEEK_SET); ls_24 = FileReadString(l_file_192); FileClose(l_file_192); } if (ls_24 == "") ls_24 = "none"; } li_184 = ras_select_partial_order(li_72, ls_24); l_bool_188 = li_184; ls_16 = ls_16 + "@" + OrderMagicNumber(); } if (cmp(buyer_opt_filter_signal, "") || 1 || StringFind("," + buyer_opt_filter_signal + ",", "," + li_68 + ",") != -1) { if (li_184) { l_count_52++; li_40 += order_modify(ld_96, ld_104, ld_112, buyer_lots_max_per_trade, l_str2time_176, l_bool_188); } else { if (!ras_select_order_history(li_72) && !signal_id_in_list(li_72)) { g_error_340 = 0; li_196 = FALSE; if (str_starts(ls_120, "from #")) { if (order_partial_close_any(li_68, li_72, ld_80, ls_120, ls_24) == 1) { l_count_44++; li_196 = TRUE; ls_16 = ls_16 + "@" + OrderMagicNumber(); } } if (!li_196 && g_error_340 <= 1/* NO_RESULT */) { if (order_create(li_68, li_72, li_76, ls_160, ld_96, ld_104, ld_112, ld_80, l_str2time_176) == 0) l_count_48++; else l_count_44++; } else if (!li_196) l_count_48++; } else l_count_36++; } } } } if (l_count_36 > 0) message(l_count_36 + " orders were found as existed before."); if (li_40 > 0) message(li_40 + " orders have been modified."); if (l_count_44 > 0) message(l_count_44 + " orders have been created."); if (l_count_48 > 0) message(l_count_48 + " orders with very different price."); if (l_count_52 > 0) message(l_count_52 + " orders already exists."); if (!cmp(ls_56, "")) message(ls_56 + " doesn\'\'t exists"); log("Open Signals: " + ls_16); if (l_count_32 > 0) close_orders_not_in_string(ls_16); signal_id_add_all(); gi_224++; FileClose(l_file_0); return (l_count_32); } int buyer_op() { int li_8; string ls_12; string ls_20; string ls_0 = ""; gi_232 = FALSE; if (gi_216 != 0) { li_8 = ForexTSD_GetStatus(gi_216); if (li_8 == 1) { ls_0 = ForexTSD_GetResult(gi_216); gi_216 = 0; } } if (TimeCurrent() - 5 > g_datetime_244) { g_datetime_244 = TimeCurrent(); ls_12 = ""; if (gi_76) ls_12 = "&fraud=sup0rt3d"; ls_20 = "http://" + gs_84 + "/get3.php?trading_symbol=all&user=" + rentasignal_username + "&key=" + rentasignal_password_key + "&signals=" + buyer_opt_filter_signal + "&version=" + gs_92 + "&date=" + formated_date(TimeCurrent()) + ls_12; ForexTSD_GetUrl(ls_20); } if (StringLen(ls_0) > 0) if (file_write_binary("ras_buyer" + buyer_install_version + ".csv", ls_0)) gi_228 = TRUE; if (gi_228) return (process_buy_orders()); return (-1); } int start() { int li_0; gs_284 = ""; if (!power_on) message(gs_84 + " version " + gs_92 + " - power off"); else { if (!IsConnected()) message("There are no connection with your broker - " + formated_date(TimeCurrent())); else { if (!IsTradeAllowed()) message("Trade is not allowed - " + formated_date(TimeCurrent())); else { if (!IsDllsAllowed()) message("You have to enable import dll for this indicator" + formated_date(TimeCurrent())); else { if (StringLen(rentasignal_username) == 0 || StringLen(rentasignal_password_key) == 0) message("Please specify username and key\n" + formated_date(TimeCurrent())); else { if (buyer) { message(gs_84 + " version " + gs_92 + " - Buyer " + formated_date(TimeCurrent())); if (gi_80) message(process_buy_orders() + " orders processed"); else { li_0 = buyer_op(); if (gi_232) message(li_0 + " orders processed"); else return (0); } } else { message(gs_84 + " version " + gs_92 + " - Seller " + formated_date(TimeCurrent())); seller_op(); } } } } } } Comment(gs_284); return (0); }