#property strict #include CAppDialog OurInterface; #include CButton SellStopButton,BuyStopButton,SellLimitButton,BuyLimitButton,BuyButton,SellButton,SetTPButton,SetSLButton,BuyPriceButton,SellPriceButton, TPPriceButton,SLPriceButton,BuyOpenButton,SellOpenButton; #include CEdit LotSize,SD,TP,SL,newTP,newSL,Price,PriceTP,PriceSL; #include CLabel LotLabel,pricetradingLabel,SDLabel,TPLabel,SLLabel,PriceLabel,PriceTPLabel,PriceSLLabel; int slip=20; double TradeVolume = 0.01; double sd = 1000; double tp = 3000; double sl= 3000; double newtp = 0; double newsl = 0; double pricetrading=0; double pricetradingtp = 0; double pricetradingsl= 0; int MagicBuyTP =000111500; int MagicSellTP = 000222500; int MagicBuyPriceTP =0; int MagicSellPriceTP = 0; double MaxAccountBalance = AccountBalance(); double MinAccountBalance = 1000000; double InitialAccountBalance = AccountBalance(); int closestprice = 200; double buyprice = 100000; double sellprice=1; double buylimitprice = 1; double selllimitprice=100000; const string LotName = "Lot_Volume"; 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"; const string Price_Value = "Price_Value"; const string PriceTP_Value = "PriceTP_Value"; const string PriceSL_Value = "PriceSL_Value"; int OnInit() { pricetrading = Ask; ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true); OurInterface.Create(0,"Spot Trading v3.0",0,50,70,470,380); 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(TradeVolume)); SDLabel.Create(0,"SDLabel",0,10,40,50,60); OurInterface.Add(SDLabel); SDLabel.Text("SD:"); SD.Create(0,SD_Value,0,90,40,160,60); OurInterface.Add(SD); SD.Text(string(sd)); TPLabel.Create(0,"TPLabel",0,10,70,50,90); OurInterface.Add(TPLabel); TPLabel.Text("TP:"); TP.Create(0,TP_Value,0,90,70,160,90); OurInterface.Add(TP); TP.Text(string(tp)); SLLabel.Create(0,"SLLabel",0,10,100,50,120); OurInterface.Add(SLLabel); SLLabel.Text("SL:"); SL.Create(0,SL_Value,0,90,100,160,120); OurInterface.Add(SL); SL.Text(string(sl)); BuyStopButton.Create(0,"BuyStopButton",0,10,130,100,150); OurInterface.Add(BuyStopButton); BuyStopButton.Text("Buy Stop"); SellStopButton.Create(0,"SellStopButton",0,110,130,200,150); OurInterface.Add(SellStopButton); SellStopButton.Text("Sell Stop"); BuyLimitButton.Create(0,"BuyLimitButton",0,10,160,100,180); OurInterface.Add(BuyLimitButton); BuyLimitButton.Text("Buy Limit"); SellLimitButton.Create(0,"SellLimitButton",0,110,160,200,180); OurInterface.Add(SellLimitButton); SellLimitButton.Text("Sell Limit"); BuyButton.Create(0,"BuyButton",0,10,190,100,210); OurInterface.Add(BuyButton); BuyButton.Text("Buy Now"); SellButton.Create(0,"SellButton",0,110,190,200,210); OurInterface.Add(SellButton); SellButton.Text("Sell Now"); newTP.Create(0,newTP_Value,0,10,220,100,240); OurInterface.Add(newTP); newTP.Text(string(newtp)); newSL.Create(0,newSL_Value,0,10,250,100,270); OurInterface.Add(newSL); newSL.Text(string(newsl)); SetTPButton.Create(0,"SetTPButton",0,110,220,200,240); OurInterface.Add(SetTPButton); SetTPButton.Text("Set new TP"); SetSLButton.Create(0,"SetSLButton",0,110,250,200,270); OurInterface.Add(SetSLButton); SetSLButton.Text("Set new SL"); PriceLabel.Create(0,"PriceLabel",0,210,10,250,30); OurInterface.Add(PriceLabel); PriceLabel.Text("Price:"); Price.Create(0,Price_Value,0,310,10,400,30); OurInterface.Add(Price); Price.Text(string(pricetrading)); PriceTPLabel.Create(0,"PriceTPLabel",0,210,40,250,60); OurInterface.Add(PriceTPLabel); PriceTPLabel.Text("TP:"); PriceTP.Create(0,PriceTP_Value,0,310,40,400,60); OurInterface.Add(PriceTP); PriceTP.Text(string(pricetradingtp)); PriceSLLabel.Create(0,"PriceSLLabel",0,210,70,250,90); OurInterface.Add(PriceSLLabel); PriceSLLabel.Text("SL:"); PriceSL.Create(0,PriceSL_Value,0,310,70,400,90); OurInterface.Add(PriceSL); PriceSL.Text(string(pricetradingsl)); BuyPriceButton.Create(0,"BuyPriceButton",0,210,110,300,130); OurInterface.Add(BuyPriceButton); BuyPriceButton.Text("Buy Price"); SellPriceButton.Create(0,"SellPriceButton",0,310,110,400,130); OurInterface.Add(SellPriceButton); SellPriceButton.Text("Sell Price"); TPPriceButton.Create(0,"TPPriceButton",0,210,140,300,160); OurInterface.Add(TPPriceButton); TPPriceButton.Text("Set New TP"); SLPriceButton.Create(0,"SLPriceButton",0,310,140,400,160); OurInterface.Add(SLPriceButton); SLPriceButton.Text("Set New SL"); BuyOpenButton.Create(0,"BuyOpenButton",0,210,170,300,190); OurInterface.Add(BuyOpenButton); BuyOpenButton.Text("Buy Open"); SellOpenButton.Create(0,"SellOpenButton",0,310,170,400,190); OurInterface.Add(SellOpenButton); SellOpenButton.Text("Sell Open"); OurInterface.Run(); return(INIT_SUCCEEDED); } void OnTick() { double CurrentAccountBalance = AccountBalance(); if (MaxAccountBalance < AccountBalance()) MaxAccountBalance = AccountBalance(); if (MinAccountBalance > AccountBalance()) MinAccountBalance = 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()==MagicBuyTP) { if (OrderOpenPrice() != buyprice && OrderOpenPrice() > buyprice) { double buystopsl = buyprice-sl*_Point; buystopsl = NormalizeDouble(buystopsl, _Digits); double buystoptp = buyprice+tp*_Point; buystoptp = NormalizeDouble(buystoptp, _Digits); 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 - sd*_Point)) { double sellstopnew = Bid - sd*_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()==MagicSellTP) { if(OrderOpenPrice() != sellprice && OrderOpenPrice() < sellprice) { double sellstopsl = sellprice +sl*_Point; sellstopsl = NormalizeDouble(sellstopsl, _Digits); double sellstoptp = sellprice -tp*_Point; sellstoptp = NormalizeDouble(sellstoptp, _Digits); 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()==MagicBuyTP) { 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 + sd*_Point)) { double sellstopnew = Bid + sd*_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()==MagicSellTP) { if(OrderOpenPrice() != selllimitprice && OrderOpenPrice() > selllimitprice) { double sellstopsl = selllimitprice +sl*_Point; sellstopsl = NormalizeDouble(sellstopsl, _Digits); double sellstoptp = selllimitprice -tp*_Point; sellstoptp = NormalizeDouble(sellstoptp, _Digits); int SellStopModify = OrderModify (OrderTicket(),selllimitprice,sellstopsl,sellstoptp,0,clrBlue); }}}}}} Comment ("Initial Account Balance was ",InitialAccountBalance,", Minimum Balance was ",MinAccountBalance,", Max Balance was ",MaxAccountBalance,", Current Balance is ",CurrentAccountBalance," and Current Equity is ",AccountEquity()); // Create and Delete Pending Order and Trailing Stop Loss Lines if (CheckBuyStopOpenOrders(MagicBuyTP)==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(MagicBuyTP)==false) ObjectDelete(0,"Buy New Expected"); if (CheckSellStopOpenOrders(MagicSellTP)==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(MagicSellTP)==false) ObjectDelete(0,"Sell New Expected"); if (CheckBuyLimitOpenOrders(MagicBuyTP)==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(MagicBuyTP)==false) ObjectDelete(0,"BuyLimit New Expected"); if (CheckSellLimitOpenOrders(MagicSellTP)==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(MagicSellTP)==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 == 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; } if(sparam == Price_Value) { string volumeText = ObjectGetString(0, Price_Value, OBJPROP_TEXT); pricetrading = StringToDouble(volumeText); ObjectSetString(0, Price_Value, OBJPROP_TEXT, string(pricetrading)); return; } if(sparam == PriceTP_Value) { string volumeText = ObjectGetString(0, PriceTP_Value, OBJPROP_TEXT); pricetradingtp = StringToDouble(volumeText); ObjectSetString(0, PriceTP_Value, OBJPROP_TEXT, string(pricetradingtp)); return; } if(sparam == PriceSL_Value) { string volumeText = ObjectGetString(0, PriceSL_Value, OBJPROP_TEXT); pricetradingsl = StringToDouble(volumeText); ObjectSetString(0, PriceSL_Value, OBJPROP_TEXT, string(pricetradingsl)); return; } } // if an object was clicked if(id==CHARTEVENT_OBJECT_CLICK) { if(sparam=="BuyStopButton") BuyStopOrder(MagicBuyTP); if(sparam=="BuyLimitButton") BuyLimitOrder(MagicBuyTP); if(sparam=="SellStopButton") SellStopOrder(MagicSellTP); if(sparam=="SellLimitButton") SellLimitOrder(MagicSellTP); if(sparam=="BuyButton") BuyOrder(MagicBuyTP); if(sparam=="SellButton") SellOrder(MagicSellTP); if(sparam=="BuyOpenButton") BuyOpenOrder(MagicBuyPriceTP); if(sparam=="SellOpenButton") SellOpenOrder(MagicSellPriceTP); if(sparam=="BuyPriceButton") { if (pricetrading>Ask) BuyStopOrder(MagicBuyPriceTP); if (pricetradingBid) SellLimitOrder(MagicSellPriceTP); int b= OrdersTotal()-1; if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol() && (OrderMagicNumber()==MagicSellPriceTP)) { int PriceModify = OrderModify (OrderTicket(),pricetrading,pricetradingsl,pricetradingtp,0,clrAqua); }} } if(sparam=="SetTPButton") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol() && (OrderMagicNumber()==MagicBuyTP || OrderMagicNumber()==MagicSellTP)) { int TPModify = OrderModify (OrderTicket(),OrderOpenPrice(),OrderStopLoss(),newtp,0,clrAqua); }}} } if(sparam=="SetSLButton") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol() && (OrderMagicNumber()==MagicBuyTP || OrderMagicNumber()==MagicSellTP)) { int SLModify = OrderModify (OrderTicket(),OrderOpenPrice(),newsl,OrderTakeProfit(),0,clrAqua); }}} } if(sparam=="TPPriceButton") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol() && (OrderMagicNumber()==MagicBuyPriceTP || OrderMagicNumber()==MagicSellPriceTP)) { int TPModify = OrderModify (OrderTicket(),OrderOpenPrice(),OrderStopLoss(),pricetradingtp,0,clrAqua); }}} } if(sparam=="SLPriceButton") { for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol() && (OrderMagicNumber()==MagicBuyPriceTP || OrderMagicNumber()==MagicSellPriceTP)) { int SLModify = OrderModify (OrderTicket(),OrderOpenPrice(),pricetradingsl,OrderTakeProfit(),0,clrAqua); }}} } }} void OnDeinit(const int reason) { OurInterface.Destroy(reason); } void BuyStopOrder(int MagicBuy) { 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); int orderbuystop = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume,buy,slip,slbuy,tpbuy,NULL,MagicBuy,0,clrBlue); buyprice= buy; } void SellStopOrder(int MagicSell) { double sell = Bid-sd*_Point; sell = NormalizeDouble(sell, _Digits); double slsellnew = sell+sl*_Point; slsellnew = NormalizeDouble(slsellnew, _Digits); double tpsellnew = sell-tp*_Point; tpsellnew = NormalizeDouble(tpsellnew, _Digits); int ordersell = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume,sell,slip,slsellnew,tpsellnew,NULL,MagicSell,0,clrGreen); sellprice = sell; } void BuyLimitOrder(int MagicBuy) { 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); int orderlimitstop = OrderSend (_Symbol,OP_BUYLIMIT,TradeVolume,buy,slip,slbuy,tpbuy,NULL,MagicBuy,0,clrBlue); buylimitprice = buy; } void SellLimitOrder(int MagicSell) { double sell = Bid+sd*_Point; // Ask+8*_Point; sell = NormalizeDouble(sell, _Digits); double slsellnew = sell+sl*_Point; slsellnew = NormalizeDouble(slsellnew, _Digits); double tpsellnew = sell-tp*_Point; tpsellnew = NormalizeDouble(tpsellnew, _Digits); int ordersell = OrderSend (_Symbol,OP_SELLLIMIT,TradeVolume,sell,slip,slsellnew,tpsellnew,NULL,MagicSell,1,clrGreen); selllimitprice = sell; } void BuyOrder(int MagicBuy) { double buy = Ask; buy = NormalizeDouble(buy, _Digits); double slbuy = buy-sl*_Point; slbuy = NormalizeDouble(slbuy, _Digits); double tpbuy = buy+tp*_Point; tpbuy = NormalizeDouble(tpbuy, _Digits); int orderbuy = OrderSend (_Symbol,OP_BUY,TradeVolume,buy,slip,slbuy,tpbuy,NULL,MagicBuy,0,clrBlue); buylimitprice = buy; } void SellOrder(int MagicSell) { double sell = Bid; sell = NormalizeDouble(sell, _Digits); double slsellnew = sell+sl*_Point; slsellnew = NormalizeDouble(slsellnew, _Digits); double tpsellnew = sell-tp*_Point; tpsellnew = NormalizeDouble(tpsellnew, _Digits); int ordersell = OrderSend (_Symbol,OP_SELL,TradeVolume,sell,slip,slsellnew,tpsellnew,NULL,MagicSell,0,clrGreen); selllimitprice = sell; } void BuyOpenOrder(int MagicBuy) { double buy = Ask; buy = NormalizeDouble(buy, _Digits); int orderbuy = OrderSend (_Symbol,OP_BUY,TradeVolume,buy,0,0,0,NULL,MagicBuy,0,clrBlue); } void SellOpenOrder(int MagicSell) { double sell = Bid; sell = NormalizeDouble(sell, _Digits); int ordersell = OrderSend (_Symbol,OP_SELL,TradeVolume,sell,0,0,0,NULL,MagicSell,0,clrGreen); } bool CheckBuyStopOpenOrders(int MagicBuy){ // 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 && OrderMagicNumber()==(MagicBuy) ) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); } bool CheckSellStopOpenOrders(int MagicSell){ // 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 && OrderMagicNumber()==(MagicSell)) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); } bool CheckBuyLimitOpenOrders(int MagicBuy){ // 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 && OrderMagicNumber()==(MagicBuy) ) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); } bool CheckSellLimitOpenOrders(int MagicSell){ // 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 && OrderMagicNumber()==(MagicSell)) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); }