#property strict #include CAppDialog OurInterface; #include CButton OrderButton,SellButton,BuyButton,NewSLButton,NewTPButton,TSLButton,OrderLimitButton,SellLimitButton,BuyLimitButton; #include CEdit LotSize,StartDifference,StartSL,StartTP,TrailingSL,UpperRSI1,LowerRSI,LotSizeSell,StartDifferenceSell,StartSLSell,StartTPSell,TrailingSLSell,LossLimitExit, RSICloseDiffBuy,MaxRSIBuyAgain,SDBuyAgain,RSIRetforCloseBuy,MinRSIforBuyClose,TPAcBuy,SDTPAcBuy, RSICloseDiffSell,MinRSISellAgain,SDSellAgain,RSIRetforCloseSell,MaxRSIforSellClose,TPAcSell,SDTPAcSell; #include CLabel LotLabel,StartDifferenceLabel,StartSLLabel,StartTPLabel,TrailingSLLabel,UpperRSILabel,LowerRSILabel,LotLabelSell,StartDifferenceLabelSell,StartSLLabelSell, StartTPLabelSell,TrailingSLLabelSell,LossLimitExitLabel, RSICloseDiffBuyLabel,MaxRSIBuyAgainLabel,SDBuyAgainLabel,RSIRetforCloseBuyLabel,MinRSIforBuyCloseLabel,TPAcBuyLabel,SDTPAcBuyLabel, RSICloseDiffSellLabel,MinRSISellAgainLabel,SDSellAgainLabel,RSIRetforCloseSellLabel,MaxRSIforSellCloseLabel,TPAcSellLabel,SDTPAcSellLabel; bool removeFromThisChartOnly = true; int slip=20; double TradeVolume = 0.5; double sd=100; // Start Diffrence double sl = 0; double tp = 0; double tsl= 50; double standardsd = sd; double rsi_close_diff_buy= 10; double max_rsi_for_buy_again = 95; double sd_buy_again = 100; double rsi_return_for_close_buy = 100; double min_rsi_for_buy_close = 10; double tp_ac_buy = 40; double sd_tp_ac_buy = 100; datetime orderholdtime = 30; // in minutes datetime timeremaining = 0; string OK_TO_BUY_afterLoss = "OK"; string OK_TO_SELL_afterLoss = "OK"; double TradeVolumeSell = 0.5; double sdSell=100; // Start Diffrence double slSell = 0; double tpSell = 0; double tslSell= 50; double standardsdSell = sdSell; double rsi_close_diff_sell= 10; double min_rsi_for_sell_again = 5; double sd_sell_again = 50; double rsi_return_for_close_sell = 100; double max_rsi_for_sell_close = 90; double tp_ac_sell = 400; double sd_tp_ac_sell = 100; double loss_limit_for_exit = 250; double buynewtsl = 10000000; double sellnewtsl = 0; double UpperRSIValue=70; double LowerRSIValue=30; int MagicBuyGoldRSI30 = 100111930; int MagicSellGoldRSI30 = 100222930; int closestprice = 20; double buyprice = 100000; double sellprice=1; double buylimitprice = 1; double selllimitprice=100000; int Buy_Orders=0; int Sell_Orders=0; string reasonforclose = "none"; double RSI_Max = 0; double RSI_Min = 100; double RSI_Buy_Close_time=100; double RSI_Sell_Close_time=0; double MaxAccountBalance = AccountBalance(); double InitialAccountBalance = AccountBalance(); const string LotName = "Lot_Volume"; const string Start_Diff = "Start_Difference"; const string Start_SL = "Start_SL"; const string Start_TP = "Start_TP"; const string Trailing_SL = "Trailing_SL"; const string Upper_RSI_Man = "Upper_RSI_Man"; const string Lower_RSI_Man = "Lower_RSI_Man"; const string LotNameSell = "Lot_Volume Sell"; const string Start_DiffSell = "Start_Difference Sell"; const string Start_SLSell = "Start_SL Sell"; const string Start_TPSell = "Start_TP Sell"; const string Trailing_SLSell = "Trailing_SL Sell"; const string Loss_LimitExit ="Loss_Limit_Exit"; const string RSI_CloseDiffBuy ="RSI_Close_DiffBuy"; const string Max_RSIBuyAgain ="Max_RSI_BuyAgain"; const string SD_BuyAgain ="SD_Buy_Again"; const string RSI_RetforCloseBuy ="RSI_Ret_forCloseBuy"; const string Min_RSIforBuyClose ="Min_RSI_forBuyClose"; const string TP_AcBuy ="TP_Ac_Buy"; const string SD_TPAcBuy ="SD_TP_AcBuy"; const string RSI_CloseDiffSell ="RSI_Close_DiffSell"; const string Min_RSISellAgain ="Min_RSI_SellAgain"; const string SD_SellAgain ="SD_Sell_Again"; const string RSI_RetforCloseSell ="RSI_Ret_forCloseSell"; const string Max_RSIforSellClose ="Max_RSI_forSellClose"; const string TP_AcSell ="TP_Ac_Sell"; const string SD_TPAcSell ="SD_TP_AcSell"; int OnInit() { ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true); OurInterface.Create(0,"Trailing Stop Loss New Update",0,10,70,405,500); LotLabel.Create(0,"LotLabel",0,10,10,50,30); OurInterface.Add(LotLabel); LotLabel.Text("Lot Size:"); LotSize.Create(0,LotName,0,90,10,130,30); OurInterface.Add(LotSize); LotSize.Text(string(TradeVolume)); StartDifferenceLabel.Create(0,"StartDifference",0,10,40,50,60); OurInterface.Add(StartDifferenceLabel); StartDifferenceLabel.Text("Start Diff:"); StartDifference.Create(0,Start_Diff,0,90,40,130,60); OurInterface.Add(StartDifference); StartDifference.Text(string(sd)); StartSLLabel.Create(0,"StartSLLabel",0,10,70,50,90); OurInterface.Add(StartSLLabel); StartSLLabel.Text("Set SL:"); StartSL.Create(0,Start_SL,0,90,70,130,90); OurInterface.Add(StartSL); StartSL.Text(string(sl)); StartTPLabel.Create(0,"StartTPLabel",0,10,100,50,120); OurInterface.Add(StartTPLabel); StartTPLabel.Text("Set TP:"); StartTP.Create(0,Start_TP,0,90,100,130,120); OurInterface.Add(StartTP); StartTP.Text(string(tp)); TrailingSLLabel.Create(0,"TrailingSLLabel",0,10,130,50,150); OurInterface.Add(TrailingSLLabel); TrailingSLLabel.Text("Trail SL:"); TrailingSL.Create(0,Trailing_SL,0,90,130,130,150); OurInterface.Add(TrailingSL); TrailingSL.Text(string(tsl)); RSICloseDiffBuyLabel.Create(0,"RSICloseDiffBuyLabel",0,10,160,50,180); OurInterface.Add(RSICloseDiffBuyLabel); RSICloseDiffBuyLabel.Text("RSI Diff BA:"); RSICloseDiffBuy.Create(0,RSI_CloseDiffBuy,0,90,160,130,180); OurInterface.Add(RSICloseDiffBuy); RSICloseDiffBuy.Text(string(rsi_close_diff_buy)); MaxRSIBuyAgainLabel.Create(0,"MaxRSIBuyAgainLabel",0,10,190,50,210); OurInterface.Add(MaxRSIBuyAgainLabel); MaxRSIBuyAgainLabel.Text("MaxRSI BA:"); MaxRSIBuyAgain.Create(0,Max_RSIBuyAgain,0,90,190,130,210); OurInterface.Add(MaxRSIBuyAgain); MaxRSIBuyAgain.Text(string(max_rsi_for_buy_again)); SDBuyAgainLabel.Create(0,"SDBuyAgainLabel",0,10,220,50,240); OurInterface.Add(SDBuyAgainLabel); SDBuyAgainLabel.Text("SD BA:"); SDBuyAgain.Create(0,SD_BuyAgain,0,90,220,130,240); OurInterface.Add(SDBuyAgain); SDBuyAgain.Text(string(sd_buy_again)); RSIRetforCloseBuyLabel.Create(0,"RSIRetforCloseBuyLabel",0,10,250,50,270); OurInterface.Add(RSIRetforCloseBuyLabel); RSIRetforCloseBuyLabel.Text("RSI Ret Cl:"); RSIRetforCloseBuy.Create(0,RSI_RetforCloseBuy,0,90,250,130,270); OurInterface.Add(RSIRetforCloseBuy); RSIRetforCloseBuy.Text(string(rsi_return_for_close_buy)); MinRSIforBuyCloseLabel.Create(0,"MinRSIforBuyCloseLabel",0,10,280,50,300); OurInterface.Add(MinRSIforBuyCloseLabel); MinRSIforBuyCloseLabel.Text("MinRSI Cl:"); MinRSIforBuyClose.Create(0,Min_RSIforBuyClose,0,90,280,130,300); OurInterface.Add(MinRSIforBuyClose); MinRSIforBuyClose.Text(string(min_rsi_for_buy_close)); TPAcBuyLabel.Create(0,"TPAcBuyLabel",0,10,310,50,330); OurInterface.Add(TPAcBuyLabel); TPAcBuyLabel.Text("TP($):"); TPAcBuy.Create(0,TP_AcBuy,0,90,310,130,330); OurInterface.Add(TPAcBuy); TPAcBuy.Text(string(tp_ac_buy)); SDTPAcBuyLabel.Create(0,"SDTPAcBuyLabel",0,10,340,50,360); OurInterface.Add(SDTPAcBuyLabel); SDTPAcBuyLabel.Text("SD for TP:"); SDTPAcBuy.Create(0,SD_TPAcBuy,0,90,340,130,360); OurInterface.Add(SDTPAcBuy); SDTPAcBuy.Text(string(sd_tp_ac_buy)); UpperRSILabel.Create(0,"UpperRSILabel",0,140,10,160,30); OurInterface.Add(UpperRSILabel); UpperRSILabel.Text("Upper RSI:"); UpperRSI1.Create(0,Upper_RSI_Man,0,220,10,250,30); OurInterface.Add(UpperRSI1); UpperRSI1.Text(string(UpperRSIValue)); LowerRSILabel.Create(0,"LowerRSILabel",0,140,40,160,60); OurInterface.Add(LowerRSILabel); LowerRSILabel.Text("Lower RSI:"); LowerRSI.Create(0,Lower_RSI_Man,0,220,40,250,60); OurInterface.Add(LowerRSI); LowerRSI.Text(string(LowerRSIValue)); LotLabelSell.Create(0,"LotLabelSell",0,260,10,330,30); OurInterface.Add(LotLabelSell); LotLabelSell.Text("Lot Size:"); LotSizeSell.Create(0,LotNameSell,0,340,10,380,30); OurInterface.Add(LotSizeSell); LotSizeSell.Text(string(TradeVolumeSell)); StartDifferenceLabelSell.Create(0,"StartDifferenceSell",0,260,40,330,60); OurInterface.Add(StartDifferenceLabelSell); StartDifferenceLabelSell.Text("Start Diff:"); StartDifferenceSell.Create(0,Start_DiffSell,0,340,40,380,60); OurInterface.Add(StartDifferenceSell); StartDifferenceSell.Text(string(sdSell)); StartSLLabelSell.Create(0,"StartSLLabelSell",0,260,70,330,90); OurInterface.Add(StartSLLabelSell); StartSLLabelSell.Text("Set SL:"); StartSLSell.Create(0,Start_SLSell,0,340,70,380,90); OurInterface.Add(StartSLSell); StartSLSell.Text(string(slSell)); StartTPLabelSell.Create(0,"StartTPLabelSell",0,260,100,330,120); OurInterface.Add(StartTPLabelSell); StartTPLabelSell.Text("Set TP:"); StartTPSell.Create(0,Start_TPSell,0,340,100,380,120); OurInterface.Add(StartTPSell); StartTPSell.Text(string(tpSell)); TrailingSLLabelSell.Create(0,"TrailingSLLabelSell",0,260,130,330,150); OurInterface.Add(TrailingSLLabelSell); TrailingSLLabelSell.Text("Trail SL:"); TrailingSLSell.Create(0,Trailing_SLSell,0,340,130,380,150); OurInterface.Add(TrailingSLSell); TrailingSLSell.Text(string(tslSell)); LossLimitExitLabel.Create(0,"LossLimitExitLabel",0,140,160,250,180); OurInterface.Add(LossLimitExitLabel); LossLimitExitLabel.Text("Max Loss Limit:"); LossLimitExit.Create(0,Loss_LimitExit,0,170,190,220,210); OurInterface.Add(LossLimitExit); LossLimitExit.Text(string(loss_limit_for_exit)); RSICloseDiffSellLabel.Create(0,"RSICloseDiffSellLabel",0,260,160,330,180); OurInterface.Add(RSICloseDiffSellLabel); RSICloseDiffSellLabel.Text("RSI Diff SA:"); RSICloseDiffSell.Create(0,RSI_CloseDiffSell,0,340,160,380,180); OurInterface.Add(RSICloseDiffSell); RSICloseDiffSell.Text(string(rsi_close_diff_sell)); MinRSISellAgainLabel.Create(0,"MinRSISellAgainLabel",0,260,190,330,210); OurInterface.Add(MinRSISellAgainLabel); MinRSISellAgainLabel.Text("MinRSI SA:"); MinRSISellAgain.Create(0,Min_RSISellAgain,0,340,190,380,210); OurInterface.Add(MinRSISellAgain); MinRSISellAgain.Text(string(min_rsi_for_sell_again)); SDSellAgainLabel.Create(0,"SDSellAgainLabel",0,260,220,330,240); OurInterface.Add(SDSellAgainLabel); SDSellAgainLabel.Text("SD SA:"); SDSellAgain.Create(0,SD_SellAgain,0,340,220,380,240); OurInterface.Add(SDSellAgain); SDSellAgain.Text(string(sd_sell_again)); RSIRetforCloseSellLabel.Create(0,"RSIRetforCloseSellLabel",0,260,250,330,270); OurInterface.Add(RSIRetforCloseSellLabel); RSIRetforCloseSellLabel.Text("RSI Ret Cl:"); RSIRetforCloseSell.Create(0,RSI_RetforCloseSell,0,340,250,380,270); OurInterface.Add(RSIRetforCloseSell); RSIRetforCloseSell.Text(string(rsi_return_for_close_sell)); MaxRSIforSellCloseLabel.Create(0,"MaxRSIforSellCloseLabel",0,260,280,330,300); OurInterface.Add(MaxRSIforSellCloseLabel); MaxRSIforSellCloseLabel.Text("MaxRSI Cl:"); MaxRSIforSellClose.Create(0,Max_RSIforSellClose,0,340,280,380,300); OurInterface.Add(MaxRSIforSellClose); MaxRSIforSellClose.Text(string(max_rsi_for_sell_close)); TPAcSellLabel.Create(0,"TPAcSellLabel",0,260,310,330,330); OurInterface.Add(TPAcSellLabel); TPAcSellLabel.Text("TP($):"); TPAcSell.Create(0,TP_AcSell,0,340,310,380,330); OurInterface.Add(TPAcSell); TPAcSell.Text(string(tp_ac_sell)); SDTPAcSellLabel.Create(0,"SDTPAcSellLabel",0,260,340,330,360); OurInterface.Add(SDTPAcSellLabel); SDTPAcSellLabel.Text("SD for TP:"); SDTPAcSell.Create(0,SD_TPAcSell,0,340,340,380,360); OurInterface.Add(SDTPAcSell); SDTPAcSell.Text(string(sd_tp_ac_sell)); NewSLButton.Create(0,"NewSLButton",0,140,70,250,90); OurInterface.Add(NewSLButton); NewSLButton.Text("Update SL"); NewTPButton.Create(0,"NewTPButton",0,140,100,250,120); OurInterface.Add(NewTPButton); NewTPButton.Text("Update TP"); TSLButton.Create(0,"TSLButton",0,140,130,250,150); OurInterface.Add(TSLButton); TSLButton.Text("Update TSL"); BuyButton.Create(0,"BuyButton",0,15,370,125,390); OurInterface.Add(BuyButton); BuyButton.Text("Buy Order"); OrderButton.Create(0,"OrderButton",0,135,370,250,390); OurInterface.Add(OrderButton); OrderButton.Text("Both Orders"); SellButton.Create(0,"SellButton",0,265,370,375,390); OurInterface.Add(SellButton); SellButton.Text("Sell Order"); OurInterface.Run(); return(INIT_SUCCEEDED); } void OnTick() { if(lastlosscheck()==true) { if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicBuyGoldRSI30) { datetime ctm=OrderCloseTime(); datetime newordertime = ctm+orderholdtime*60; if (newordertime>TimeCurrent()) { timeremaining = newordertime-TimeCurrent(); OK_TO_BUY_afterLoss = "NG"; OK_TO_SELL_afterLoss = "OK"; } else {timeremaining = 0; OK_TO_BUY_afterLoss = "OK"; } } if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicSellGoldRSI30) { datetime ctm=OrderCloseTime(); datetime newordertime = ctm+orderholdtime*60; if (newordertime>TimeCurrent()) { timeremaining = newordertime-TimeCurrent(); OK_TO_BUY_afterLoss = "OK"; OK_TO_SELL_afterLoss = "NG"; } else { timeremaining = 0; OK_TO_SELL_afterLoss = "OK"; } } }} double CurrentAccountBalance = AccountBalance(); // Trailing BuyStop Pending Order double buyclosestprice = Ask + closestprice*_Point; buyclosestprice = NormalizeDouble(buyclosestprice, _Digits); if (buyprice >Ask + sd*_Point) { double buystopnew = Ask + sd*_Point; buystopnew = NormalizeDouble(buystopnew, _Digits); buyprice = buystopnew; } if (buyprice-buyclosestprice=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol()) { if(OrderType()==OP_BUYSTOP && OrderMagicNumber()==MagicBuyGoldRSI30) { if (OrderOpenPrice() != buyprice && OrderOpenPrice() > buyprice) { double buystopsl = buyprice-sl*_Point; buystopsl = NormalizeDouble(buystopsl, _Digits); double buystoptp = buyprice+tp*_Point; buystoptp = NormalizeDouble(buystoptp, _Digits); if(tp==0){buystoptp=0;} if(sl==0){buystopsl=0;} int BuyStopModify = OrderModify (OrderTicket(),buyprice,buystopsl,buystoptp,0,clrAqua); }}}}}} // Trailing SellStop Pending Order double sellclosestprice = Bid - closestprice*_Point; sellclosestprice = NormalizeDouble(sellclosestprice, _Digits); if (sellprice< (Bid - sdSell*_Point)) { double sellstopnew = Bid - sdSell*_Point; sellstopnew = NormalizeDouble(sellstopnew, _Digits); sellprice = sellstopnew;} if (sellclosestprice-sellprice=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol()) { if(OrderType()==OP_SELLSTOP && OrderMagicNumber()==MagicSellGoldRSI30) { if(OrderOpenPrice() != sellprice && OrderOpenPrice() < sellprice) { double sellstopsl = sellprice +slSell*_Point; sellstopsl = NormalizeDouble(sellstopsl, _Digits); double sellstoptp = sellprice -tpSell*_Point; sellstoptp = NormalizeDouble(sellstoptp, _Digits); if(tpSell==0){sellstoptp=0;} if(slSell==0){sellstopsl=0;} int SellStopModify = OrderModify (OrderTicket(),sellprice,sellstopsl,sellstoptp,0,clrBlue); }}}}}} // Trailing BuyLimit Pending Order if (buylimitprice =0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol()) { if(OrderType()==OP_BUYLIMIT && OrderMagicNumber()==MagicBuyGoldRSI30) { if (OrderOpenPrice() != buylimitprice && OrderOpenPrice() < buylimitprice) { double buylimitsl = buylimitprice-sl*_Point; buylimitsl = NormalizeDouble(buylimitsl, _Digits); double buylimittp = buylimitprice+tp*_Point; buylimittp = NormalizeDouble(buylimittp, _Digits); if(tp==0){buylimittp=0;} if(sl==0){buylimitsl=0;} int BuylimitModify = OrderModify (OrderTicket(),buylimitprice,buylimitsl,buylimittp,0,clrAqua); }}}}}} // Trailing SellLimit Pending Order if (selllimitprice> (Bid + sdSell*_Point)) { double sellstopnew = Bid + sdSell*_Point; sellstopnew = NormalizeDouble(sellstopnew, _Digits); selllimitprice = sellstopnew;} if (selllimitprice-Bid=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol()) { if(OrderType()==OP_SELLLIMIT && OrderMagicNumber()==MagicSellGoldRSI30) { if(OrderOpenPrice() != selllimitprice && OrderOpenPrice() > selllimitprice) { double sellstopsl = selllimitprice +slSell*_Point; sellstopsl = NormalizeDouble(sellstopsl, _Digits); double sellstoptp = selllimitprice -tpSell*_Point; sellstoptp = NormalizeDouble(sellstoptp, _Digits); if(tpSell==0){sellstoptp=0;} if(slSell==0){sellstopsl=0;} int SellStopModify = OrderModify (OrderTicket(),selllimitprice,sellstopsl,sellstoptp,0,clrBlue); }}}}}} // Trailing StopLoss for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol()) { // Trailing StopLoss for Buy if(tsl!=0 && Ask> OrderOpenPrice()+ tsl*_Point) { if(OrderType()==OP_BUY && OrderMagicNumber()==MagicBuyGoldRSI30) { if (buynewtsl Bid + tslSell*_Point || OrderStopLoss()==0) { sellnewtsl = Bid +tslSell*_Point; sellnewtsl = NormalizeDouble(sellnewtsl, _Digits); } if (sellnewtsl-Bidsellnewsl+tsl*_Point && OrderStopLoss()Bid+tsl*_Point && OrderType()==OP_SELL && OrderMagicNumber()==MagicSellNews) { sellnewtsl = Bid +tsl*_Point; sellnewtsl = NormalizeDouble(sellnewtsl, _Digits); int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),sellnewtsl,OrderTakeProfit(),0,clrBlue); } */ }}} double RSI = iRSI(_Symbol,PERIOD_M30,2,0,0); bool RSI_Buy = RSI<=LowerRSIValue; bool RSI_Sell = RSI>=UpperRSIValue; if ((RSI_Buy==true && CheckBuyOpenOrders()==false) || (RSI>RSI_Buy_Close_time+rsi_close_diff_buy && CheckBuyOpenOrders()==false) || (RSI>max_rsi_for_buy_again && CheckBuyOpenOrders()==false)) { if (RSI>max_rsi_for_buy_again) sd=sd_buy_again; BuyStopOrder(MagicBuyGoldRSI30); Sleep (5000); sd=standardsd; } if ((RSI_Sell==true && CheckSellOpenOrders()==false) || (RSIRSI_Max) RSI_Max = RSI; if (RSItp_ac_buy) { for(int i = OrdersTotal() - 1; i >= 0 ; i--) { int OrderAll = OrderSelect(i,SELECT_BY_POS); if(OrderSymbol() != Symbol() && removeFromThisChartOnly) continue; if(OrderType() == OP_BUY && OrderMagicNumber()==MagicBuyGoldRSI30) { if (AccountEquity()-AccountBalance()>tp_ac_buy) reasonforclose="profittaken"; CloseBuyOrders(MagicBuyGoldRSI30); RSI_Max = 0; RSI_Buy_Close_time=RSI; if (reasonforclose=="profittaken") { sd=sd_tp_ac_buy; BuyStopOrder(MagicBuyGoldRSI30); Sleep (5000); sd=standardsd; reasonforclose = "none"; } }}} if (RSI>RSI_Min+rsi_return_for_close_sell || RSI>max_rsi_for_sell_close || AccountEquity()-AccountBalance()>tp_ac_sell) { for(int i = OrdersTotal() - 1; i >= 0 ; i--) { int OrderAll = OrderSelect(i,SELECT_BY_POS); if(OrderSymbol() != Symbol() && removeFromThisChartOnly) continue; if(OrderType() == OP_SELL && OrderMagicNumber()==MagicSellGoldRSI30) { if (AccountEquity()-AccountBalance()>tp_ac_sell) reasonforclose="profittaken"; CloseSellOrders(MagicSellGoldRSI30); RSI_Min = 100; RSI_Sell_Close_time=RSI; if (reasonforclose=="profittaken") { sdSell=sd_tp_ac_sell; SellStopOrder(MagicSellGoldRSI30); Sleep (5000); sdSell=standardsdSell; reasonforclose = "none"; } }}} if (MaxAccountBalance < AccountBalance()) MaxAccountBalance = AccountBalance(); if (AccountBalance()< MaxAccountBalance-loss_limit_for_exit) ExpertRemove(); double buypricedifference = buyprice-buyclosestprice; buypricedifference = NormalizeDouble(buypricedifference, _Digits); double sellpricedifference = sellclosestprice-sellprice; sellpricedifference = NormalizeDouble(sellpricedifference, _Digits); RSI_Max = NormalizeDouble(RSI_Max, _Digits); RSI_Min = NormalizeDouble(RSI_Min, _Digits); Comment ("Buy: ",buyprice," and ",buyclosestprice," and ", buypricedifference," | Sell: ", sellprice," and ",sellclosestprice," and ", sellpricedifference, "\nInitial Account Balance was ",InitialAccountBalance," Maximum Account Balance was ",MaxAccountBalance," and Current Account Balance is ",CurrentAccountBalance, "\nRSI Max is ", RSI_Max," and RSI Min is ", RSI_Min ); // Create and Delete Pending Order and Trailing Stop Loss Lines if (CheckBuyStopOpenOrders()==true) { ObjectCreate(0,"Buy New Expected",OBJ_HLINE,0,0,buyprice); ObjectSetDouble(0,"Buy New Expected",OBJPROP_PRICE,buyprice); ObjectSet("Buy New Expected", OBJPROP_STYLE,STYLE_DASHDOT); ObjectSetText("Buy New Expected", "New BuyStop", 10, "Times New Roman", clrBlue) ; ObjectSetInteger(0,"Buy New Expected",OBJPROP_COLOR,clrGreen); } if (CheckBuyStopOpenOrders()==false) ObjectDelete(0,"Buy New Expected"); if (CheckSellStopOpenOrders()==true) { ObjectCreate(0,"Sell New Expected",OBJ_HLINE,0,0,sellprice); ObjectSetDouble(0,"Sell New Expected",OBJPROP_PRICE,sellprice); ObjectSet("Sell New Expected", OBJPROP_STYLE, STYLE_DASHDOT); ObjectSetText("Sell New Expected", "New SellStop", 10, "Times New Roman", clrBlue) ; ObjectSetInteger(0,"Sell New Expected",OBJPROP_COLOR,clrBlue); } if (CheckSellStopOpenOrders()==false) ObjectDelete(0,"Sell New Expected"); if (CheckBuyOpenOrders()==true && tsl!=0) { ObjectCreate(0,"Buy New TSL",OBJ_HLINE,0,0,buynewtsl); ObjectSetDouble(0,"Buy New TSL",OBJPROP_PRICE,buynewtsl); ObjectSet("Buy New TSL", OBJPROP_STYLE,STYLE_DASHDOT); ObjectSetText("Buy New TSL", "tsl-buy", 10, "Times New Roman", clrBlue) ; ObjectSetInteger(0,"Buy New TSL",OBJPROP_COLOR,clrRed); } if (CheckBuyOpenOrders()==false || tsl==0) ObjectDelete(0,"Buy New TSL"); if (CheckSellOpenOrders()==true && tslSell!=0) { ObjectCreate(0,"Sell New TSL",OBJ_HLINE,0,0,sellnewtsl); ObjectSetDouble(0,"Sell New TSL",OBJPROP_PRICE,sellnewtsl); ObjectSet("Sell New TSL", OBJPROP_STYLE,STYLE_DASHDOT); ObjectSetText("Sell New TSL", "tsl-sell", 10, "Times New Roman", clrBlue) ; ObjectSetInteger(0,"Sell New TSL",OBJPROP_COLOR,clrRed); } if (CheckSellOpenOrders()==false || tslSell==0) ObjectDelete(0,"Sell New TSL"); if (CheckBuyLimitOpenOrders()==true) { ObjectCreate(0,"BuyLimit New Expected",OBJ_HLINE,0,0,buylimitprice); ObjectSetDouble(0,"BuyLimit New Expected",OBJPROP_PRICE,buylimitprice); ObjectSet("BuyLimit New Expected", OBJPROP_STYLE,STYLE_DASHDOT); ObjectSetText("BuyLimit New Expected", "New BuyLimit", 10, "Times New Roman", clrBlue) ; ObjectSetInteger(0,"BuyLimit New Expected",OBJPROP_COLOR,clrGreen); } if (CheckBuyLimitOpenOrders()==false) ObjectDelete(0,"BuyLimit New Expected"); if (CheckSellLimitOpenOrders()==true) { ObjectCreate(0,"SellLimit New Expected",OBJ_HLINE,0,0,selllimitprice); ObjectSetDouble(0,"SellLimit New Expected",OBJPROP_PRICE,selllimitprice); ObjectSet("SellLimit New Expected", OBJPROP_STYLE, STYLE_DASHDOT); ObjectSetText("SellLimit New Expected", "New SellLimit", 10, "Times New Roman", clrBlue) ; ObjectSetInteger(0,"SellLimit New Expected",OBJPROP_COLOR,clrBlue); } if (CheckSellLimitOpenOrders()==false) ObjectDelete(0,"SellLimit New Expected"); } // 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); TradeVolume = StringToDouble(volumeText); ObjectSetString(0, LotName, OBJPROP_TEXT, string(TradeVolume)); return; } if(sparam == Start_Diff) { string volumeText = ObjectGetString(0, Start_Diff, OBJPROP_TEXT); sd = StringToDouble(volumeText); ObjectSetString(0, Start_Diff, OBJPROP_TEXT, string(sd)); return; standardsd = sd; } if(sparam == Start_TP) { string volumeText = ObjectGetString(0, Start_TP, OBJPROP_TEXT); tp = StringToDouble(volumeText); ObjectSetString(0, Start_TP, OBJPROP_TEXT, string(tp)); return; } if(sparam == Start_SL) { string volumeText = ObjectGetString(0, Start_SL, OBJPROP_TEXT); sl = StringToDouble(volumeText); ObjectSetString(0, Start_SL, OBJPROP_TEXT, string(sl)); return; } if(sparam == Trailing_SL) { string volumeText = ObjectGetString(0, Trailing_SL, OBJPROP_TEXT); tsl = StringToDouble(volumeText); ObjectSetString(0, Trailing_SL, OBJPROP_TEXT, string(tsl)); return; } if(sparam == Upper_RSI_Man) { string volumeText = ObjectGetString(0, Upper_RSI_Man, OBJPROP_TEXT); UpperRSIValue = StringToDouble(volumeText); ObjectSetString(0, Upper_RSI_Man, OBJPROP_TEXT, string(UpperRSIValue)); return; } if(sparam == Lower_RSI_Man) { string volumeText = ObjectGetString(0, Lower_RSI_Man, OBJPROP_TEXT); LowerRSIValue = StringToDouble(volumeText); ObjectSetString(0, Lower_RSI_Man, OBJPROP_TEXT, string(LowerRSIValue)); return; } if(sparam == LotNameSell) { string volumeText = ObjectGetString(0, LotNameSell, OBJPROP_TEXT); TradeVolumeSell = StringToDouble(volumeText); ObjectSetString(0, LotNameSell, OBJPROP_TEXT, string(TradeVolumeSell)); return; } if(sparam == Start_DiffSell) { string volumeText = ObjectGetString(0, Start_DiffSell, OBJPROP_TEXT); sdSell = StringToDouble(volumeText); ObjectSetString(0, Start_DiffSell, OBJPROP_TEXT, string(sdSell)); standardsd = sdSell; return; } if(sparam == Start_TPSell) { string volumeText = ObjectGetString(0, Start_TPSell, OBJPROP_TEXT); tpSell = StringToDouble(volumeText); ObjectSetString(0, Start_TPSell, OBJPROP_TEXT, string(tpSell)); return; } if(sparam == Start_SLSell) { string volumeText = ObjectGetString(0, Start_SLSell, OBJPROP_TEXT); slSell = StringToDouble(volumeText); ObjectSetString(0, Start_SLSell, OBJPROP_TEXT, string(slSell)); return; } if(sparam == Trailing_SLSell) { string volumeText = ObjectGetString(0, Trailing_SLSell, OBJPROP_TEXT); tslSell = StringToDouble(volumeText); ObjectSetString(0, Trailing_SLSell, OBJPROP_TEXT, string(tslSell)); return; } if(sparam == Loss_LimitExit) { string volumeText = ObjectGetString(0, Loss_LimitExit, OBJPROP_TEXT); loss_limit_for_exit = StringToDouble(volumeText); ObjectSetString(0, Loss_LimitExit, OBJPROP_TEXT, string(loss_limit_for_exit)); return; } if(sparam == RSI_CloseDiffBuy) { string volumeText = ObjectGetString(0, RSI_CloseDiffBuy, OBJPROP_TEXT); rsi_close_diff_buy = StringToDouble(volumeText); ObjectSetString(0, RSI_CloseDiffBuy, OBJPROP_TEXT, string(rsi_close_diff_buy)); return; } if(sparam == Max_RSIBuyAgain) { string volumeText = ObjectGetString(0, Max_RSIBuyAgain, OBJPROP_TEXT); max_rsi_for_buy_again = StringToDouble(volumeText); ObjectSetString(0, Max_RSIBuyAgain, OBJPROP_TEXT, string(max_rsi_for_buy_again)); return; } if(sparam == SD_BuyAgain) { string volumeText = ObjectGetString(0, SD_BuyAgain, OBJPROP_TEXT); sd_buy_again = StringToDouble(volumeText); ObjectSetString(0, SD_BuyAgain, OBJPROP_TEXT, string(sd_buy_again)); return; } if(sparam == RSI_RetforCloseBuy) { string volumeText = ObjectGetString(0, RSI_RetforCloseBuy, OBJPROP_TEXT); rsi_return_for_close_buy = StringToDouble(volumeText); ObjectSetString(0, RSI_RetforCloseBuy, OBJPROP_TEXT, string(rsi_return_for_close_buy)); return; } if(sparam == Min_RSIforBuyClose) { string volumeText = ObjectGetString(0, Min_RSIforBuyClose, OBJPROP_TEXT); min_rsi_for_buy_close = StringToDouble(volumeText); ObjectSetString(0, Min_RSIforBuyClose, OBJPROP_TEXT, string(min_rsi_for_buy_close)); return; } if(sparam == TP_AcBuy) { string volumeText = ObjectGetString(0, TP_AcBuy, OBJPROP_TEXT); tp_ac_buy = StringToDouble(volumeText); ObjectSetString(0, TP_AcBuy, OBJPROP_TEXT, string(tp_ac_buy)); return; } if(sparam == SD_TPAcBuy) { string volumeText = ObjectGetString(0, SD_TPAcBuy, OBJPROP_TEXT); sd_tp_ac_buy = StringToDouble(volumeText); ObjectSetString(0, SD_TPAcBuy, OBJPROP_TEXT, string(sd_tp_ac_buy)); return; } if(sparam == RSI_CloseDiffSell) { string volumeText = ObjectGetString(0, RSI_CloseDiffSell, OBJPROP_TEXT); rsi_close_diff_sell = StringToDouble(volumeText); ObjectSetString(0, RSI_CloseDiffSell, OBJPROP_TEXT, string(rsi_close_diff_sell)); return; } if(sparam == Min_RSISellAgain) { string volumeText = ObjectGetString(0, Min_RSISellAgain, OBJPROP_TEXT); min_rsi_for_sell_again = StringToDouble(volumeText); ObjectSetString(0, Min_RSISellAgain, OBJPROP_TEXT, string(min_rsi_for_sell_again)); return; } if(sparam == SD_SellAgain) { string volumeText = ObjectGetString(0, SD_SellAgain, OBJPROP_TEXT); sd_sell_again = StringToDouble(volumeText); ObjectSetString(0, SD_SellAgain, OBJPROP_TEXT, string(sd_sell_again)); return; } if(sparam == RSI_RetforCloseSell) { string volumeText = ObjectGetString(0, RSI_RetforCloseSell, OBJPROP_TEXT); rsi_return_for_close_sell = StringToDouble(volumeText); ObjectSetString(0, RSI_RetforCloseSell, OBJPROP_TEXT, string(rsi_return_for_close_sell)); return; } if(sparam == Max_RSIforSellClose) { string volumeText = ObjectGetString(0, Max_RSIforSellClose, OBJPROP_TEXT); max_rsi_for_sell_close = StringToDouble(volumeText); ObjectSetString(0, Max_RSIforSellClose, OBJPROP_TEXT, string(max_rsi_for_sell_close)); return; } if(sparam == TP_AcSell) { string volumeText = ObjectGetString(0, TP_AcSell, OBJPROP_TEXT); tp_ac_sell = StringToDouble(volumeText); ObjectSetString(0, TP_AcSell, OBJPROP_TEXT, string(tp_ac_sell)); return; } if(sparam == SD_TPAcSell) { string volumeText = ObjectGetString(0, SD_TPAcSell, OBJPROP_TEXT); sd_tp_ac_sell = StringToDouble(volumeText); ObjectSetString(0, SD_TPAcSell, OBJPROP_TEXT, string(sd_tp_ac_sell)); return; } } // if an object was clicked if(id==CHARTEVENT_OBJECT_CLICK) { if(sparam=="BuyButton" || sparam=="OrderButton") BuyStopOrder(MagicBuyGoldRSI30); if(sparam=="SellButton" || sparam=="OrderButton") SellStopOrder(MagicSellGoldRSI30); if(sparam=="BuyLimitButton" || sparam=="OrderLimitButton") BuyLimitOrder(MagicBuyGoldRSI30); if(sparam=="SellLimitButton" || sparam=="OrderLimitButton") SellLimitOrder(MagicSellGoldRSI30); if(sparam=="NewSLButton") { // Chart Output Comment ("New Stop Loss has been updated"); double buynewsl = Ask - sl*_Point; buynewsl = NormalizeDouble(buynewsl, _Digits); double sellnewsl = Bid + slSell*_Point; sellnewsl = NormalizeDouble(sellnewsl, _Digits); if(sl==0) buynewsl=0; if(slSell==0) sellnewsl=0; for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol()) { // New Take Profit for Buy if(OrderType()==OP_BUY && OrderMagicNumber()==MagicBuyGoldRSI30) { int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),buynewsl,OrderTakeProfit(),0,clrAqua); } // New Take Profit for Sell if(OrderType()==OP_SELL&& OrderMagicNumber()==MagicSellGoldRSI30) { int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),sellnewsl,OrderTakeProfit() ,0,clrBlue); } } } } } if(sparam=="NewTPButton") { // Chart Output Comment ("New Taking Profit has been updated"); double buynewtp = Ask + tp*_Point; buynewtp = NormalizeDouble(buynewtp, _Digits); double sellnewtp = Bid - tpSell*_Point; sellnewtp = NormalizeDouble(sellnewtp, _Digits); if(tp==0) buynewtp=0; if(tpSell==0) sellnewtp=0; for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol()) { // New Take Profit for Buy if(OrderType()==OP_BUY && OrderMagicNumber()==MagicBuyGoldRSI30) { int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),OrderStopLoss(),buynewtp,0,clrAqua); } // New Take Profit for Sell if(OrderType()==OP_SELL && OrderMagicNumber()==MagicSellGoldRSI30) { int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),OrderStopLoss(),sellnewtp ,0,clrBlue); } } } } } if(sparam=="TSLButton") { // Chart Output Comment ("Trailing SL has been updated"); double buynewsl = Ask - tsl*_Point; buynewsl = NormalizeDouble(buynewsl, _Digits); double sellnewsl = Bid + tslSell*_Point; sellnewsl = NormalizeDouble(sellnewsl, _Digits); sellnewtsl = sellnewsl; buynewtsl = buynewsl; if(tsl==0) buynewsl=0; if(tslSell==0) sellnewsl=0; for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol()) { // New StopLoss for Buy if(OrderType()==OP_BUY && OrderMagicNumber()==MagicBuyGoldRSI30) { int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),buynewsl,OrderTakeProfit(),0,clrAqua); } // New StopLoss for Sell if(OrderType()==OP_SELL && OrderMagicNumber()==MagicSellGoldRSI30) { int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),sellnewsl,OrderTakeProfit() ,0,clrBlue); }}}} } } } void OnDeinit(const int reason) { OurInterface.Destroy(reason); } void BuyStopOrder(int MagicBuy) { if (sl==0 && tsl!=0) sl=tsl; double buy = Ask+sd*Point; buy = NormalizeDouble(buy, _Digits); double slbuy = buy-sl*Point; slbuy = NormalizeDouble(slbuy, _Digits); double tpbuy = buy+tp*Point; tpbuy = NormalizeDouble(tpbuy, _Digits); if(sl==0){slbuy=0;} if(tp==0){tpbuy=0;} int orderbuystop = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume,buy,slip,slbuy,tpbuy,NULL,MagicBuy,0,clrBlue); buyprice = buy; if (sl!=0 && tsl!=0) buynewtsl=slbuy; } void SellStopOrder(int MagicSell) { if (slSell==0 && tslSell!=0) slSell=tslSell; double sell = Bid-sdSell*Point; sell = NormalizeDouble(sell, _Digits); double tpsellnew = sell-tpSell*Point; tpsellnew = NormalizeDouble(tpsellnew, _Digits); double slsellnew = sell+slSell*Point; slsellnew = NormalizeDouble(slsellnew, _Digits); if(slSell==0){slsellnew=0;} if(tpSell==0){tpsellnew=0;} int ordersell = OrderSend (_Symbol,OP_SELLSTOP,TradeVolumeSell,sell,slip,slsellnew,tpsellnew,NULL,MagicSell,0,clrGreen); sellprice = sell; if (slSell!=0 && tslSell!=0) sellnewtsl=slsellnew; } void BuyLimitOrder(int MagicBuy) { if (sl==0 && tsl!=0) sl=tsl; double buy = Ask-sd*Point; // Bid-8*_Point; buy = NormalizeDouble(buy, _Digits); double slbuy = buy-sl*Point; slbuy = NormalizeDouble(slbuy, _Digits); double tpbuy = buy+tp*Point; tpbuy = NormalizeDouble(tpbuy, _Digits); if(sl==0){slbuy=0;} if(tp==0){tpbuy=0;} int orderlimitstop = OrderSend (_Symbol,OP_BUYLIMIT,TradeVolume,buy,slip,slbuy,tpbuy,NULL,MagicBuy,0,clrBlue); buylimitprice = buy; if (sl!=0 && tsl!=0) buynewtsl=slbuy; } void SellLimitOrder(int MagicSell) { if (slSell==0 && tslSell!=0) slSell=tslSell; double sell = Bid+sdSell*Point; // Ask+8*_Point; sell = NormalizeDouble(sell, _Digits); double tpsellnew = sell-tpSell*Point; tpsellnew = NormalizeDouble(tpsellnew, _Digits); double slsellnew = sell+slSell*Point; slsellnew = NormalizeDouble(slsellnew, _Digits); if(slSell==0){slsellnew=0;} if(tpSell==0){tpsellnew=0;} int ordersell = OrderSend (_Symbol,OP_SELLLIMIT,TradeVolumeSell,sell,slip,slsellnew,tpsellnew,NULL,MagicSell,0,clrGreen); selllimitprice = sell; if (slSell!=0 && tslSell!=0) sellnewtsl=slsellnew; } void CloseBuyOrders(int MagicBuy) { Comment ("Buy Orders are Closed"); for(int i = OrdersTotal() - 1; i >= 0 ; i--){ int OrderAll = OrderSelect(i,SELECT_BY_POS); if(OrderSymbol() != Symbol() && removeFromThisChartOnly) continue; if(OrderType() == OP_BUY) { if (OrderMagicNumber()==MagicBuy) { double price = MarketInfo(OrderSymbol(),MODE_BID); int OpenDelete = OrderClose(OrderTicket(), OrderLots(),price,5); }} Sleep(100); int error = GetLastError(); if(error > 0) Print("Unanticipated error: "); RefreshRates(); } } void CloseSellOrders(int MagicSell) { Comment ("Sell Orders are Closed"); for(int i = OrdersTotal() - 1; i >= 0 ; i--){ int OrderAll = OrderSelect(i,SELECT_BY_POS); if(OrderSymbol() != Symbol() && removeFromThisChartOnly) continue; if(OrderType() == OP_SELL) { if (OrderMagicNumber()==MagicSell) { double price = MarketInfo(OrderSymbol(),MODE_ASK); int OpenDelete = OrderClose(OrderTicket(), OrderLots(),price,5); }} Sleep(100); int error = GetLastError(); if(error > 0) Print("Unanticipated error: "); RefreshRates(); } } void ClosePendingOrders(int Magic) { Comment ("All Pending Orders are Closed"); for(int i = OrdersTotal() - 1; i >= 0 ; i--){ int OrderPending = OrderSelect(i,SELECT_BY_POS); // if(OrderSymbol() != Symbol() && removeFromThisChartOnly) continue; double price = MarketInfo(OrderSymbol(),MODE_ASK); if(OrderType() == OP_BUY) price = MarketInfo(OrderSymbol(),MODE_BID); if((OrderType() == OP_BUY )|| (OrderType() == OP_SELL)){ // OrderClose(OrderTicket(), OrderLots(),price,5); }else if (OrderMagicNumber()==(Magic)) { int PendingDelete = OrderDelete(OrderTicket()); } Sleep(100); int error = GetLastError(); if(error > 0) Print("Unanticipated error: "); RefreshRates(); } } void CloseAllOrders(int Magic) { Comment ("All Orders are Closed"); for(int i = OrdersTotal() - 1; i >= 0 ; i--){ int OrderAll = OrderSelect(i,SELECT_BY_POS); if(OrderSymbol() != Symbol() && removeFromThisChartOnly) continue; double price = MarketInfo(OrderSymbol(),MODE_ASK); if(OrderType() == OP_BUY) price = MarketInfo(OrderSymbol(),MODE_BID); if((OrderType() == OP_BUY && OrderMagicNumber()==(Magic))|| (OrderType() == OP_SELL && OrderMagicNumber()==(Magic))){ int OpenDelete = OrderClose(OrderTicket(), OrderLots(),price,5); }else{ int AllDelete = OrderDelete(OrderTicket()); } Sleep(100); int error = GetLastError(); if(error > 0) Print("Unanticipated error: "); RefreshRates(); } } bool CheckBuyStopOpenOrders(){ // We need to scan all the open and pending orders to see if there are any. // OrdersTotal returns the total number of market and pending orders. // What we do is scan all orders and check if they are of the same symbol as the one where the EA is running. for( int i = 0 ; i < OrdersTotal() ; i++ ) { // We select the order of index i selecting by position and from the pool of market/pending trades. int OrderBO = OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); // If the pair of the order is equal to the pair where the EA is running. if(OrderType()==OP_BUYSTOP) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); } bool CheckSellStopOpenOrders(){ // We need to scan all the open and pending orders to see if there are any. // OrdersTotal returns the total number of market and pending orders. // What we do is scan all orders and check if they are of the same symbol as the one where the EA is running. for( int i = 0 ; i < OrdersTotal() ; i++ ) { // We select the order of index i selecting by position and from the pool of market/pending trades. int OrderSO = OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); // If the pair of the order is equal to the pair where the EA is running. if(OrderType()==OP_SELLSTOP) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); } bool CheckBuyLimitOpenOrders(){ // We need to scan all the open and pending orders to see if there are any. // OrdersTotal returns the total number of market and pending orders. // What we do is scan all orders and check if they are of the same symbol as the one where the EA is running. for( int i = 0 ; i < OrdersTotal() ; i++ ) { // We select the order of index i selecting by position and from the pool of market/pending trades. int OrderBO = OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); // If the pair of the order is equal to the pair where the EA is running. if(OrderType()==OP_BUYLIMIT) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); } bool CheckSellLimitOpenOrders(){ // We need to scan all the open and pending orders to see if there are any. // OrdersTotal returns the total number of market and pending orders. // What we do is scan all orders and check if they are of the same symbol as the one where the EA is running. for( int i = 0 ; i < OrdersTotal() ; i++ ) { // We select the order of index i selecting by position and from the pool of market/pending trades. int OrderSO = OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); // If the pair of the order is equal to the pair where the EA is running. if(OrderType()==OP_SELLLIMIT) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); } bool CheckBuyOpenOrders(){ // We need to scan all the open and pending orders to see if there are any. // OrdersTotal returns the total number of market and pending orders. // What we do is scan all orders and check if they are of the same symbol as the one where the EA is running. for( int i = 0 ; i < OrdersTotal() ; i++ ) { // We select the order of index i selecting by position and from the pool of market/pending trades. int OrderBO = OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); // If the pair of the order is equal to the pair where the EA is running. if(OrderType()==OP_BUY) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); } bool CheckSellOpenOrders(){ // We need to scan all the open and pending orders to see if there are any. // OrdersTotal returns the total number of market and pending orders. // What we do is scan all orders and check if they are of the same symbol as the one where the EA is running. for( int i = 0 ; i < OrdersTotal() ; i++ ) { // We select the order of index i selecting by position and from the pool of market/pending trades. int OrderSO = OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); // If the pair of the order is equal to the pair where the EA is running. if(OrderType()==OP_SELL) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); } bool lastlosscheck(){ int OrderCheck = OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY); if(OrderProfit()<0) return(true); else return(false); }