#property copyright "Copyright © 2009 www.FXBora.com" #property link "mailto:ea@fxbora.com" #import "http51.dll" string httpGET(string a0, int& a1[]); #import string gs_76; string gs_84; extern string login = ""; extern string password = ""; bool gi_108 = FALSE; bool gi_112 = FALSE; extern double baseLotSize = 0.1; bool gi_124 = TRUE; extern int EmergencyStop = 100; extern int MaxPriceDifference = 5; extern bool autoSuffix = TRUE; extern string symbolSuffix = ""; extern bool sendEmail = FALSE; extern int IgnoreMagic1 = 0; extern int IgnoreMagic2 = 0; extern int IgnoreMagic3 = 0; bool gi_164 = FALSE; extern bool System1 = TRUE; extern bool System2 = FALSE; extern bool System3 = FALSE; string gs_180 = "1.87"; bool gi_188 = FALSE; int g_slippage_192 = 1; int gia_196[1]; int gi_200 = 3202; int gi_204 = 120; int gi_208 = 120; int gi_212 = 0; string gs_216 = ""; string gs_224 = "smartforexsignal.fxbora.com"; string gs_232 = ""; string gs_240 = "0123456789ABCDEF"; int init() { if (autoSuffix) symbolSuffix = StringSubstr(Symbol(), 6); gs_216 = authenticate(); return (0); } int deinit() { gs_76 = "action=logout&sid=" + URLEncode(gs_216); gs_84 = httpGET("http://" + gs_224 + "/get.php?" + gs_76, gia_196); return (0); } string authenticate() { gs_216 = ""; gs_76 = "action=auth&username=" + URLEncode(login) + "&password=" + URLEncode(password) + "&ver=" + URLEncode(gs_180) + "&sys="; if (System1) gs_76 = gs_76 + "1"; else gs_76 = gs_76 + "0"; if (System2) gs_76 = gs_76 + "1"; else gs_76 = gs_76 + "0"; if (System3) gs_76 = gs_76 + "1"; else gs_76 = gs_76 + "0"; gs_84 = httpGET("http://" + gs_224 + "/get.php?" + gs_76, gia_196); if (StringSubstr(gs_84, 0, 2) != "OK" && gia_196[0] == 200) { if (gs_84 == "MULTIPLE LOGIN") { Print("Authentication error: " + gs_84); gs_232 = "Multiple login!"; } if (gs_84 == "AUTHENTICATION FAILED") { Print("Authentication error: " + gs_84); gs_232 = "Authentication failed!"; } } else { if (gia_196[0] != 200) Print("Error connecting: " + gia_196[0]); else gs_216 = StringSubstr(gs_84, 3); } return (gs_216); } double PointValue(string a_symbol_0) { if (MarketInfo(a_symbol_0, MODE_DIGITS) < 4.0) return (0.01); return (0.0001); } string URLEncode(string as_0) { string ls_24; int li_32; int l_str_len_8 = StringLen(as_0); string l_str_concat_12 = ""; for (int li_20 = 0; li_20 < l_str_len_8; li_20++) { ls_24 = StringSubstr(as_0, li_20, 1); li_32 = StringGetChar(ls_24, 0); if ((li_32 > '/' && li_32 < ':') || (li_32 > '@' && li_32 < '[') || (li_32 > '`' && li_32 < '{')) l_str_concat_12 = StringConcatenate(l_str_concat_12, ls_24); else { if (li_32 == ' ') l_str_concat_12 = StringConcatenate(l_str_concat_12, "+"); else l_str_concat_12 = StringConcatenate(l_str_concat_12, "%", hex(li_32)); } } return (l_str_concat_12); } string hex(int ai_0) { string l_str_concat_4 = ""; int li_12 = ai_0 % 16; int li_16 = (ai_0 - li_12) / 16; if (li_16 > 15) l_str_concat_4 = StringConcatenate(hex(li_16), StringSubstr(gs_240, li_12, 1)); else l_str_concat_4 = StringConcatenate(StringSubstr(gs_240, li_16, 1), StringSubstr(gs_240, li_12, 1)); return (l_str_concat_4); } int start() { string ls_8; string ls_16; string l_symbol_24; string ls_32; int l_str2int_56; int l_error_72; int l_ticket_76; int l_magic_88; int l_str2int_92; int l_str2int_96; int l_str2int_100; int l_str2int_104; int l_str2int_108; int lia_112[500]; int l_str2int_128; double l_lots_144; double l_price_152; double l_price_160; double l_price_168; string ls_0 = ""; string ls_40 = ""; string ls_48 = ""; int li_60 = 0; int li_64 = 0; bool li_68 = FALSE; int l_index_80 = 0; int l_ticket_120 = 0; bool li_124 = FALSE; bool li_132 = FALSE; double l_price_136 = 0.0; double l_price_176 = 0; double l_price_184 = 0; if (IsTesting()) return (0); if (!IsDemo() && !gi_188 && 0) { Alert("This version only works with demo accounts"); gi_188 = TRUE; return (0); } if (gi_108 == TRUE) { if (gi_112 == TRUE) baseLotSize = NormalizeDouble(AccountEquity() / 1000.0, 1); else baseLotSize = NormalizeDouble(AccountEquity() / 10000.0, 1); } else { if (baseLotSize / 4.0 / MarketInfo(Symbol(), MODE_LOTSTEP) != MathRound(baseLotSize / 4.0 / MarketInfo(Symbol(), MODE_LOTSTEP)) && !gi_124) { gs_232 = "baseLotSize incorrect (you would be unable to open quarter position)"; gs_216 = ""; } } if (baseLotSize < 4.0 * MarketInfo(Symbol(), MODE_MINLOT) && !gi_124) { if (gi_108 == FALSE) gs_232 = "baseLotSize is set too low"; else gs_232 = "Your account balance is too low."; gs_216 = ""; } if (gs_216 != "") { gi_212 = FALSE; while (true) { ls_40 = ""; gs_76 = "action=get&time=" + TimeCurrent() + "&pid=" + URLEncode(gi_200) + "&sid=" + URLEncode(gs_216); gs_84 = httpGET("http://" + gs_224 + "/get.php?" + gs_76, gia_196); if (StringSubstr(gs_84, 0, 2) != "OK") { Print("Error occured! Status: " + gia_196[0] + ", Response: " + gs_84); li_132 = gia_196[0]; if (gs_84 == "AUTHENTICATION FAILED") { gs_216 = ""; gs_232 = "Authentication failed!"; break; } if (gs_84 == "SESSION EXPIRED") { gs_216 = ""; gs_232 = "Session expired!"; break; } if (gs_84 == "MULTIPLE LOGIN") { gs_216 = ""; gs_232 = "Multiple login!"; break; } } else { li_132 = FALSE; ls_0 = StringSubstr(gs_84, 3); l_str2int_56 = StrToInteger(StringSubstr(ls_0, 0, StringFind(ls_0, ";"))); ls_0 = StringSubstr(ls_0, StringFind(ls_0, ";") + 1); l_index_80 = 0; for (int l_count_192 = 0; l_count_192 < l_str2int_56; l_count_192++) { if (l_count_192 + 1 == l_str2int_56) li_60 = 0; else li_60 = StringFind(ls_0, "|"); ls_16 = StringSubstr(ls_0, 0, li_60); ls_0 = StringSubstr(ls_0, li_60 + 1); ls_8 = ls_16; li_64 = StringFind(ls_8, ";"); l_magic_88 = StrToInteger(StringSubstr(ls_8, 0, li_64)); ls_8 = StringSubstr(ls_8, li_64 + 1); li_64 = StringFind(ls_8, ";"); ls_8 = StringSubstr(ls_8, li_64 + 1); li_64 = StringFind(ls_8, ";"); l_str2int_92 = StrToInteger(StringSubstr(ls_8, 0, li_64)); ls_8 = StringSubstr(ls_8, li_64 + 1); li_64 = StringFind(ls_8, ";"); l_str2int_128 = StrToInteger(StringSubstr(ls_8, 0, li_64)); ls_8 = StringSubstr(ls_8, li_64 + 1); li_64 = StringFind(ls_8, ";"); l_str2int_96 = StrToInteger(StringSubstr(ls_8, 0, li_64)); ls_8 = StringSubstr(ls_8, li_64 + 1); li_64 = StringFind(ls_8, ";"); l_str2int_100 = StrToInteger(StringSubstr(ls_8, 0, li_64)); ls_8 = StringSubstr(ls_8, li_64 + 1); li_64 = StringFind(ls_8, ";"); l_symbol_24 = StringSubstr(ls_8, 0, li_64); l_symbol_24 = l_symbol_24 + symbolSuffix; ls_8 = StringSubstr(ls_8, li_64 + 1); li_64 = StringFind(ls_8, ";"); l_str2int_104 = StrToInteger(StringSubstr(ls_8, 0, li_64)); ls_8 = StringSubstr(ls_8, li_64 + 1); li_64 = StringFind(ls_8, ";"); l_lots_144 = baseLotSize * StrToDouble(StringSubstr(ls_8, 0, li_64)); ls_8 = StringSubstr(ls_8, li_64 + 1); li_64 = StringFind(ls_8, ";"); l_price_152 = NormalizeDouble(StrToDouble(StringSubstr(ls_8, 0, li_64)), MarketInfo(l_symbol_24, MODE_DIGITS)); ls_8 = StringSubstr(ls_8, li_64 + 1); li_64 = StringFind(ls_8, ";"); l_price_160 = NormalizeDouble(StrToDouble(StringSubstr(ls_8, 0, li_64)), MarketInfo(l_symbol_24, MODE_DIGITS)); ls_8 = StringSubstr(ls_8, li_64 + 1); li_64 = StringFind(ls_8, ";"); l_price_168 = NormalizeDouble(StrToDouble(StringSubstr(ls_8, 0, li_64)), MarketInfo(l_symbol_24, MODE_DIGITS)); ls_8 = StringSubstr(ls_8, li_64 + 1); li_64 = StringFind(ls_8, ";"); l_str2int_108 = StrToInteger(StringSubstr(ls_8, 0, li_64)); for (int l_pos_196 = OrdersTotal() - 1; l_pos_196 >= 0; l_pos_196--) { OrderSelect(l_pos_196, SELECT_BY_POS); if (OrderMagicNumber() == l_magic_88) { l_ticket_120 = OrderTicket(); break; } } if (l_ticket_120 == 0) { if (l_str2int_104 < OP_BUYLIMIT && l_str2int_96 > TimeCurrent() - gi_208) { RefreshRates(); if (l_str2int_104 == OP_SELL) { l_price_136 = MarketInfo(l_symbol_24, MODE_BID); if (l_price_160 == 0.0) l_price_160 = l_price_136 + PointValue(l_symbol_24) * EmergencyStop; if ((l_price_152 - l_price_136) / PointValue(l_symbol_24) > MaxPriceDifference) li_124 = TRUE; } else { if (l_str2int_104 == OP_BUY) { l_price_136 = MarketInfo(l_symbol_24, MODE_ASK); if (l_price_160 == 0.0) l_price_160 = l_price_136 - PointValue(l_symbol_24) * EmergencyStop; if ((l_price_136 - l_price_152) / PointValue(l_symbol_24) > MaxPriceDifference) li_124 = TRUE; } } if (!gi_164) { l_price_176 = l_price_160; l_price_184 = l_price_168; } else { l_price_176 = 0; l_price_184 = 0; } if (li_124 == FALSE && !IsTradeContextBusy()) { l_ticket_76 = OrderSend(l_symbol_24, l_str2int_104, l_lots_144, l_price_136, g_slippage_192, l_price_176, l_price_184, "", l_magic_88, l_str2int_108, CLR_NONE); if (l_ticket_76 != -1) { l_ticket_120 = l_ticket_76; if (gi_164) { OrderSelect(l_ticket_120, SELECT_BY_TICKET); OrderModify(OrderTicket(), OrderOpenPrice(), l_price_160, l_price_168, 0); } if (sendEmail) { if (l_str2int_104 == OP_SELL) ls_48 = "SELL"; if (l_str2int_104 == OP_BUY) ls_48 = "BUY"; ls_40 = ls_40 + "Order opened: Ticket #" + l_ticket_120 + " " + ls_48 + " " + DoubleToStr(l_lots_144, 2) + " " + l_symbol_24 + " @ " + DoubleToStr(l_price_136, MarketInfo(l_symbol_24, MODE_DIGITS)) + "\nSL: " + DoubleToStr(l_price_160, MarketInfo(l_symbol_24, MODE_DIGITS)) + ", TP: " + DoubleToStr(l_price_168, MarketInfo(l_symbol_24, MODE_DIGITS)) + "\n\n"; } } else { l_error_72 = GetLastError(); Print("error(", l_error_72, ")"); if (l_error_72 == 131/* INVALID_TRADE_VOLUME */) { gs_216 = ""; gs_232 = "Incorrect lot size"; break; } if (l_error_72 == 132/* MARKET_CLOSED */) Sleep(900); } } } } else { if (l_ticket_120 != 0) { OrderSelect(l_ticket_120, SELECT_BY_TICKET); if (OrderType() != l_str2int_104) { if (l_str2int_96 < TimeCurrent() - gi_204) OrderDelete(l_ticket_120); } else { if (l_lots_144 < OrderLots() && !IsTradeContextBusy()) { RefreshRates(); if (l_str2int_104 == OP_SELL) l_price_136 = MarketInfo(l_symbol_24, MODE_ASK); else if (l_str2int_104 == OP_BUY) l_price_136 = MarketInfo(l_symbol_24, MODE_BID); if (OrderClose(l_ticket_120, OrderLots() - l_lots_144, l_price_136, g_slippage_192, CLR_NONE)) { if (sendEmail) { if (l_str2int_104 == OP_SELL) ls_48 = "SELL"; if (l_str2int_104 == OP_BUY) ls_48 = "BUY"; ls_40 = ls_40 + "Order portion closed: Ticket #" + l_ticket_120 + " " + ls_48 + " " + DoubleToStr(OrderLots(), 2) + " (" + DoubleToStr(OrderLots() - l_lots_144, MarketInfo(OrderSymbol(), MODE_DIGITS)) + " closed) " + OrderSymbol() + " @ " + DoubleToStr(OrderOpenPrice(), MarketInfo(OrderSymbol(), MODE_DIGITS)) + " (closed @" + DoubleToStr(l_price_136, MarketInfo(OrderSymbol(), MODE_DIGITS)) + ")\nSL: " + DoubleToStr(OrderStopLoss(), MarketInfo(OrderSymbol(), MODE_DIGITS)) + ", TP: " + DoubleToStr(OrderTakeProfit(), MarketInfo(OrderSymbol(), MODE_DIGITS)) + "\n\n"; } } } if (OrderType() == OP_SELL && l_price_160 == 0.0) l_price_160 = OrderOpenPrice() + PointValue(l_symbol_24) * EmergencyStop; if (OrderType() == OP_BUY && l_price_160 == 0.0) l_price_160 = OrderOpenPrice() - PointValue(l_symbol_24) * EmergencyStop; if ((l_price_152 != OrderOpenPrice() && OrderType() > OP_SELL) || l_price_160 != OrderStopLoss() || l_price_168 != OrderTakeProfit() || l_str2int_108 != OrderExpiration()) { if (!IsTradeContextBusy()) { if (OrderModify(l_ticket_120, l_price_152, l_price_160, l_price_168, l_str2int_108)) { if (sendEmail) { if (OrderType() == OP_SELL) ls_48 = "SELL"; if (OrderType() == OP_BUY) ls_48 = "BUY"; ls_40 = ls_40 + "Order modified: Ticket #" + l_ticket_120 + " " + ls_48 + " " + DoubleToStr(OrderLots(), 2) + " " + OrderSymbol() + " @ " + DoubleToStr(OrderOpenPrice(), MarketInfo(OrderSymbol(), MODE_DIGITS)) + "\nSL: " + DoubleToStr(l_price_160, MarketInfo(OrderSymbol(), MODE_DIGITS)) + ", TP: " + DoubleToStr(l_price_168, MarketInfo(OrderSymbol(), MODE_DIGITS)) + "\n\n"; } } } } if (OrderType() == OP_SELL && l_price_160 == 0.0) l_price_160 = OrderOpenPrice() + PointValue(l_symbol_24) * EmergencyStop; if (OrderType() == OP_BUY && l_price_160 == 0.0) l_price_160 = OrderOpenPrice() - PointValue(l_symbol_24) * EmergencyStop; } } } li_64 = 0; l_price_136 = 0.0; li_124 = FALSE; l_ticket_120 = 0; lia_112[l_index_80] = l_magic_88; l_index_80++; } if (gs_216 == "") break; for (int l_pos_200 = OrdersTotal() - 1; l_pos_200 >= 0; l_pos_200--) { OrderSelect(l_pos_200, SELECT_BY_POS); for (int l_index_204 = 0; l_index_204 < l_index_80; l_index_204++) if (OrderMagicNumber() == lia_112[l_index_204]) li_68 = TRUE; if (li_68 == FALSE && OrderMagicNumber() != 0 && OrderMagicNumber() != IgnoreMagic1 && OrderMagicNumber() != IgnoreMagic2 && OrderMagicNumber() != IgnoreMagic3) { if (OrderType() > OP_SELL) { if (!IsTradeContextBusy()) OrderDelete(OrderTicket()); } else { if (!IsTradeContextBusy()) { RefreshRates(); if (OrderType() == OP_SELL) l_price_136 = MarketInfo(OrderSymbol(), MODE_ASK); else if (OrderType() == OP_BUY) l_price_136 = MarketInfo(OrderSymbol(), MODE_BID); if (!OrderClose(OrderTicket(), OrderLots(), l_price_136, g_slippage_192, CLR_NONE)) { l_error_72 = GetLastError(); Print("error(", l_error_72, ")"); if (l_error_72 == 131/* INVALID_TRADE_VOLUME */) { gs_216 = ""; gs_232 = "Incorrect lot size"; break; } if (l_error_72 == 132/* MARKET_CLOSED */) Sleep(900); } else { if (sendEmail) { if (OrderType() == OP_SELL) ls_48 = "SELL"; if (OrderType() == OP_BUY) ls_48 = "BUY"; ls_40 = ls_40 + "Order closed: Ticket #" + OrderTicket() + " " + ls_48 + " " + DoubleToStr(OrderLots(), 2) + " " + OrderSymbol() + " @ " + DoubleToStr(OrderOpenPrice(), MarketInfo(OrderSymbol(), MODE_DIGITS)) + " (closed @" + DoubleToStr(l_price_136, MarketInfo(OrderSymbol(), MODE_DIGITS)) + ")\n\n"; } } } } } else li_68 = FALSE; } } ls_32 = "\nVersion: " + gs_180 + "\nStatus: "; if (li_132 != FALSE) ls_32 = ls_32 + gs_84; else ls_32 = ls_32 + "Connected."; ls_32 = ls_32 + "\nUsername: " + login + "\nbaseLotSize: " + DoubleToStr(NormalizeDouble(baseLotSize, 2), 2) + "\nMaxPriceDifference: " + MaxPriceDifference + "\nEmergencyStop: " + EmergencyStop; if (sendEmail) { ls_32 = ls_32 + "\nEmail: enabled"; } else { ls_32 = ls_32 + "\nEmail: disabled"; } if (System1) { ls_32 = ls_32 + "\nSystem 1 enabled"; } if (System2) { ls_32 = ls_32 + "\nSystem 2 enabled"; } if (System3) { ls_32 = ls_32 + "\nSystem 3 enabled"; } Comment(ls_32); if (ls_40 != "") { SendMail("New activity on your account", ls_40); ls_40 = ""; } Sleep(1000); } } else { if (gs_232 == "Incorrect lot size" || gs_232 == "Authentication failed!" || gs_232 == "Multiple login!" || gs_232 == "baseLotSize is set too low" || gs_232 == "baseLotSize incorrect (you would be unable to open quarter position)") { if (gi_212 == FALSE) { Alert(gs_232); gi_212 = TRUE; } Comment("\nVersion: " + gs_180 + "\nStatus: " + gs_232); } else if (gs_232 == "Session expired!") gs_216 = authenticate(); } return (0); }