#property strict #include CAppDialog OurInterface; #include CButton OrderButton,SellButton,BuyButton,NewSLButton,NewTPButton,TSLButton; #include CEdit LotSize,StartDifference,StartSL,StartTP,TrailingSL,LotSizeSell,StartDifferenceSell,StartSLSell,StartTPSell,TrailingSLSell; #include CLabel LotLabel,StartDifferenceLabel,StartSLLabel,StartTPLabel,TrailingSLLabel,LotLabelSell,StartDifferenceLabelSell,StartSLLabelSell, StartTPLabelSell,TrailingSLLabelSell; bool removeFromThisChartOnly = true; int slip=20; // Best Setting for One Sided Up is sd 100, sl 243, tp 257, last four 100 double TradeVolume = 1; double sd=100; // Start Diffrence 200 double sl = 1000; double tp = 1000; double tsl= 0; double TradeVolumeSell = 1; double sdSell=sd; // Start Diffrence 200 double slSell = sl; double tpSell = tp; double tslSell= 0; double buynewtsl = 10000000; double sellnewtsl = 0; int closestprice = 20; double buyprice = 100000; double buypriceforminprofit = 100000; double buypriceforfirstprofit = 100000; double sellprice=1; double sellpriceforminprofit = 1; double sellpriceforfirstprofit = 1; double buylimitprice = 1; double selllimitprice=100000; int MagicBuyScalpingMAC5 =100111615; int MagicSellScalpingMAC5 = 100222615; double MaxAccountBalance = AccountBalance(); double MinAccountBalance = 1000000; double InitialAccountBalance = AccountBalance(); string OK_TO_BUY = "NG"; string OK_TO_BUY_PreviousBar = "NG"; string OK_TO_BUY_ThisBar = "NG"; string OK_TO_SELL = "NG"; string OK_TO_SELL_PreviousBar = "NG"; string OK_TO_SELL_ThisBar = "NG"; string OK_TO_BUY_LastFour = "NG"; string OK_TO_SELL_LastFour = "NG"; string EMA30_OK_TO_BUY = "NG"; string EMA30_OK_TO_SELL = "NG"; string EMA05_OK_TO_BUY = "NG"; string EMA05_OK_TO_SELL = "NG"; int first_start_hour = 1; // 1Pm for Testing. 3pm for actual int first_start_min = 0; string first_start_AMPM = "AM"; int first_end_hour = 11; int first_end_min = 59; string first_end_AMPM = "PM"; int second_start_hour = 9; int second_start_min = 0; string second_start_AMPM = "AM"; int second_end_hour = 9; int second_end_min = 0; string second_end_AMPM = "PM"; string OK_TO_TRADE = "NG"; 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 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"; // int speedSlowness = 500000000; // intended for 32 speed, adjust as desired int speedSlowness = 0; int OnInit() { ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true); OurInterface.Create(0,"Moving Average Change",0,50,70,445,290); 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)); 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)); 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,160,125,180); OurInterface.Add(BuyButton); BuyButton.Text("Buy Order"); OrderButton.Create(0,"OrderButton",0,135,160,250,180); OurInterface.Add(OrderButton); OrderButton.Text("Both Orders"); SellButton.Create(0,"SellButton",0,265,160,375,180); OurInterface.Add(SellButton); SellButton.Text("Sell Order"); OurInterface.Run(); return(INIT_SUCCEEDED); } void OnTick() { // 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()==MagicBuyScalpingMAC5) { 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()==MagicSellScalpingMAC5) { 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()==MagicBuyScalpingMAC5) { 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()==MagicSellScalpingMAC5) { 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()==MagicBuyScalpingMAC5) { if (buynewtsl Bid + tslSell*_Point || OrderStopLoss()==0) { sellnewtsl = Bid +tslSell*_Point; sellnewtsl = NormalizeDouble(sellnewtsl, _Digits); } if (sellnewtsl-Bid AccountBalance()) MinAccountBalance = AccountBalance(); double M05EMALast = iMA(_Symbol, PERIOD_M5, 14, 0, MODE_EMA, PRICE_CLOSE, 0); double M05EMA3 = iMA(_Symbol, PERIOD_M5, 14, 3, MODE_EMA, PRICE_CLOSE, 0); if (CheckPreviousBarRed()==true) OK_TO_BUY_PreviousBar = "OK"; if (CheckPreviousBarRed()==false) OK_TO_BUY_PreviousBar = "NG"; if (CheckPreviousBarGreen()==true) OK_TO_SELL_PreviousBar = "OK"; if (CheckPreviousBarGreen()==false) OK_TO_SELL_PreviousBar = "NG"; if (CheckThisBarRed()==true) OK_TO_BUY_ThisBar = "OK"; if (CheckThisBarRed()==false) OK_TO_BUY_ThisBar = "NG"; if (CheckThisBarGreen()==true) OK_TO_SELL_ThisBar = "OK"; if (CheckThisBarGreen()==false) OK_TO_SELL_ThisBar = "NG"; if (CheckLastFourHigh()==true) OK_TO_BUY_LastFour= "OK"; if (CheckLastFourHigh()==false) OK_TO_BUY_LastFour= "NG"; if (CheckLastFourLow()==true) OK_TO_SELL_LastFour= "OK"; if (CheckLastFourLow()==false) OK_TO_SELL_LastFour= "NG"; if (OK_TO_BUY_LastFour=="OK" && CheckBuyStopOpenOrders(MagicBuyScalpingMAC5)==false && CheckBuyOpenOrders(MagicBuyScalpingMAC5)==false) OK_TO_BUY = "OK"; if (OK_TO_SELL_LastFour=="OK" && CheckSellStopOpenOrders(MagicSellScalpingMAC5)==false && CheckSellOpenOrders(MagicSellScalpingMAC5)==false) OK_TO_SELL = "OK"; if (M05EMA3-M05EMALast>0.25) { EMA05_OK_TO_SELL = "OK"; } else { EMA05_OK_TO_SELL = "NG"; } if (M05EMALast-M05EMA3>0.25) {EMA05_OK_TO_BUY = "OK";} else {EMA05_OK_TO_BUY = "NG";} // if (M05EMALast-M05EMA3>0.5) EMA05_OK_TO_BUY = "OK"; // if (M05EMALast-M05EMA3<0.5) EMA05_OK_TO_SELL = "NG"; if (EMA05_OK_TO_BUY == "OK" && (OK_TO_BUY_PreviousBar=="OK") && CheckBuyStopOpenOrders(MagicBuyScalpingMAC5)==false && CheckBuyOpenOrders(MagicBuyScalpingMAC5)==false) { BuyStopOrder(MagicBuyScalpingMAC5); EMA05_OK_TO_BUY = "NG"; OK_TO_BUY_PreviousBar="NG"; Sleep(300000); } if (EMA05_OK_TO_SELL == "OK" && (OK_TO_SELL_PreviousBar=="OK") && CheckSellStopOpenOrders(MagicSellScalpingMAC5)==false && CheckSellOpenOrders(MagicSellScalpingMAC5)==false) { SellStopOrder(MagicSellScalpingMAC5); EMA05_OK_TO_SELL = "NG"; OK_TO_SELL_PreviousBar="NG"; Sleep(300000); } Comment ("Initial Account Balance was ",InitialAccountBalance,", Minimum Balance was ",MinAccountBalance,", Max Balance was ",MaxAccountBalance,", Current Balance is ",CurrentAccountBalance," and Current Equity is ",AccountEquity(), "\nPrevious Bar Close Red : ",OK_TO_BUY_PreviousBar ,", EMA05 Buy Signal: ",EMA05_OK_TO_BUY, "\nPrevious Bar Close Green : ",OK_TO_SELL_PreviousBar,", EMA05 Sell Signal: ",EMA05_OK_TO_SELL," and its Value is : ",M05EMA3-M05EMALast, ""); // Create and Delete Pending Order and Trailing Stop Loss Lines if (CheckBuyStopOpenOrders(MagicBuyScalpingMAC5)==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(MagicBuyScalpingMAC5)==false) ObjectDelete(0,"Buy New Expected"); if (CheckSellStopOpenOrders(MagicSellScalpingMAC5)==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(MagicSellScalpingMAC5)==false) ObjectDelete(0,"Sell New Expected"); if (CheckBuyOpenOrders(MagicBuyScalpingMAC5)==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(MagicBuyScalpingMAC5)==false || tsl==0) ObjectDelete(0,"Buy New TSL"); if (CheckSellOpenOrders(MagicSellScalpingMAC5)==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(MagicSellScalpingMAC5)==false || tslSell==0) ObjectDelete(0,"Sell New TSL"); } // 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; } 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 == 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)); 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 an object was clicked if(id==CHARTEVENT_OBJECT_CLICK) { if(sparam=="BuyButton" || sparam=="OrderButton") BuyStopOrder(MagicBuyScalpingMAC5); if(sparam=="SellButton" || sparam=="OrderButton") SellStopOrder(MagicSellScalpingMAC5); 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()==MagicBuyScalpingMAC5) { int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),buynewsl,OrderTakeProfit(),0,clrAqua); } // New Take Profit for Sell if(OrderType()==OP_SELL&& OrderMagicNumber()==MagicSellScalpingMAC5) { 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()==MagicBuyScalpingMAC5) { int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),OrderStopLoss(),buynewtp,0,clrAqua); } // New Take Profit for Sell if(OrderType()==OP_SELL && OrderMagicNumber()==MagicSellScalpingMAC5) { 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); 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()==MagicBuyScalpingMAC5) { int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),buynewsl,OrderTakeProfit(),0,clrAqua); } // New StopLoss for Sell if(OrderType()==OP_SELL && OrderMagicNumber()==MagicSellScalpingMAC5) { 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 && tsl==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; buypriceforminprofit = buy; buypriceforfirstprofit= 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 && tslSell==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; sellpriceforminprofit = sell; sellpriceforfirstprofit= 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(); } } 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 CheckBuyOpenOrders(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_BUY && OrderMagicNumber()==MagicBuy) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); } bool CheckSellOpenOrders(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_SELL && OrderMagicNumber()==MagicSell) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); } bool CheckThisBarRed(){ double thisopen = Open[0]; if (Ask2 || previousopen2-previousclose>2 || previousopen3-previousclose>2 || previousopen-Ask>2 || thisopen-Ask>2 || theHighestprevious-Ask>2 || theHighestprevious2-Ask>2) return(true); else return(false); } bool CheckPreviousBarGreen(){ double theLowestprevious = Low[iLowest(_Symbol,PERIOD_M5,MODE_LOW,1)]; double theLowestprevious2 = Low[iLowest(_Symbol,PERIOD_M5,MODE_LOW,2)]; double thisopen = Open[0]; double previousopen = Open[1]; double previousclose = Close[1]; double previousopen2 = Open[2]; double previousclose2 = Close[2]; double previousopen3 = Open[3]; double previousclose3 = Close[3]; if (previousclose-previousopen>2 || previousclose2-previousopen>2 || previousclose3-previousopen>2 || Bid-previousopen>2 || Bid-thisopen>2 || Bid-theLowestprevious>2 || Bid-theLowestprevious2>2) return(true); else return(false); } bool CheckPrevious2BarRed(){ double previousopen2 = Open[2]; double previousclose2 = Close[2]; if (previousopen2>previousclose2) return(true); else return(false); } bool CheckPrevious3BarRed(){ double previousopen3 = Open[3]; double previousclose3 = Close[3]; if (previousopen3>previousclose3) return(true); else return(false); } bool CheckPrevious4BarRed(){ double previousopen4 = Open[4]; double previousclose4 = Close[4]; if (previousopen4>previousclose4) return(true); else return(false); } bool CheckLastFourHigh(){ double theHighest = Close[iHighest(NULL,0,MODE_CLOSE,7,0)]; // <= close of the bar found if (AsktheLowest+200*_Point) return(true); else return(false); }