#property strict // Final 8 on 9 jan 2:56 #include #include #include CAppDialog OurInterface; #include CButton SetTPButton,SetSLButton; #include CEdit LotSize,LotSize2,LotSize3,SD,TP,SL,newTP,newSL; #include CLabel LotLabel,LotLabel2,LotLabel3,SDLabel,TPLabel,SLLabel; bool removeFromThisChartOnly = true; double TradeVolume1 = 1; double TradeVolume2 = 0.02; double TradeVolume3 = 0.03; double sd= 0; // Start Diffrence double sl = 500; double tp = 1000; double tsl= 0; double refsl = 500; double breakevensl=20; double booksomeprofitsl=200; int account=AccountNumber(); double newtp = 0; double newsl = 0; double MaxAccountBalance = AccountBalance(); double MinAccountBalance = 1000000; double InitialAccountBalance = AccountBalance(); int max_trades_same_type = 3; const string LotName = "Lot_Volume"; const string LotName2 = "Lot_Volume2"; const string LotName3 = "Lot_Volume3"; const string SD_Value = "SD_Value"; const string TP_Value = "TP_Value"; const string SL_Value = "SL_Value"; const string newTP_Value = "newTP_Value"; const string newSL_Value = "newSL_Value"; string symbols[]={"XAUUSD","XAGUSD","XTIUSD","USDJPY","EURJPY","GBPJPY","CADJPY","CHFJPY","USDCAD","AUDUSD", "EURUSD","EURGBP","EURNZD","GBPUSD","NZDCAD","GBPNZD","GBPAUD","EURAUD","NZDCHF"}; string sources[] ={"Own","Alex","GoldPro","GoldKiller","Gold2Pro"}; int count_symbols = ArraySize(symbols); int count_sources = ArraySize(sources); datetime timetostart = TimeCurrent(); datetime timetostart2 = TimeCurrent(); datetime timetostart3 = TimeCurrent(); CCustomBot bot; string InpToken= "8181067618:AAGqA6S1y59CG5JgxX-c2rcgEt0kvpgCBvY"; // UK Bot // string InpToken= "7207841516:AAEV7qVVTEkulc_2wPHMyOPIlAJFWj4gKqo"; // US Bot int check_telegram_updates = 2150; //miliseconds int capture_previous_update_id= 0; ulong chat_id = 0; int OnInit() { bot.Token(InpToken); // Random Number Generator MathSrand(GetTickCount()); EventSetMillisecondTimer(check_telegram_updates); telegram_to_mt4(); ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true); OurInterface.Create(0,"AutoTrading Bot v11.0",0,180,70,400,350); LotLabel.Create(0,"LotLabel",0,10,10,50,30); OurInterface.Add(LotLabel); LotLabel.Text("Lot Size:"); LotSize.Create(0,LotName,0,90,10,160,30); OurInterface.Add(LotSize); LotSize.Text(string(TradeVolume1)); LotLabel2.Create(0,"LotLabel2",0,10,40,50,60); OurInterface.Add(LotLabel2); LotLabel2.Text("Lot Size2:"); LotSize2.Create(0,LotName2,0,90,40,160,60); OurInterface.Add(LotSize2); LotSize2.Text(string(TradeVolume2)); LotLabel3.Create(0,"LotLabel3",0,10,70,50,90); OurInterface.Add(LotLabel3); LotLabel3.Text("Lot Size3:"); LotSize3.Create(0,LotName3,0,90,70,160,90); OurInterface.Add(LotSize3); LotSize3.Text(string(TradeVolume3)); SDLabel.Create(0,"SDLabel",0,10,100,50,120); OurInterface.Add(SDLabel); SDLabel.Text("SD:"); SD.Create(0,SD_Value,0,90,100,160,120); OurInterface.Add(SD); SD.Text(string(sd)); TPLabel.Create(0,"TPLabel",0,10,130,50,150); OurInterface.Add(TPLabel); TPLabel.Text("TP:"); TP.Create(0,TP_Value,0,90,130,160,150); OurInterface.Add(TP); TP.Text(string(tp)); SLLabel.Create(0,"SLLabel",0,10,160,50,180); OurInterface.Add(SLLabel); SLLabel.Text("SL:"); SL.Create(0,SL_Value,0,90,160,160,180); OurInterface.Add(SL); SL.Text(string(sl)); newTP.Create(0,newTP_Value,0,10,190,100,210); OurInterface.Add(newTP); newTP.Text(string(newtp)); newSL.Create(0,newSL_Value,0,10,220,100,240); OurInterface.Add(newSL); newSL.Text(string(newsl)); SetTPButton.Create(0,"SetTPButton",0,110,190,200,210); OurInterface.Add(SetTPButton); SetTPButton.Text("Set new TP"); SetSLButton.Create(0,"SetSLButton",0,110,220,200,240); OurInterface.Add(SetSLButton); SetSLButton.Text("Set new SL"); OurInterface.Run(); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { EventKillTimer(); // Kill the timer OurInterface.Destroy(reason); } void OnTick() { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP) { datetime ctm= TimeCurrent()-OrderOpenTime(); if (ctm>3600) { int OpenDelete = OrderDelete(OrderTicket()); }}}} if (TimeCurrent()-timetostart>10) { Print ("Checking All TP1/TP2/TP3 now"); timetostart=TimeCurrent(); long CID = ChartFirst(); while(CID>=0) { ObjectCreate (CID, "1TPSL_"+ChartSymbol(CID), OBJ_LABEL, 0,0,0); ObjectSetInteger (CID,"1TPSL_"+ChartSymbol(CID),OBJPROP_CORNER, CORNER_LEFT_UPPER); ObjectSetInteger (CID,"1TPSL_"+ChartSymbol(CID), OBJPROP_XDISTANCE,4); ObjectSetInteger (CID,"1TPSL_"+ChartSymbol(CID), OBJPROP_YDISTANCE,30); ObjectSetInteger (CID,"1TPSL_"+ChartSymbol(CID), OBJPROP_COLOR, clrBlack); ObjectSetInteger (CID,"1TPSL_"+ChartSymbol(CID), OBJPROP_FONTSIZE,8); ObjectCreate (CID, "2TPSL_"+ChartSymbol(CID), OBJ_LABEL, 0,0,0); ObjectSetInteger (CID,"2TPSL_"+ChartSymbol(CID),OBJPROP_CORNER, CORNER_LEFT_UPPER); ObjectSetInteger (CID,"2TPSL_"+ChartSymbol(CID), OBJPROP_XDISTANCE,4); ObjectSetInteger (CID,"2TPSL_"+ChartSymbol(CID), OBJPROP_YDISTANCE,45); ObjectSetInteger (CID,"2TPSL_"+ChartSymbol(CID), OBJPROP_COLOR, clrBlack); ObjectSetInteger (CID,"2TPSL_"+ChartSymbol(CID), OBJPROP_FONTSIZE,8); CID=ChartNext(CID); } // Gold Killer TP1,TP2 and TP3 updater for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderMagicNumber()!=0) { if(GetMagicSource(OrderMagicNumber())=="GoldKiller") { if (OrderType()==OP_BUY) { int filehandleGKR = FileOpen(IntegerToString(account)+"-GoldKiller-"+OrderSymbol()+"-Buy-TP1.txt",FILE_READ); double temp_tp1 = StringToDouble(FileReadString(filehandleGKR)); FileClose(filehandleGKR); filehandleGKR = FileOpen(IntegerToString(account)+"-GoldKiller-"+OrderSymbol()+"-Buy-TP2.txt",FILE_READ); double temp_tp2 = StringToDouble(FileReadString(filehandleGKR)); FileClose(filehandleGKR); filehandleGKR = FileOpen(IntegerToString(account)+"-GoldKiller-"+OrderSymbol()+"-Buy-TP3.txt",FILE_READ); double temp_tp3 = StringToDouble(FileReadString(filehandleGKR)); FileClose(filehandleGKR); filehandleGKR = FileOpen(IntegerToString(account)+"-GoldKiller-"+OrderSymbol()+"-Buy-SL.txt",FILE_READ); double temp_sl = StringToDouble(FileReadString(filehandleGKR)); FileClose(filehandleGKR); long ChID = GetChartIDSymbol(GetMagicSymbol(OrderMagicNumber())); ObjectSetString(ChID,"1TPSL_"+GetMagicSymbol(OrderMagicNumber()),OBJPROP_TEXT, GetMagicSource(OrderMagicNumber())+ "-"+GetMagicSymbol(OrderMagicNumber())+ "-"+GetMagicType(OrderMagicNumber())+ "-Price:"+TruncateNumber(DoubleToStr(OrderOpenPrice()))); ObjectSetString(ChID,"2TPSL_"+GetMagicSymbol(OrderMagicNumber()),OBJPROP_TEXT, "TP1:"+TruncateNumber(DoubleToStr(temp_tp1))+ ", TP2:"+TruncateNumber(DoubleToStr(temp_tp2))+ ", TP3:"+TruncateNumber(DoubleToStr(temp_tp3))+ ", SL:"+TruncateNumber(DoubleToStr(temp_sl))); if ((MarketInfo(OrderSymbol(),MODE_ASK))>temp_tp1 && temp_tp1>OrderStopLoss()) { double updatedsl = OrderOpenPrice()+(PipsToPrice(breakevensl, OrderSymbol())); if (updatedsl!=OrderStopLoss()) int Modify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); } if ((MarketInfo(OrderSymbol(),MODE_ASK))>temp_tp2 && temp_tp2>OrderStopLoss()) { double updatedsl = temp_tp1; if (updatedsl!=OrderStopLoss()) int Modify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); } if ((MarketInfo(OrderSymbol(),MODE_ASK))>((temp_tp2+temp_tp3)/2)&& temp_tp2>OrderStopLoss()) { double updatedsl = temp_tp2; if (updatedsl!=OrderStopLoss()) int Modify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); } } if (OrderType()==OP_SELL) { int filehandleGKR = FileOpen(IntegerToString(account)+"-GoldKiller-"+OrderSymbol()+"-Sell-TP1.txt",FILE_READ); double temp_tp1 = StringToDouble(FileReadString(filehandleGKR)); FileClose(filehandleGKR); filehandleGKR = FileOpen(IntegerToString(account)+"-GoldKiller-"+OrderSymbol()+"-Sell-TP2.txt",FILE_READ); double temp_tp2 = StringToDouble(FileReadString(filehandleGKR)); FileClose(filehandleGKR); filehandleGKR = FileOpen(IntegerToString(account)+"-GoldKiller-"+OrderSymbol()+"-Sell-TP3.txt",FILE_READ); double temp_tp3 = StringToDouble(FileReadString(filehandleGKR)); FileClose(filehandleGKR); filehandleGKR = FileOpen(IntegerToString(account)+"-GoldKiller-"+OrderSymbol()+"-Sell-SL.txt",FILE_READ); double temp_sl = StringToDouble(FileReadString(filehandleGKR)); FileClose(filehandleGKR); long ChID = GetChartIDSymbol(GetMagicSymbol(OrderMagicNumber())); ObjectSetString(ChID,"1TPSL_"+GetMagicSymbol(OrderMagicNumber()),OBJPROP_TEXT, GetMagicSource(OrderMagicNumber())+ "-"+GetMagicSymbol(OrderMagicNumber())+ "-"+GetMagicType(OrderMagicNumber())+ "-Price:"+TruncateNumber(DoubleToStr(OrderOpenPrice()))); ObjectSetString(ChID,"2TPSL_"+GetMagicSymbol(OrderMagicNumber()),OBJPROP_TEXT, "TP1:"+TruncateNumber(DoubleToStr(temp_tp1))+ ", TP2:"+TruncateNumber(DoubleToStr(temp_tp2))+ ", TP3:"+TruncateNumber(DoubleToStr(temp_tp3))+ ", SL:"+TruncateNumber(DoubleToStr(temp_sl))); if ((MarketInfo(OrderSymbol(),MODE_BID))0 && temp_tp10 && temp_tp20 && ((temp_tp2+temp_tp3)/2) AccountBalance()) MinAccountBalance = AccountBalance(); Comment ("Initial Account Balance was ",InitialAccountBalance,", Minimum Balance was ",MinAccountBalance,", Max Balance was ", MaxAccountBalance,", Current Balance is ",CurrentAccountBalance," and Current Equity is ",AccountEquity(), ""); } // End of On Tick void OnTimer() { // Print ("Timer is working"); // Open Symbol Chart for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { bool found = false; long ID = ChartFirst(); while(ID>=0) { if(ChartSymbol(ID)==OrderSymbol()) { found=true; break; } ID=ChartNext(ID); } if(!found) ChartOpen(OrderSymbol(),0); }} if (TimeCurrent()-timetostart2>60) { Print ("Trying to Close Chart not in use"); timetostart2=TimeCurrent(); // Chart Close bool found_chart = false; long ID_chart = ChartFirst(); ID_chart=ChartNext(ID_chart); while(ID_chart>=0) { found_chart = false; for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(ChartSymbol(ID_chart)==OrderSymbol() || ChartSymbol(ID_chart)=="XAUUSD") { found_chart=true; break; }}} if(!found_chart) ChartClose(ID_chart); ID_chart=ChartNext(ID_chart); } } if (TimeCurrent()-timetostart3>90) { timetostart3=TimeCurrent(); Print ("Trying to Close Files of TP and SL, not in use"); string file_name; // variable for storing file names string filter= StringConcatenate(IntegerToString(account),"*.txt"); // filter for searching the files string filenamecontents[]; bool found_order = false; string acc_num = IntegerToString(account); //--- receive the search handle in the local folder's root long search_handle=FileFindFirst(filter,file_name); //--- check if FileFindFirst() executed successfully if(search_handle!=INVALID_HANDLE) { //--- searching files in the loop do { found_order = false; StringSplit(file_name,StringGetCharacter("-", 0), filenamecontents); int count_filenamecontents = ArraySize(filenamecontents); if (count_filenamecontents>3) { string file_acc_num = filenamecontents[0]; string file_source = filenamecontents[1]; string file_sybm = filenamecontents[2]; string file_type = filenamecontents[3]; for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (acc_num == file_acc_num && GetMagicSource(OrderMagicNumber())==file_source && GetMagicSymbol(OrderMagicNumber())==filenamecontents[2] && GetMagicType(OrderMagicNumber())==filenamecontents[3]) { found_order = true; } }} if (found_order==false) { Print (file_name," has been deleted"); FileDelete(file_name); } } } while(FileFindNext(search_handle,file_name)); //--- close the search handle FileFindClose(search_handle); } } if(check_telegram_updates >= 2000) telegram_to_mt4(); else Alert("Get Updates Time in Millisecond Should be Greater"); int filehandle = FileOpen("update_id.txt",FILE_READ); int check_used_update_id = (int) (FileReadString(filehandle)); FileClose(filehandle); if(capture_previous_update_id > check_used_update_id) { Print ("New Message Received"); int filehandle1 = FileOpen("update_id.txt",FILE_WRITE|FILE_TXT); FileWriteString(filehandle1,IntegerToString(capture_previous_update_id)); FileClose(filehandle1); int filehandle2 = FileOpen("chat_id.txt",FILE_READ); string check_chat_id = FileReadString(filehandle2); FileClose(filehandle2); int filehandle3 = FileOpen("message_details.txt",FILE_READ|FILE_CSV); string check_message_complete = FileReadString(filehandle3); FileClose(filehandle3); check_message_complete = toUpper(check_message_complete); string check_message = check_message_complete; string reply_message = ""; string replymsg[]; StringReplace(check_message_complete,"MESSAGE_IS_REPLY_OF:","^"); StringSplit(check_message_complete,StringGetCharacter("^", 0), replymsg); int count_replymsg = ArraySize(replymsg); if (count_replymsg>1) { check_message = (replymsg[0]); reply_message = (replymsg[1]); } int trade_Own = StringFind(check_message,"MYOWN"); int trade_Alex = StringFind(check_message,"ALEX"); int trade_Alex2 = StringFind(check_message,"DAYTRADINGACADEMY"); int trade_GoldPro = StringFind(check_message,"GOLDPRO"); int trade_GoldKiller = StringFind(check_message,"GOLDKILLER"); StringReplace(check_message,"GOLDPRO","PRO"); StringReplace(check_message,"GOLDKILLER","KILLER"); StringReplace(check_message,"GOLD","XAUUSD"); StringReplace(check_message,"SILVER","XAGUSD"); StringReplace(check_message,"USOIL","XTIUSD"); StringReplace(check_message,"OIL","XTIUSD"); StringReplace(reply_message,"GOLD","XAUUSD"); StringReplace(reply_message,"SILVER","XAGUSD"); StringReplace(reply_message,"USOIL","XTIUSD"); StringReplace(reply_message,"OIL","XTIUSD"); string SymbolOrder = ""; count_symbols = ArraySize(symbols); for(int x=0;x=0) { if(ChartSymbol(ID)==SymbolOrder) { found=true; break; } ID=ChartNext(ID); } if(!found) ChartOpen(SymbolOrder,0); // Trade for Alex if (trade_Alex!=-1 || trade_Alex2!=-1) { Print("Message Received from Alex"); int order_buynow = StringFind(check_message,"BUY NOW"); int order_sellnow = StringFind(check_message,"SELL NOW"); int order_type_buy = StringFind(check_message,"BUY"); int order_type_sell = StringFind(check_message,"SELL"); int find_tp = StringFind(check_message,"TP"); int find_sl = StringFind(check_message,"SL"); int find_close = StringFind(check_message,"CLOSE"); int find_close_half = StringFind(check_message,"CLOSE HALF"); int find_close_half2 = StringFind(check_message,"CLOSING HALF"); int find_close_first_entry = StringFind(check_message,"CLOSE FIRST ENTRY"); int check_breakeven = StringFind(check_message,"BREAKEVEN"); int check_breakeven2 = StringFind(check_message,"POSITION TO BREAKEVEN"); int check_breakeven_now = StringFind(check_message,"BREAKEVEN NOW"); int check_set_breakeven = StringFind(check_message,"SET"); int find_full_order = StringFind(check_message,"@"); int changing_sl = StringFind(check_message,"CHANGING MY SL"); int changing_sl2 = StringFind(check_message,"CHANGE SL"); int add_layering = StringFind(check_message,"ADD LAYERING"); int cut_loss = StringFind(check_message,"CUT LOSS"); int close_all = StringFind(check_message,"CLOSE ALL"); int msg_len = StringLen(check_message); int MagicBuyAlex1 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 1); int MagicBuyAlex2 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 2); int MagicBuyAlex3 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 3); int MagicSellAlex1 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 1); int MagicSellAlex2 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 2); int MagicSellAlex3 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 3); if (SymbolOrder!="" && order_buynow!=-1 && order_type_buy!=-1 && CheckOpenOrders(MagicBuyAlex1)==false && CountBuyOpenOrders(SymbolOrder)==true) { if (CheckOpenOrders(MagicSellAlex1)==true) CloseAllOrders (MagicSellAlex1, SymbolOrder); if (CheckOpenOrders(MagicSellAlex2)==true) CloseAllOrders (MagicSellAlex2, SymbolOrder); if (CheckOpenOrders(MagicSellAlex3)==true) CloseAllOrders (MagicSellAlex3, SymbolOrder); double buyprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_ASK),4); double buy = buyprice; double slbuy = buyprice-PipsToPrice(sl, SymbolOrder); double tpbuy = buyprice+PipsToPrice(tp, SymbolOrder); int orderbuy = OrderSend (SymbolOrder,OP_BUY,TradeVolume1,buy,0,slbuy,tpbuy,NULL,MagicBuyAlex1,0,clrBlue); } if (SymbolOrder!="" && order_sellnow!=-1 && order_type_sell!=-1 && CheckOpenOrders(MagicSellAlex1)==false && CountSellOpenOrders(SymbolOrder)==true) { if (CheckOpenOrders(MagicBuyAlex1)==true) CloseAllOrders (MagicBuyAlex1, SymbolOrder); if (CheckOpenOrders(MagicBuyAlex2)==true) CloseAllOrders (MagicBuyAlex2, SymbolOrder); if (CheckOpenOrders(MagicBuyAlex3)==true) CloseAllOrders (MagicBuyAlex3, SymbolOrder); double sellprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_BID),4); double sell = sellprice; double slsell = sellprice+PipsToPrice(sl, SymbolOrder); double tpsell = sellprice-PipsToPrice(tp, SymbolOrder); int ordersell = OrderSend (SymbolOrder,OP_SELL,TradeVolume1,sell,0,slsell,tpsell,NULL,MagicSellAlex1,0,clrBlue); } if (SymbolOrder!="" && (order_buynow!=-1 || order_sellnow!=-1) && find_tp!=-1 && find_sl!=-1 && (CheckOpenOrders(MagicSellAlex1)==true || CheckOpenOrders(MagicBuyAlex1)==true)) { if (order_buynow!=-1) { if (CheckOpenOrders(MagicSellAlex1)==true) CloseAllOrders (MagicSellAlex1, SymbolOrder); if (CheckOpenOrders(MagicSellAlex2)==true) CloseAllOrders (MagicSellAlex2, SymbolOrder); if (CheckOpenOrders(MagicSellAlex3)==true) CloseAllOrders (MagicSellAlex3, SymbolOrder); } if(order_sellnow!=-1) { if (CheckOpenOrders(MagicBuyAlex1)==true) CloseAllOrders (MagicBuyAlex1, SymbolOrder); if (CheckOpenOrders(MagicBuyAlex2)==true) CloseAllOrders (MagicBuyAlex2, SymbolOrder); if (CheckOpenOrders(MagicBuyAlex3)==true) CloseAllOrders (MagicBuyAlex3, SymbolOrder); } string getnewsl[]; // An array to get strings StringReplace(check_message,"SL :","^"); StringReplace(check_message,"SL:","^"); StringSplit(check_message,StringGetCharacter("^", 0), getnewsl); int count_getnewsl = ArraySize(getnewsl); if (count_getnewsl>1) newsl = StringToDouble(getnewsl[1]); string getnewtp[]; StringReplace(check_message,"TP :","`"); StringReplace(check_message,"TP:","`"); StringReplace(check_message,"TP1:","`"); StringReplace(check_message,"TP1 :","`"); StringSplit(check_message,StringGetCharacter("`", 0), getnewtp); int count_getnewtp = ArraySize(getnewtp); if (count_getnewtp>1) newtp = StringToDouble(getnewtp[1]); for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderMagicNumber()== MagicBuyAlex1 || OrderMagicNumber()== MagicSellAlex1) { int Modify = OrderModify (OrderTicket(),OrderOpenPrice(),newsl,newtp,0,clrAqua); }}} double firstprice=0; double secondprice=0; string getfirstprice[]; // An array to get strings StringSplit(check_message,StringGetCharacter("@", 0), getfirstprice); int count_getfirstprice = ArraySize(getfirstprice); if (count_getfirstprice>1) StringSplit(getfirstprice[1],StringGetCharacter(",", 0), getfirstprice); count_getfirstprice = ArraySize(getfirstprice); if (count_getfirstprice>0) StringSplit(getfirstprice[0],StringGetCharacter("-", 0), getfirstprice); count_getfirstprice = ArraySize(getfirstprice); if (count_getfirstprice>0) firstprice = StringToDouble(getfirstprice[0]); string getsecondprice[]; // An array to get strings StringSplit(check_message,StringGetCharacter("-", 0), getsecondprice); int count_getsecondprice = ArraySize(getsecondprice); if (count_getsecondprice>1) StringSplit(getsecondprice[1],StringGetCharacter(",", 0), getsecondprice); count_getsecondprice = ArraySize(getsecondprice); if (count_getsecondprice>0) secondprice = StringToDouble(getsecondprice[0]); double newprice = firstprice; // (firstprice+secondprice)/2; double checkprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_ASK),4); if (order_type_buy!=-1 && CheckOpenOrders(MagicBuyAlex2)==false && CountBuyOpenOrders(SymbolOrder)==true) { if (newsl==0) newsl= newprice-PipsToPrice(sl, SymbolOrder); if (newtp==0) newtp= newprice+PipsToPrice(tp, SymbolOrder); if (newpricecheckprice) int newordersell=OrderSend (SymbolOrder,OP_SELLLIMIT,TradeVolume1,newprice,0,newsl,newtp,NULL,MagicSellAlex2,0,clrBlue); else int newordersell2=OrderSend (SymbolOrder,OP_SELL,TradeVolume1,newprice,0,newsl,newtp,NULL,MagicSellAlex2,0,clrBlue); Sleep (5000); }} if (add_layering!=-1 && (changing_sl!=-1 || changing_sl2!=-1)) { if (SymbolOrder=="") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(GetMagicSource (OrderMagicNumber())== "Alex") SymbolOrder= GetMagicSymbol (OrderMagicNumber()); }}} MagicBuyAlex1 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 1); MagicBuyAlex2 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 2); MagicBuyAlex3 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 3); MagicSellAlex1 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 1); MagicSellAlex2 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 2); MagicSellAlex3 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 3); double updatedsl=0; string getnewsl[]; StringReplace(check_message,"SL TO","^"); StringReplace(check_message,"AND YOU","^"); StringSplit(check_message,StringGetCharacter("^", 0), getnewsl); int count_getnewsl = ArraySize(getnewsl); if (count_getnewsl>1) updatedsl =StrToDouble(getnewsl[1]); for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderMagicNumber()== MagicBuyAlex2 && CountBuyOpenOrders(SymbolOrder)==true && updatedsl!=0) { double old_sl= OrderStopLoss(); double old_tp= OrderTakeProfit(); double buyprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_ASK),4); int orderbuy = OrderSend (SymbolOrder,OP_BUY,TradeVolume1,buyprice,0,updatedsl,old_tp,NULL,MagicBuyAlex3,0,clrBlue); } if(OrderMagicNumber()== MagicSellAlex2 && CountSellOpenOrders(SymbolOrder)==true && updatedsl!=0) { double old_sl= OrderStopLoss(); double old_tp= OrderTakeProfit(); double sellprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_BID),4); int ordersell = OrderSend (SymbolOrder,OP_SELL,TradeVolume1,sellprice,0,updatedsl,old_tp,NULL,MagicSellAlex3,0,clrBlue); } } } } // End Add Layering if (find_close_half!=-1 || find_close_half2!=-1 || find_close_first_entry!=-1 || (find_close!=-1 && check_breakeven!=-1)) { if (SymbolOrder=="") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(GetMagicSource (OrderMagicNumber())== "Alex") SymbolOrder= GetMagicSymbol (OrderMagicNumber()); }}} MagicBuyAlex1 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 1); MagicBuyAlex2 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 2); MagicBuyAlex3 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 3); MagicSellAlex1 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 1); MagicSellAlex2 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 2); MagicSellAlex3 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 3); if (CheckOpenOrders(MagicBuyAlex1)==true && CheckOpenOrders(MagicBuyAlex2)==true) CloseAllOrders (MagicBuyAlex2, SymbolOrder); if (CheckOpenOrders(MagicSellAlex1)==true && CheckOpenOrders(MagicSellAlex2)==true) CloseAllOrders (MagicSellAlex2, SymbolOrder); for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==OP_BUY && (OrderMagicNumber()== MagicBuyAlex1 || OrderMagicNumber()== MagicBuyAlex2 || OrderMagicNumber()== MagicBuyAlex3)) { double updatedsl = OrderOpenPrice()+(PipsToPrice(breakevensl, OrderSymbol())); int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); } if(OrderType()==OP_SELL && (OrderMagicNumber()== MagicSellAlex1 || OrderMagicNumber()== MagicSellAlex2 || OrderMagicNumber()== MagicSellAlex3)) { double updatedsl = OrderOpenPrice()-(PipsToPrice(breakevensl, OrderSymbol())); int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit() ,0,clrBlue); } } } } // End Close Half if (changing_sl!=-1 || changing_sl2!=-1) { if (SymbolOrder=="") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(GetMagicSource (OrderMagicNumber())== "Alex") SymbolOrder= GetMagicSymbol (OrderMagicNumber()); }}} MagicBuyAlex1 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 1); MagicBuyAlex2 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 2); MagicBuyAlex3 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 3); MagicSellAlex1 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 1); MagicSellAlex2 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 2); MagicSellAlex3 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 3); double updatedsl=0; string getnewsl[]; StringReplace(check_message,"SL TO","^"); StringReplace(check_message,"AND YOU","^"); StringSplit(check_message,StringGetCharacter("^", 0), getnewsl); int count_getnewsl = ArraySize(getnewsl); if (count_getnewsl>1) updatedsl =StrToDouble(getnewsl[1]); for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==OP_BUY && updatedsl!=0 && (OrderMagicNumber()== MagicBuyAlex1 || OrderMagicNumber()== MagicBuyAlex2 || OrderMagicNumber()== MagicBuyAlex3)) { if ((OrderStopLoss()-updatedsl)<(PipsToPrice(refsl, OrderSymbol()))) { int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); } } if(OrderType()==OP_SELL && updatedsl!=0 && (OrderMagicNumber()== MagicSellAlex1 || OrderMagicNumber()== MagicSellAlex2 || OrderMagicNumber()== MagicSellAlex3)) { if ((updatedsl-OrderStopLoss())<(PipsToPrice(refsl, OrderSymbol()))) { int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit() ,0,clrBlue); } } } } } // End Changing SL if ((check_breakeven!=-1 && check_set_breakeven!=-1) || check_breakeven2!=-1 || check_breakeven_now!=-1) { if (SymbolOrder=="") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(GetMagicSource (OrderMagicNumber())== "Alex") SymbolOrder= GetMagicSymbol (OrderMagicNumber()); }}} MagicBuyAlex1 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 1); MagicBuyAlex2 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 2); MagicBuyAlex3 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 3); MagicSellAlex1 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 1); MagicSellAlex2 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 2); MagicSellAlex3 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 3); for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==OP_BUY && (OrderMagicNumber()== MagicBuyAlex1 || OrderMagicNumber()== MagicBuyAlex2 || OrderMagicNumber()== MagicBuyAlex3)) { double updatedsl = OrderOpenPrice()+(PipsToPrice(breakevensl, OrderSymbol())); int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); } if(OrderType()==OP_SELL && (OrderMagicNumber()== MagicSellAlex1 || OrderMagicNumber()== MagicSellAlex2 || OrderMagicNumber()== MagicSellAlex3)) { double updatedsl = OrderOpenPrice()-(PipsToPrice(breakevensl, OrderSymbol())); int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit() ,0,clrBlue); } } } } // End Breakeven Only if (cut_loss!=-1 || close_all!=-1) { if (SymbolOrder=="") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(GetMagicSource (OrderMagicNumber())== "Alex") SymbolOrder= GetMagicSymbol (OrderMagicNumber()); }}} MagicBuyAlex1 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 1); MagicBuyAlex2 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 2); MagicBuyAlex3 = CreateMagicNumber("Alex", SymbolOrder, "Buy", 3); MagicSellAlex1 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 1); MagicSellAlex2 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 2); MagicSellAlex3 = CreateMagicNumber("Alex", SymbolOrder, "Sell", 3); if (CheckOpenOrders(MagicBuyAlex1)==true) CloseAllOrders (MagicBuyAlex1, SymbolOrder); if (CheckOpenOrders(MagicBuyAlex2)==true) CloseAllOrders (MagicBuyAlex2, SymbolOrder); if (CheckOpenOrders(MagicBuyAlex2)==true) CloseAllOrders (MagicBuyAlex2, SymbolOrder); if (CheckOpenOrders(MagicSellAlex1)==true) CloseAllOrders (MagicSellAlex1, SymbolOrder); if (CheckOpenOrders(MagicSellAlex2)==true) CloseAllOrders (MagicSellAlex2, SymbolOrder); if (CheckOpenOrders(MagicSellAlex2)==true) CloseAllOrders (MagicSellAlex2, SymbolOrder); } } // End Alex // Trade for Gold Pro Traders if (trade_GoldPro!=-1) { Print("Message Received from GoldPro"); int order_type_buy = StringFind(check_message,"BUY"); int order_type_sell = StringFind(check_message,"SELL"); int find_tp = StringFind(check_message,"TP"); int find_sl = StringFind(check_message,"SL"); int find_close = StringFind(check_message,"CLOSE"); int find_hold = StringFind(check_message,"HOLD"); int find_entry = StringFind(check_message,"ENTRY"); int find_close_all = StringFind(check_message,"CLOSE ALL"); int find_book_some_profit = StringFind(check_message,"BOOK SOME PROFIT"); int find_limit = StringFind(check_message,"LIMIT"); int changing_sl = StringFind(check_message,"UPDATE SL"); int changing_sl2 = StringFind(check_message,"SAME TP"); int find_hyphen = StringFind(check_message,"-"); int find_dot = StringFind(check_message,"."); int find_complete = StringFind(check_message,"COMPLETE"); int find_completely = StringFind(check_message,"COMPLETELY"); int find_hit = StringFind(check_message,"HIT"); int close_sixty = StringFind(check_message,"60%"); int close_eighty = StringFind(check_message,"80%"); int check_running = StringFind(check_message,"80%"); int check_boom = StringFind(check_message,"80%"); int close_buy_gold = StringFind(check_message,"CLOSE BUY XAUUSD"); int close_gold_buy = StringFind(check_message,"CLOSE XAUUSD BUY"); int close_sell_gold = StringFind(check_message,"CLOSE SELL XAUUSD"); int close_gold_sell = StringFind(check_message,"CLOSE XAUUSD SELL"); int move_sl = StringFind(check_message,"MOVE SL"); int MagicBuyGoldPro1 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 1); int MagicBuyGoldPro2 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 2); int MagicBuyGoldPro3 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 3); int MagicSellGoldPro1 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 1); int MagicSellGoldPro2 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 2); int MagicSellGoldPro3 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 3); // Start Gold Pro Orders if (SymbolOrder!="" && order_type_buy!=-1 && find_limit==-1 && (find_dot!=-1 || find_hyphen!=-1) && (check_running==-1 || check_boom==-1) && CheckOpenOrders(MagicBuyGoldPro1)==false && CountBuyOpenOrders(SymbolOrder)==true) { if (CheckOpenOrders(MagicSellGoldPro1)==true) CloseAllOrders (MagicSellGoldPro1, SymbolOrder); if (CheckOpenOrders(MagicSellGoldPro2)==true) CloseAllOrders (MagicSellGoldPro2, SymbolOrder); if (CheckOpenOrders(MagicSellGoldPro3)==true) CloseAllOrders (MagicSellGoldPro3, SymbolOrder); double buyprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_ASK),4); double buy = buyprice; double slbuy = buyprice-PipsToPrice(sl, SymbolOrder); double tpbuy = buyprice+PipsToPrice(tp, SymbolOrder); int orderbuy = OrderSend (SymbolOrder,OP_BUY,TradeVolume1,buy,0,slbuy,tpbuy,NULL,MagicBuyGoldPro1,0,clrBlue); } if (SymbolOrder!="" && order_type_sell!=-1 && find_limit==-1 && (find_dot!=-1 || find_hyphen!=-1) && (check_running==-1 || check_boom==-1) && CheckOpenOrders(MagicSellGoldPro1)==false && CountSellOpenOrders(SymbolOrder)==true) { if (CheckOpenOrders(MagicBuyGoldPro1)==true) CloseAllOrders (MagicBuyGoldPro1, SymbolOrder); if (CheckOpenOrders(MagicBuyGoldPro2)==true) CloseAllOrders (MagicBuyGoldPro2, SymbolOrder); if (CheckOpenOrders(MagicBuyGoldPro3)==true) CloseAllOrders (MagicBuyGoldPro3, SymbolOrder); double sellprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_BID),4); double sell = sellprice; double slsell = sellprice+PipsToPrice(sl, SymbolOrder); double tpsell = sellprice-PipsToPrice(tp, SymbolOrder); int ordersell = OrderSend (SymbolOrder,OP_SELL,TradeVolume1,sell,0,slsell,tpsell,NULL,MagicSellGoldPro1,0,clrBlue); } if (SymbolOrder!="" && (order_type_buy!=-1 ||order_type_sell!=-1) && find_tp!=-1 && find_sl!=-1) { if (order_type_buy!=-1) { if (CheckOpenOrders(MagicSellGoldPro1)==true) CloseAllOrders (MagicSellGoldPro1, SymbolOrder); if (CheckOpenOrders(MagicSellGoldPro2)==true) CloseAllOrders (MagicSellGoldPro2, SymbolOrder); if (CheckOpenOrders(MagicSellGoldPro3)==true) CloseAllOrders (MagicSellGoldPro3, SymbolOrder); } if (order_type_sell!=-1) { if (CheckOpenOrders(MagicBuyGoldPro1)==true) CloseAllOrders (MagicBuyGoldPro1, SymbolOrder); if (CheckOpenOrders(MagicBuyGoldPro2)==true) CloseAllOrders (MagicBuyGoldPro2, SymbolOrder); if (CheckOpenOrders(MagicBuyGoldPro3)==true) CloseAllOrders (MagicBuyGoldPro3, SymbolOrder); } string prices =""; double firstprice =0; double secondprice =0; string getsecondpricest=""; double tp1=0; double tp2=0; double tp3=0; string gettpst=""; string checkdots[]; string getprice[]; string getprice2[]; string getfirstprice[]; StringReplace(check_message,"BUY ","^"); StringReplace(check_message,"SELL ","^"); StringReplace(check_message,"BUY","^"); StringReplace(check_message,"SELL","^"); StringSplit(check_message,StringGetCharacter("^", 0), getprice); int count_getprice = ArraySize(getprice); if (count_getprice>1) StringSplit(getprice[1],StringGetCharacter(",", 0), getprice2); int count_getprice2 = ArraySize(getprice2); if (count_getprice2>0) { StringSplit(getprice2[0],StringGetCharacter(".", 0), checkdots); int count_checkdots = ArraySize(checkdots); if (count_checkdots<3) StringReplace(getprice2[0],".","-"); StringReplace(getprice2[0],"/","-"); StringReplace(getprice2[0]," ","-"); prices = getprice2[0]; StringSplit(prices,StringGetCharacter("-", 0), getfirstprice); int count_getfirstprice = ArraySize(getfirstprice); if (count_getfirstprice>0) firstprice = StringToDouble(getfirstprice[0]); if (count_getfirstprice>1) secondprice = StringToDouble(getfirstprice[1]); } double buyorderprice=firstprice; double sellorderprice=secondprice; string gettp[]; // An array to get strings StringReplace(check_message,"^","-"); StringReplace(check_message,",TP","^"); StringSplit(check_message,StringGetCharacter("^", 0), gettp); int count_gettp = ArraySize(gettp); string gettp3[]; if (count_gettp>3) StringSplit(gettp[3],StringGetCharacter(",", 0), gettp3); int count_gettp3 = ArraySize(gettp3); if (count_gettp>1) tp1 = StringToDouble(gettp[1]); if (count_gettp>2) tp2 = StringToDouble(gettp[2]); if (count_gettp3>0) tp3 = StringToDouble(gettp3[0]); string getnewsl[]; // An array to get strings StringReplace(check_message,"SL","<"); StringSplit(check_message,StringGetCharacter("<", 0), getnewsl); int count_getnewsl = ArraySize(getnewsl); if (count_getnewsl>1) newsl = StringToDouble(getnewsl[1]); if (order_type_buy!=-1 && CheckOpenOrders(MagicBuyGoldPro1)==true) { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderMagicNumber()== MagicBuyGoldPro1 && tp1!=0 && newsl!=0) { int Modify = OrderModify (OrderTicket(),OrderOpenPrice(),newsl,tp1,0,clrAqua); }}}} if (order_type_buy!=-1 && CheckOpenOrders(MagicBuyGoldPro2)==false && tp2!=0 && newsl!=0) { double buyprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_ASK),4); if (firstprice>secondprice) buyorderprice = secondprice; if (buyorderprice=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderMagicNumber()== MagicSellGoldPro1) { int Modify = OrderModify (OrderTicket(),OrderOpenPrice(),newsl,tp1,0,clrAqua); }}}} if (order_type_sell!=-1 && CheckOpenOrders(MagicSellGoldPro2)==false && tp2!=0 && newsl!=0) { double sellprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_BID),4); if (firstprice>secondprice) sellorderprice = firstprice; if (sellorderprice>sellprice && CountSellOpenOrders(SymbolOrder)==true) int newordersell=OrderSend (SymbolOrder,OP_SELLLIMIT,TradeVolume1,sellorderprice,0,newsl,tp2,NULL,MagicSellGoldPro2,0,clrBlue); } // End of Sale Order Gold Pro } // End of Orders if (((find_hold!=-1 || find_entry!=-1)) || find_book_some_profit!=-1) // find_close!=-1 && { if (SymbolOrder=="") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(GetMagicSource (OrderMagicNumber())== "GoldPro") SymbolOrder= GetMagicSymbol (OrderMagicNumber()); }}} MagicBuyGoldPro1 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 1); MagicBuyGoldPro2 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 2); MagicBuyGoldPro3 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 3); MagicSellGoldPro1 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 1); MagicSellGoldPro2 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 2); MagicSellGoldPro3 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 3); if (CheckOpenOrders(MagicBuyGoldPro1)==true && CheckOpenOrders(MagicBuyGoldPro2)==true) CloseAllOrders (MagicBuyGoldPro1, SymbolOrder); if (CheckOpenOrders(MagicSellGoldPro1)==true && CheckOpenOrders(MagicSellGoldPro2)==true) CloseAllOrders (MagicSellGoldPro1, SymbolOrder); for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==OP_BUY && OrderSymbol()==SymbolOrder && OrderMagicNumber()== MagicBuyGoldPro1) { double updatedsl = Ask-(PipsToPrice(booksomeprofitsl, OrderSymbol())); if (updatedslOrderOpenPrice()) updatedsl = OrderOpenPrice()-(PipsToPrice(breakevensl, OrderSymbol())); int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit() ,0,clrBlue); } if(OrderType()==OP_SELL && OrderSymbol()==SymbolOrder && (OrderMagicNumber()== MagicSellGoldPro2 || OrderMagicNumber()== MagicSellGoldPro3) ) { double updatedsl = OrderOpenPrice()-(PipsToPrice(breakevensl, OrderSymbol())); int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit() ,0,clrBlue); } } } } // End Close Half // Start of 60% or 80% Close if (close_sixty!=-1 || close_eighty!=-1) { if (SymbolOrder=="") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(GetMagicSource (OrderMagicNumber())== "GoldPro") SymbolOrder= GetMagicSymbol (OrderMagicNumber()); }}} MagicBuyGoldPro1 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 1); MagicBuyGoldPro2 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 2); MagicBuyGoldPro3 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 3); MagicSellGoldPro1 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 1); MagicSellGoldPro2 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 2); MagicSellGoldPro3 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 3); if (CheckOpenOrders(MagicBuyGoldPro1)==true) CloseAllOrders (MagicBuyGoldPro1, SymbolOrder); if (CheckOpenOrders(MagicSellGoldPro1)==true) CloseAllOrders (MagicSellGoldPro1, SymbolOrder); for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==OP_BUY && OrderSymbol()==SymbolOrder && OrderMagicNumber()== MagicBuyGoldPro2) { double updatedsl = OrderOpenPrice()+(PipsToPrice(breakevensl, OrderSymbol())); int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); updatedsl = OrderOpenPrice()+(PipsToPrice(500, OrderSymbol())); int BuyModify2 = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); updatedsl = OrderOpenPrice()+(PipsToPrice(1000, OrderSymbol())); int BuyModify3 = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); } if(OrderType()==OP_SELL && OrderSymbol()==SymbolOrder && OrderMagicNumber()== MagicSellGoldPro2) { double updatedsl = OrderOpenPrice()-(PipsToPrice(breakevensl, OrderSymbol())); int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit() ,0,clrBlue); updatedsl = OrderOpenPrice()-(PipsToPrice(500, OrderSymbol())); int SellModify2 = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit() ,0,clrBlue); updatedsl = OrderOpenPrice()-(PipsToPrice(1000, OrderSymbol())); int SellModify3 = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit() ,0,clrBlue); } } } } // 60% or 80% Close if (changing_sl!=-1 || changing_sl2!=-1 || move_sl!=-1 || (find_tp==-1 && find_sl!=-1)) { if (SymbolOrder=="") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(GetMagicSource (OrderMagicNumber())== "GoldPro") SymbolOrder= GetMagicSymbol (OrderMagicNumber()); }}} MagicBuyGoldPro1 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 1); MagicBuyGoldPro2 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 2); MagicBuyGoldPro3 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 3); MagicSellGoldPro1 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 1); MagicSellGoldPro2 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 2); MagicSellGoldPro3 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 3); double updatedsl = 0; string getnewsl[]; StringReplace(check_message,"SL","^"); StringSplit(check_message,StringGetCharacter("^", 0), getnewsl); int count_getnewsl = ArraySize(getnewsl); if (count_getnewsl>1) updatedsl =StrToDouble(getnewsl[1]); for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==OP_BUY && updatedsl!=0 && (OrderMagicNumber()== MagicBuyGoldPro1 || OrderMagicNumber()== MagicBuyGoldPro2 || OrderMagicNumber()== MagicBuyGoldPro3)) { if ((OrderStopLoss()-updatedsl)<(PipsToPrice(refsl, OrderSymbol()))) { int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); } } if(OrderType()==OP_SELL && updatedsl!=0 && (OrderMagicNumber()== MagicSellGoldPro1 || OrderMagicNumber()== MagicSellGoldPro2 || OrderMagicNumber()== MagicSellGoldPro3)) { if ((updatedsl-OrderStopLoss())<(PipsToPrice(refsl, OrderSymbol()))) { int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit() ,0,clrBlue); } } } } } // End Changing SL // Start of Close Completely if (find_complete!=-1 || find_completely!=-1 || find_close_all!=-1) { if (SymbolOrder=="") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(GetMagicSource (OrderMagicNumber())== "GoldPro") SymbolOrder= GetMagicSymbol (OrderMagicNumber()); }}} MagicBuyGoldPro1 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 1); MagicBuyGoldPro2 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 2); MagicBuyGoldPro3 = CreateMagicNumber("GoldPro", SymbolOrder, "Buy", 3); MagicSellGoldPro1 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 1); MagicSellGoldPro2 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 2); MagicSellGoldPro3 = CreateMagicNumber("GoldPro", SymbolOrder, "Sell", 3); if (CheckOpenOrders(MagicBuyGoldPro1)==true) CloseAllOrders (MagicBuyGoldPro1, SymbolOrder); if (CheckOpenOrders(MagicBuyGoldPro2)==true) CloseAllOrders (MagicBuyGoldPro2, SymbolOrder); if (CheckOpenOrders(MagicBuyGoldPro3)==true) CloseAllOrders (MagicBuyGoldPro3, SymbolOrder); if (CheckOpenOrders(MagicSellGoldPro1)==true) CloseAllOrders (MagicSellGoldPro1, SymbolOrder); if (CheckOpenOrders(MagicSellGoldPro2)==true) CloseAllOrders (MagicSellGoldPro2, SymbolOrder); if (CheckOpenOrders(MagicSellGoldPro3)==true) CloseAllOrders (MagicSellGoldPro3, SymbolOrder); } // End of Close Completely if (close_buy_gold!=-1 || close_gold_buy!=-1) { if (CheckOpenOrders(MagicBuyGoldPro1)==true) CloseAllOrders (MagicBuyGoldPro1, SymbolOrder); if (CheckOpenOrders(MagicBuyGoldPro2)==true) CloseAllOrders (MagicBuyGoldPro2, SymbolOrder); if (CheckOpenOrders(MagicBuyGoldPro3)==true) CloseAllOrders (MagicBuyGoldPro3, SymbolOrder); } if (close_sell_gold!=-1 || close_gold_sell!=-1) { if (CheckOpenOrders(MagicSellGoldPro1)==true) CloseAllOrders (MagicSellGoldPro1, SymbolOrder); if (CheckOpenOrders(MagicSellGoldPro2)==true) CloseAllOrders (MagicSellGoldPro2, SymbolOrder); if (CheckOpenOrders(MagicSellGoldPro3)==true) CloseAllOrders (MagicSellGoldPro3, SymbolOrder); } // Start of TP1 TP2 TP3 working if (find_tp!=-1 && find_hit!=-1) { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==OP_BUY && (OrderMagicNumber()== MagicBuyGoldPro2 || OrderMagicNumber()== MagicBuyGoldPro3)) { double updatedsl = OrderOpenPrice()+(PipsToPrice(breakevensl, OrderSymbol())); int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); } } } for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==OP_BUY && OrderMagicNumber()== MagicBuyGoldPro3 && CheckOpenOrders(MagicBuyGoldPro2)==false) { double updatedsl = OrderOpenPrice()+(PipsToPrice(500, OrderSymbol())); int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); updatedsl = OrderOpenPrice()+(PipsToPrice(1000, OrderSymbol())); int BuyModify2 = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit(),0,clrAqua); } } } for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==OP_SELL && (OrderMagicNumber()== MagicSellGoldPro2 || OrderMagicNumber()== MagicSellGoldPro3)) { double updatedsl = OrderOpenPrice()-(PipsToPrice(breakevensl, OrderSymbol())); int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit() ,0,clrBlue); } } } for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==OP_SELL && OrderMagicNumber()== MagicSellGoldPro3 && CheckOpenOrders(MagicSellGoldPro2)==false) { double updatedsl = OrderOpenPrice()-(PipsToPrice(500, OrderSymbol())); int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit() ,0,clrBlue); updatedsl = OrderOpenPrice()-(PipsToPrice(1000, OrderSymbol())); int SellModify2 = OrderModify (OrderTicket(),OrderOpenPrice(),updatedsl,OrderTakeProfit() ,0,clrBlue); } } } } // End of TP1 TP2 TP3 working } // End for Gold Trader Pro // Trade for GoldKiller if (trade_GoldKiller!=-1) { Print("Message Received from GoldKiller"); if (SymbolOrder!="") { Print ("Symbol Order available for GoldKiller"); int order_type_buy = StringFind(check_message,"BUY"); int order_type_sell = StringFind(check_message,"SELL"); int find_tp = StringFind(check_message,"TP"); int find_sl = StringFind(check_message,"SL"); int MagicBuyGoldKiller1 = CreateMagicNumber("GoldKiller", SymbolOrder, "Buy", 1); int MagicBuyGoldKiller2 = CreateMagicNumber("GoldKiller", SymbolOrder, "Buy", 2); int MagicBuyGoldKiller3 = CreateMagicNumber("GoldKiller", SymbolOrder, "Buy", 3); int MagicSellGoldKiller1 = CreateMagicNumber("GoldKiller", SymbolOrder, "Sell", 1); int MagicSellGoldKiller2 = CreateMagicNumber("GoldKiller", SymbolOrder, "Sell", 2); int MagicSellGoldKiller3 = CreateMagicNumber("GoldKiller", SymbolOrder, "Sell", 3); string gettype[]; string getprice[]; string getpricelast[]; string getsecondprice[]; StringReplace(check_message,"BUY","^"); StringReplace(check_message,"SELL","^"); StringReplace(check_message,"TP","~"); StringReplace(check_message,"SL","`"); StringSplit(check_message,StringGetCharacter("^", 0), gettype); string getslar; string gettp1ar; string gettp2ar; string gettp3ar; double price=0; double secondprice=0; string fprice; int count_gettype = ArraySize(gettype); if (count_gettype>1) StringSplit(gettype[1],StringGetCharacter("~", 0), getprice); int count_getprice = ArraySize(getprice); if (count_getprice>1) { price = StringToDouble(getprice[0]); int find_slash = StringFind(getprice[0],"/"); if (find_slash!=-1) StringSplit(getprice[0],StringGetCharacter("/", 0), getsecondprice); int count_getsecondprice = ArraySize(getsecondprice); if (count_getsecondprice>1) { fprice = StringSubstr(getsecondprice[0],6,4); price = StringToDouble(fprice); secondprice = StringToDouble(getsecondprice[1]); } if (price==0) price = StringToDouble(StringSubstr(getprice[0],6,4)); } if (count_getprice>1) gettp1ar = getprice[1]; if (count_getprice>2) gettp2ar = getprice[2]; if (count_getprice>6) gettp2ar = getprice[4]; if (count_getprice>1) StringSplit(getprice[count_getprice-1],StringGetCharacter("`", 0), getpricelast); int count_getpricelast = ArraySize(getpricelast); if (count_getpricelast>0) gettp3ar = getpricelast[0]; if (count_getpricelast>1) getslar = getpricelast[1]; // getprice[5]; string gettp1[]; StringSplit(gettp1ar,StringGetCharacter(",", 0), gettp1); string gettp2[]; StringSplit(gettp2ar,StringGetCharacter(",", 0), gettp2); string gettp3[]; StringSplit(gettp3ar,StringGetCharacter(",", 0), gettp3); string getsl[]; StringSplit(getslar,StringGetCharacter(",", 0), getsl); int count_gettp1 = ArraySize(gettp1); int count_gettp2 = ArraySize(gettp2); int count_gettp3 = ArraySize(gettp3); int count_getsl = ArraySize(getsl); if (order_type_buy!=-1) { if (count_getsl>0) { int filehandleGK = FileOpen(IntegerToString(account)+"-GoldKiller-"+SymbolOrder+"-Buy-SL.txt",FILE_WRITE|FILE_TXT); FileWriteString(filehandleGK,DoubleToString(StringToDouble(getsl[0]))); FileClose(filehandleGK); } if (count_gettp1>0) { int filehandleGK = FileOpen(IntegerToString(account)+"-GoldKiller-"+SymbolOrder+"-Buy-TP1.txt",FILE_WRITE|FILE_TXT); FileWriteString(filehandleGK,DoubleToString(StringToDouble(gettp1[0]))); FileClose(filehandleGK); } if (count_gettp2>0) { int filehandleGK = FileOpen(IntegerToString(account)+"-GoldKiller-"+SymbolOrder+"-Buy-TP2.txt",FILE_WRITE|FILE_TXT); FileWriteString(filehandleGK,DoubleToString(StringToDouble(gettp2[0]))); FileClose(filehandleGK); } if (count_gettp3>0) { int filehandleGK = FileOpen(IntegerToString(account)+"-GoldKiller-"+SymbolOrder+"-Buy-TP3.txt",FILE_WRITE|FILE_TXT); FileWriteString(filehandleGK,DoubleToString(StringToDouble(gettp3[0]))); FileClose(filehandleGK); } } if (order_type_sell!=-1) { if (count_getsl>0) { int filehandleGK = FileOpen(IntegerToString(account)+"-GoldKiller-"+SymbolOrder+"-Sell-SL.txt",FILE_WRITE|FILE_TXT); FileWriteString(filehandleGK,DoubleToString(StringToDouble(getsl[0]))); FileClose(filehandleGK); } if (count_gettp1>0) { int filehandleGK = FileOpen(IntegerToString(account)+"-GoldKiller-"+SymbolOrder+"-Sell-TP1.txt",FILE_WRITE|FILE_TXT); FileWriteString(filehandleGK,DoubleToString(StringToDouble(gettp1[0]))); FileClose(filehandleGK); } if (count_gettp2>0) { int filehandleGK = FileOpen(IntegerToString(account)+"-GoldKiller-"+SymbolOrder+"-Sell-TP2.txt",FILE_WRITE|FILE_TXT); FileWriteString(filehandleGK,DoubleToString(StringToDouble(gettp2[0]))); FileClose(filehandleGK); } if (count_gettp3>0) { int filehandleGK = FileOpen(IntegerToString(account)+"-GoldKiller-"+SymbolOrder+"-Sell-TP3.txt",FILE_WRITE|FILE_TXT); FileWriteString(filehandleGK,DoubleToString(StringToDouble(gettp3[0]))); FileClose(filehandleGK); } } double checkbuyprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_ASK),4); double checksellprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_BID),4); if (SymbolOrder!="" && order_type_buy!=-1 && (find_tp!=-1 || find_sl!=-1) && CheckOpenOrders(MagicBuyGoldKiller1)==false && CountBuyOpenOrders(SymbolOrder)==true) { if (CheckOpenOrders(MagicSellGoldKiller1)==true) CloseAllOrders (MagicSellGoldKiller1, SymbolOrder); if (CheckOpenOrders(MagicSellGoldKiller2)==true) CloseAllOrders (MagicSellGoldKiller2, SymbolOrder); if (CheckOpenOrders(MagicSellGoldKiller3)==true) CloseAllOrders (MagicSellGoldKiller3, SymbolOrder); double buyprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_ASK),4); double buy = buyprice; double slbuy = buyprice-PipsToPrice(sl, SymbolOrder); double tpbuy = buyprice+PipsToPrice(tp, SymbolOrder); int orderbuy = OrderSend (SymbolOrder,OP_BUY,TradeVolume1,buy,0,slbuy,tpbuy,NULL,MagicBuyGoldKiller1,0,clrBlue); } if (SymbolOrder!="" && order_type_sell!=-1 && (find_tp!=-1 || find_sl!=-1) && CheckOpenOrders(MagicSellGoldKiller1)==false && CountSellOpenOrders(SymbolOrder)==true) { if (CheckOpenOrders(MagicBuyGoldKiller1)==true) CloseAllOrders (MagicBuyGoldKiller1, SymbolOrder); if (CheckOpenOrders(MagicBuyGoldKiller2)==true) CloseAllOrders (MagicBuyGoldKiller2, SymbolOrder); if (CheckOpenOrders(MagicBuyGoldKiller3)==true) CloseAllOrders (MagicBuyGoldKiller3, SymbolOrder); double sellprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_BID),4); double sell = sellprice; double slsell = sellprice+PipsToPrice(sl, SymbolOrder); double tpsell = sellprice-PipsToPrice(tp, SymbolOrder); int ordersell = OrderSend (SymbolOrder,OP_SELL,TradeVolume1,sell,0,slsell,tpsell,NULL,MagicSellGoldKiller1,0,clrBlue); } if (order_type_buy!=-1 && find_tp!=-1 && CheckOpenOrders(MagicBuyGoldKiller2)==false && CountBuyOpenOrders(SymbolOrder)==true) { if (CheckOpenOrders(MagicSellGoldKiller1)==true) CloseAllOrders (MagicSellGoldKiller1, SymbolOrder); if (CheckOpenOrders(MagicSellGoldKiller2)==true) CloseAllOrders (MagicSellGoldKiller2, SymbolOrder); if (CheckOpenOrders(MagicSellGoldKiller3)==true) CloseAllOrders (MagicSellGoldKiller3, SymbolOrder); double buyprice = price; if (buyprice==0) buyprice = NormalizeDouble(MarketInfo(SymbolOrder,MODE_ASK),4); double slbuy = buyprice-PipsToPrice(sl, SymbolOrder); double tpbuy = buyprice+PipsToPrice(tp, SymbolOrder); if (buypricechecksellprice) int ordersell = OrderSend (SymbolOrder,OP_SELLLIMIT,TradeVolume1,sellprice,0,slsell,tpsell,NULL,MagicSellGoldKiller2,0,clrBlue); else int ordersell2 = OrderSend (SymbolOrder,OP_SELL,TradeVolume1,sellprice,0,slsell,tpsell,NULL,MagicSellGoldKiller2,0,clrBlue); } if ((order_type_buy!=-1 || order_type_sell!=-1) && (find_tp!=-1 || find_sl!=-1) && (CheckOpenOrders(MagicSellGoldKiller1)==true || CheckOpenOrders(MagicBuyGoldKiller1)==true)) { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderMagicNumber()== MagicBuyGoldKiller1 || OrderMagicNumber()== MagicSellGoldKiller1) { double slnew = StringToDouble(getsl[0]); double tpnew = StringToDouble(gettp1[0]); if (OrderMagicNumber()== MagicBuyGoldKiller1 && slnewOrderStopLoss() && OrderStopLoss()!=0) slnew= OrderStopLoss(); if (OrderMagicNumber()== MagicBuyGoldKiller1 && tpnewOrderOpenPrice()&& OrderTakeProfit()!=0) tpnew= OrderTakeProfit(); int Modify = OrderModify (OrderTicket(),OrderOpenPrice(),slnew,tpnew,0,clrAqua); } }} } if ((order_type_buy!=-1 || order_type_sell!=-1) && (find_tp!=-1 || find_sl!=-1) && (CheckOpenOrders(MagicSellGoldKiller2)==true || CheckOpenOrders(MagicBuyGoldKiller2)==true)) { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderMagicNumber()== MagicBuyGoldKiller2 || OrderMagicNumber()== MagicSellGoldKiller2) { double slnew = StringToDouble(getsl[0]); double tpnew = StringToDouble(gettp3[0]); if (OrderMagicNumber()== MagicBuyGoldKiller2 && slnewOrderStopLoss() && OrderStopLoss()!=0) slnew= OrderStopLoss(); if (OrderMagicNumber()== MagicBuyGoldKiller2 && tpnewOrderOpenPrice()&& OrderTakeProfit()!=0) tpnew= OrderTakeProfit(); int Modify = OrderModify (OrderTicket(),OrderOpenPrice(),slnew,tpnew,0,clrAqua); } }} } } // End of Orders } // End of Gold Killer }} // End Capture ID and On Timer // Start of Event Handling void OnChartEvent (const int id,const long &lparam,const double &dparam,const string &sparam) { OurInterface.OnEvent(id,lparam,dparam, sparam); if (id == CHARTEVENT_OBJECT_ENDEDIT){ if(sparam == LotName) { string volumeText = ObjectGetString(0, LotName, OBJPROP_TEXT); TradeVolume1 = StringToDouble(volumeText); ObjectSetString(0, LotName, OBJPROP_TEXT, string(TradeVolume1)); return; } if(sparam == LotName2) { string volumeText = ObjectGetString(0, LotName2, OBJPROP_TEXT); TradeVolume2 = StringToDouble(volumeText); ObjectSetString(0, LotName2, OBJPROP_TEXT, string(TradeVolume2)); return; } if(sparam == LotName3) { string volumeText = ObjectGetString(0, LotName3, OBJPROP_TEXT); TradeVolume3 = StringToDouble(volumeText); ObjectSetString(0, LotName3, OBJPROP_TEXT, string(TradeVolume3)); return; } if(sparam == SD_Value) { string volumeText = ObjectGetString(0, SD_Value, OBJPROP_TEXT); sd = StringToDouble(volumeText); ObjectSetString(0, SD_Value, OBJPROP_TEXT, string(sd)); return; } if(sparam == TP_Value) { string volumeText = ObjectGetString(0, TP_Value, OBJPROP_TEXT); tp = StringToDouble(volumeText); ObjectSetString(0, TP_Value, OBJPROP_TEXT, string(tp)); return; } if(sparam == SL_Value) { string volumeText = ObjectGetString(0, SL_Value, OBJPROP_TEXT); sl = StringToDouble(volumeText); ObjectSetString(0, SL_Value, OBJPROP_TEXT, string(sl)); return; } if(sparam == newTP_Value) { string volumeText = ObjectGetString(0, newTP_Value, OBJPROP_TEXT); newtp = StringToDouble(volumeText); ObjectSetString(0, newTP_Value, OBJPROP_TEXT, string(newtp)); return; } if(sparam == newSL_Value) { string volumeText = ObjectGetString(0, newSL_Value, OBJPROP_TEXT); newsl = StringToDouble(volumeText); ObjectSetString(0, newSL_Value, OBJPROP_TEXT, string(newsl)); return; } } // End of CHARTEVENT_OBJECT_ENDEDIT // if an object was clicked if(id==CHARTEVENT_OBJECT_CLICK) { if(sparam=="NewSLButton") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),newsl,OrderTakeProfit(),0,clrAqua); if(OrderType()==OP_SELL) int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),newsl,OrderTakeProfit() ,0,clrBlue); } } } } if(sparam=="NewTPButton") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),OrderStopLoss(),newtp,0,clrAqua); if(OrderType()==OP_SELL) int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),OrderStopLoss(),newtp ,0,clrBlue); } } } } } // End CHARTEVENT_OBJECT_CLICK } // End of Event Handling // Functions Start int telegram_to_mt4() { CJAVal js; string headers; char post[], result[]; int res = WebRequest("GET","https://api.telegram.org/bot"+InpToken+"/getUpdates?offset=-1","", NULL, 10000, post, ArraySize(post), result, headers); string server_response_data = CharArrayToString(result); js.Deserialize(result); string update_id_str = js["result"] [0] ["update_id"].ToStr(); int update_id = StrToInteger(update_id_str); string chat_id_str = js["result"][0]["message"]["chat"]["id"].ToStr(); chat_id=(ulong)chat_id_str; string output[]; string output2[]; if(capture_previous_update_id < update_id) { capture_previous_update_id = update_id; string chat_message_text = js["result"] [0] ["message"]["text"].ToStr(); string chat_message_caption = js["result"] [0] ["message"]["caption"].ToStr(); StringSplit(chat_message_text,StringGetCharacter("\n", 0), output); StringSplit(chat_message_caption,StringGetCharacter("\n", 0), output2); if(res==-1) { Print("Error in WebRequest. Error code =",GetLastError()); //--- Perhaps the URL is not listed, display a message about the necessity to add the address MessageBox("Add the address in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION); } else { int filehandle11 = FileOpen("chat_id.txt",FILE_WRITE|FILE_TXT); FileWriteString(filehandle11,IntegerToString(chat_id)); FileClose(filehandle11); int filehandle2 = FileOpen("message_details.txt",FILE_WRITE|FILE_CSV); int count_lines = ArraySize(output); for(int x=0;x= 0 ; i--) { int OrderAll = OrderSelect(i,SELECT_BY_POS); double price = MarketInfo(symb,MODE_ASK); if(OrderType() == OP_BUY) price = MarketInfo(symb,MODE_BID); if((OrderType() == OP_BUY || (OrderType() == OP_SELL)) && OrderMagicNumber()==(Magic)) { int OpenDelete = OrderClose(OrderTicket(), OrderLots(),price,5); } if((OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP) && OrderMagicNumber()==(Magic)) { int OpenDelete = OrderDelete(OrderTicket()); } Sleep(100); int error = GetLastError(); if(error > 0) Print("Unanticipated error: "); RefreshRates(); } } bool CountBuyOpenOrders(string symb) { int ordercount = 0; for( int i = 0 ; i < OrdersTotal() ; i++ ) { int OrderSO = OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); if(OrderSymbol()==symb && (OrderType()==OP_BUY)) ordercount=ordercount+1; } if (ordercount=0) { if(ChartSymbol(ID)==symb) { found=true; break; } ID=ChartNext(ID); } return ID; } string TruncateNumber(string number) { int start_index = StringFind(number, "."); if (start_index == -1) return number; string vals[2] = {"", ""}; StringSplit(number, '.', vals); if (StringLen(vals[1]) <= 3 ) return number; return StringConcatenate(vals[0], ".", StringSubstr(vals[1], 0, 2)); }