#property strict #include CAppDialog OurInterface; #include CButton OrderButton,BuyButton,SellButton,NewTPButton,TSLButton,PendingClose, AllClose; #include CEdit LotSize1,LotSize2,LotSize3,LotSize4,TradeDifference1,TradeDifference2,TradeDifference3,TradeDifference4,Slippage,StartSL,StartTP,TrailingSL, FirstHour,FirstMin,FirstAMPM,SecondHour,SecondMin,SecondAMPM,ThirdHour,ThirdMin,ThirdAMPM; #include CLabel LotLabel1,LotLabel2,LotLabel3,LotLabel4,TradeDifferenceLabel1,TradeDifferenceLabel2,TradeDifferenceLabel3,TradeDifferenceLabel4,SlippageLabel, StartSLLabel,StartTPLabel,TrailingSLLabel,ScheduleHeadingLabel,FirstSchedule,SecondSchedule,ThirdSchedule,Colon1,Colon2,Colon3; #include bool removeFromThisChartOnly = true; double TradeVolume1 = 0.01; double TradeVolume2 = 0.01; double TradeVolume3 = 0.01; double TradeVolume4 = 0.01; double TVD1 = 150; // Trade Volume 1 Difference double TVD2 = 30; // Trade Volume 2 Difference double TVD3 = 30; // Trade Volume 3 Difference double TVD4 = 30; // Trade Volume 4 Difference int slip=2; double sl = 150; double tp = 0; double tsl=0; int MagicBuy = 300111800; int MagicSell = 300222800; int first_start_hour = 5; int first_start_min = 30; string first_AMPM = "PM"; int second_start_hour = 2; int second_start_min = 10; string second_AMPM = "PM"; int third_start_hour = 10; int third_start_min = 50; string third_AMPM = "AM"; const string LotName1 = "Lot_Volume1"; const string LotName2 = "Lot_Volume2"; const string LotName3 = "Lot_Volume3"; const string LotName4 = "Lot_Volume4"; const string First_Diff = "First_Difference"; const string Second_Diff = "Second_Difference"; const string Third_Diff = "Third_Difference"; const string Fourth_Diff = "Fourth_Difference"; const string Slippage_st = "Start_Slippage"; const string Start_SL = "Start_SL"; const string Start_TP = "Start_TP"; const string Trailing_SL = "Trailing_SL"; const string First_Hour = "First_Hour"; const string First_Min = "First_Min"; const string First_AMPM = "First_AMPM"; const string Second_Hour = "Second_Hour"; const string Second_Min = "Second_Min"; const string Second_AMPM = "Second_AMPM"; const string Third_Hour = "Third_Hour"; const string Third_Min = "Third_Min"; const string Third_AMPM = "Third_AMPM"; int OnInit() { ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true); OurInterface.Create(0,"News Items for Forex",0,10,70,500,380); LotLabel1.Create(0,"LotLabel1",0,10,10,50,30); OurInterface.Add(LotLabel1); LotLabel1.Text("1st Lot:"); LotSize1.Create(0,LotName1,0,90,10,150,30); OurInterface.Add(LotSize1); LotSize1.Text(string(TradeVolume1)); TradeDifferenceLabel1.Create(0,"StartDifference",0,160,10,250,30); OurInterface.Add(TradeDifferenceLabel1); TradeDifferenceLabel1.Text("1st Diff:"); TradeDifference1.Create(0,First_Diff,0,230,10,275,30); OurInterface.Add(TradeDifference1); TradeDifference1.Text(string(TVD1)); LotLabel2.Create(0,"LotLabel2",0,10,40,50,60); OurInterface.Add(LotLabel2); LotLabel2.Text("2nd Lot:"); LotSize2.Create(0,LotName2,0,90,40,150,60); OurInterface.Add(LotSize2); LotSize2.Text(string(TradeVolume2)); TradeDifferenceLabel2.Create(0,"SecondDifference",0,160,40,250,60); OurInterface.Add(TradeDifferenceLabel2); TradeDifferenceLabel2.Text("2nd Diff:"); TradeDifference2.Create(0,Second_Diff,0,230,40,275,60); OurInterface.Add(TradeDifference2); TradeDifference2.Text(string(TVD2)); LotLabel3.Create(0,"LotLabel3",0,10,70,50,90); OurInterface.Add(LotLabel3); LotLabel3.Text("3rd Lot:"); LotSize3.Create(0,LotName3,0,90,70,150,90); OurInterface.Add(LotSize3); LotSize3.Text(string(TradeVolume3)); TradeDifferenceLabel3.Create(0,"ThirdDifference",0,160,70,250,90); OurInterface.Add(TradeDifferenceLabel3); TradeDifferenceLabel3.Text("3rd Diff:"); TradeDifference3.Create(0,Third_Diff,0,230,70,275,90); OurInterface.Add(TradeDifference3); TradeDifference3.Text(string(TVD3)); LotLabel4.Create(0,"LotLabel4",0,10,100,50,120); OurInterface.Add(LotLabel4); LotLabel4.Text("4th Lot:"); LotSize4.Create(0,LotName4,0,90,100,150,120); OurInterface.Add(LotSize4); LotSize4.Text(string(TradeVolume4)); TradeDifferenceLabel4.Create(0,"FourthDifference",0,160,100,250,120); OurInterface.Add(TradeDifferenceLabel4); TradeDifferenceLabel4.Text("4th Diff:"); TradeDifference4.Create(0,Fourth_Diff,0,230,100,275,120); OurInterface.Add(TradeDifference4); TradeDifference4.Text(string(TVD4)); SlippageLabel.Create(0,"SlippageLabel",0,10,130,50,160); OurInterface.Add(SlippageLabel); SlippageLabel.Text("Slip:"); Slippage.Create(0,Slippage_st,0,90,130,150,150); OurInterface.Add(Slippage); Slippage.Text(string(slip)); StartSLLabel.Create(0,"StartSLLabel",0,10,160,50,180); OurInterface.Add(StartSLLabel); StartSLLabel.Text("Set SL:"); StartSL.Create(0,Start_SL,0,90,160,150,180); OurInterface.Add(StartSL); StartSL.Text(string(sl)); StartTPLabel.Create(0,"StartTPLabel",0,10,190,50,210); OurInterface.Add(StartTPLabel); StartTPLabel.Text("Set TP:"); StartTP.Create(0,Start_TP,0,90,190,150,210); OurInterface.Add(StartTP); StartTP.Text(string(tp)); TrailingSLLabel.Create(0,"TrailingSLLabel",0,10,220,50,240); OurInterface.Add(TrailingSLLabel); TrailingSLLabel.Text("Trail SL:"); TrailingSL.Create(0,Trailing_SL,0,90,220,150,240); OurInterface.Add(TrailingSL); TrailingSL.Text(string(tsl)); ScheduleHeadingLabel.Create(0,"ScheduleHeading",0,310,10,400,30); OurInterface.Add(ScheduleHeadingLabel); ScheduleHeadingLabel.Text("Set News Schedule"); FirstSchedule.Create(0,"FirstScheduleLabel",0,290,40,350,60); OurInterface.Add(FirstSchedule); FirstSchedule.Text("1st News:"); FirstHour.Create(0,First_Hour,0,370,40,400,60); OurInterface.Add(FirstHour); FirstHour.Text(string(first_start_hour)); Colon1.Create(0,"Colon",0,402,40,405,60); OurInterface.Add(Colon1); Colon1.Text(":"); FirstMin.Create(0,First_Min,0,410,40,440,60); OurInterface.Add(FirstMin); FirstMin.Text(string(first_start_min)); FirstAMPM.Create(0,First_AMPM,0,445,40,475,60); OurInterface.Add(FirstAMPM); FirstAMPM.Text(string(first_AMPM)); SecondSchedule.Create(0,"SecondScheduleLabel",0,290,70,350,90); OurInterface.Add(SecondSchedule); SecondSchedule.Text("2nd News:"); SecondHour.Create(0,Second_Hour,0,370,70,400,90); OurInterface.Add(SecondHour); SecondHour.Text(string(second_start_hour)); Colon2.Create(0,"Colon2",0,402,70,405,90); OurInterface.Add(Colon2); Colon2.Text(":"); SecondMin.Create(0,Second_Min,0,410,70,440,90); OurInterface.Add(SecondMin); SecondMin.Text(string(second_start_min)); SecondAMPM.Create(0,Second_AMPM,0,445,70,475,90); OurInterface.Add(SecondAMPM); SecondAMPM.Text(string(second_AMPM)); ThirdSchedule.Create(0,"ThirdScheduleLabel",0,290,100,350,120); OurInterface.Add(ThirdSchedule); ThirdSchedule.Text("3rd News:"); ThirdHour.Create(0,Third_Hour,0,370,100,400,120); OurInterface.Add(ThirdHour); ThirdHour.Text(string(third_start_hour)); Colon3.Create(0,"Colon3",0,402,100,405,120); OurInterface.Add(Colon3); Colon3.Text(":"); ThirdMin.Create(0,Third_Min,0,410,100,440,120); OurInterface.Add(ThirdMin); ThirdMin.Text(string(third_start_min)); ThirdAMPM.Create(0,Third_AMPM,0,445,100,475,120); OurInterface.Add(ThirdAMPM); ThirdAMPM.Text(string(third_AMPM)); PendingClose.Create(0,"PendingCloseButton",0,165,130,275,150); OurInterface.Add(PendingClose); PendingClose.Text("Pending Close"); AllClose.Create(0,"AllCloseButton",0,165,160,275,180); OurInterface.Add(AllClose); AllClose.Text("Close All"); NewTPButton.Create(0,"NewTPButton",0,170,190,270,210); OurInterface.Add(NewTPButton); NewTPButton.Text("Update TP"); TSLButton.Create(0,"TSLButton",0,170,220,270,240); OurInterface.Add(TSLButton); TSLButton.Text("Update TSL"); BuyButton.Create(0,"BuyButton",0,5,250,85,270); OurInterface.Add(BuyButton); BuyButton.Text("Buy Order"); OrderButton.Create(0,"OrderButton",0,90,250,185,270); OurInterface.Add(OrderButton); OrderButton.Text("Both Orders"); SellButton.Create(0,"SellButton",0,190,250,270,270); OurInterface.Add(SellButton); SellButton.Text("Sell Order"); OurInterface.Run(); return(INIT_SUCCEEDED); } void OnTick() { datetime Today = StrToTime(StringConcatenate(Year(), ".", Month(), ".", Day())); int first_start_hour_set=first_start_hour; if (first_AMPM == "PM" && first_start_hour!=12) first_start_hour_set=first_start_hour+12; datetime first_start_time = Today+first_start_hour_set*3600+first_start_min*60; datetime firstpreviousmin = first_start_time-61; datetime firstnextmin = first_start_time-57; if(LocalTime()>firstpreviousmin && LocalTime()secondpreviousmin && LocalTime()thirdpreviousmin && LocalTime()firstnextmin+65 && LocalTime()secondnextmin+65 && LocalTime()thirdnextmin+65 && LocalTime()=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol()) { // Trailing StopLoss for Buy if(OrderType()==OP_BUY) { if (OrderStopLoss() Bid + tsl*_Point || OrderStopLoss()==0) { int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),Bid +tsl*_Point,OrderTakeProfit(),0,clrBlue); } } } } } } // 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 == LotName1) { string volumeText1 = ObjectGetString(0, LotName1, OBJPROP_TEXT); SetVolume1(volumeText1); ObjectSetString(0, LotName1, OBJPROP_TEXT, string(TradeVolume1)); return; } if(sparam == LotName2) { string volumeText2 = ObjectGetString(0, LotName2, OBJPROP_TEXT); SetVolume2(volumeText2); ObjectSetString(0, LotName2, OBJPROP_TEXT, string(TradeVolume2)); return; } if(sparam == LotName3) { string volumeText3 = ObjectGetString(0, LotName3, OBJPROP_TEXT); SetVolume3(volumeText3); ObjectSetString(0, LotName3, OBJPROP_TEXT, string(TradeVolume3)); return; } if(sparam == LotName4) { string volumeText4 = ObjectGetString(0, LotName4, OBJPROP_TEXT); SetVolume4(volumeText4); ObjectSetString(0, LotName4, OBJPROP_TEXT, string(TradeVolume4)); return; } if(sparam == First_Diff) { string TVD1Text = ObjectGetString(0, First_Diff, OBJPROP_TEXT); SetTVD1(TVD1Text); ObjectSetString(0, First_Diff, OBJPROP_TEXT, string(TVD1)); return; } if(sparam == Second_Diff) { string TVD2Text = ObjectGetString(0, Second_Diff, OBJPROP_TEXT); SetTVD2(TVD2Text); ObjectSetString(0, Second_Diff, OBJPROP_TEXT, string(TVD2)); return; } if(sparam == Third_Diff) { string TVD3Text = ObjectGetString(0, Third_Diff, OBJPROP_TEXT); SetTVD3(TVD3Text); ObjectSetString(0, Third_Diff, OBJPROP_TEXT, string(TVD3)); return; } if(sparam == Fourth_Diff) { string TVD4Text = ObjectGetString(0, Fourth_Diff, OBJPROP_TEXT); SetTVD4(TVD4Text); ObjectSetString(0, Fourth_Diff, OBJPROP_TEXT, string(TVD4)); return; } if(sparam == Start_TP) { string TPText = ObjectGetString(0, Start_TP, OBJPROP_TEXT); SetTP(TPText); ObjectSetString(0, Start_TP, OBJPROP_TEXT, string(tp)); return; } if(sparam == Start_SL) { string SLText = ObjectGetString(0, Start_SL, OBJPROP_TEXT); SetSL(SLText); ObjectSetString(0, Start_SL, OBJPROP_TEXT, string(sl)); return; } if(sparam == Trailing_SL) { string TSLText = ObjectGetString(0, Trailing_SL, OBJPROP_TEXT); SetTSL(TSLText); ObjectSetString(0, Trailing_SL, OBJPROP_TEXT, string(tsl)); return; } if(sparam == First_Hour) { string FHText = ObjectGetString(0, First_Hour, OBJPROP_TEXT); SetFH(FHText); ObjectSetString(0, First_Hour, OBJPROP_TEXT, string(first_start_hour)); return; } if(sparam == First_Min) { string FMText = ObjectGetString(0, First_Min, OBJPROP_TEXT); SetFM(FMText); ObjectSetString(0, First_Min, OBJPROP_TEXT, string(first_start_min)); return; } if(sparam == First_AMPM) { string FAPText = ObjectGetString(0, First_AMPM, OBJPROP_TEXT); SetFAP(FAPText); ObjectSetString(0, First_AMPM, OBJPROP_TEXT, string(first_AMPM)); return; } if(sparam == Second_Hour) { string SHText = ObjectGetString(0, Second_Hour, OBJPROP_TEXT); SetSH(SHText); ObjectSetString(0, Second_Hour, OBJPROP_TEXT, string(second_start_hour)); return; } if(sparam == Second_Min) { string SMText = ObjectGetString(0, Second_Min, OBJPROP_TEXT); SetSM(SMText); ObjectSetString(0, Second_Min, OBJPROP_TEXT, string(second_start_min)); return; } if(sparam == Second_AMPM) { string SAPText = ObjectGetString(0, Second_AMPM, OBJPROP_TEXT); SetSAP(SAPText); ObjectSetString(0, Second_AMPM, OBJPROP_TEXT, string(second_AMPM)); return; } if(sparam == Third_Hour) { string THText = ObjectGetString(0, Third_Hour, OBJPROP_TEXT); SetTH(THText); ObjectSetString(0, Third_Hour, OBJPROP_TEXT, string(third_start_hour)); return; } if(sparam == Third_Min) { string TMText = ObjectGetString(0, Third_Min, OBJPROP_TEXT); SetTM(TMText); ObjectSetString(0, Third_Min, OBJPROP_TEXT, string(third_start_min)); return; } if(sparam == Third_AMPM) { string TAPText = ObjectGetString(0, Third_AMPM, OBJPROP_TEXT); SetTAP(TAPText); ObjectSetString(0, Third_AMPM, OBJPROP_TEXT, string(third_AMPM)); return; } } // if an object was clicked if(id==CHARTEVENT_OBJECT_CLICK) { Comment (sparam+" Value is Changed"); // Open Buy Limit double buy1 = Ask+TVD1*_Point; buy1 = NormalizeDouble(buy1, _Digits); double tpbuy1 = buy1+tp*_Point; tpbuy1 = NormalizeDouble(tpbuy1, _Digits); if(tp==0){tpbuy1=0;} double slbuy1 = buy1-sl*_Point; slbuy1 = NormalizeDouble(slbuy1, _Digits); if(sl==0){slbuy1=0;} double buy2 = buy1+TVD2*_Point; buy2 = NormalizeDouble(buy2, _Digits); double tpbuy2 = buy2+tp*_Point; tpbuy2 = NormalizeDouble(tpbuy2, _Digits); if(tp==0){tpbuy2=0;} double slbuy2 = buy2-sl*_Point; slbuy2 = NormalizeDouble(slbuy2, _Digits); if(sl==0){slbuy2=0;} double buy3 = buy2+TVD3*_Point; buy3 = NormalizeDouble(buy3, _Digits); double tpbuy3 = buy3+tp*_Point; tpbuy3 = NormalizeDouble(tpbuy3, _Digits); if(tp==0){tpbuy3=0;} double slbuy3 = buy3-sl*_Point; slbuy3 = NormalizeDouble(slbuy3, _Digits); if(sl==0){slbuy3=0;} double buy4 = buy3+TVD4*_Point; buy4 = NormalizeDouble(buy4, _Digits); double tpbuy4 = buy4+tp*_Point; tpbuy4 = NormalizeDouble(tpbuy4, _Digits); if(tp==0){tpbuy4=0;} double slbuy4 = buy4-sl*_Point; slbuy4 = NormalizeDouble(slbuy4, _Digits); if(sl==0){slbuy4=0;} // Open Sell Limit double sell1 = Bid-TVD1*_Point; sell1 = NormalizeDouble(sell1, _Digits); double tpsell1 = sell1-tp*_Point; tpsell1 = NormalizeDouble(tpsell1, _Digits); if(tp==0){tpsell1=0;} double slsell1 = sell1+sl*_Point; slsell1 = NormalizeDouble(slsell1, _Digits); if(sl==0){slsell1=0;} double sell2 = sell1-TVD2*_Point; sell2 = NormalizeDouble(sell2, _Digits); double tpsell2 = sell2-tp*_Point; tpsell2 = NormalizeDouble(tpsell2, _Digits); if(tp==0){tpsell2=0;} double slsell2 = sell2+sl*_Point; slsell2 = NormalizeDouble(slsell2, _Digits); if(sl==0){slsell2=0;} double sell3 = sell2-TVD3*_Point; sell3 = NormalizeDouble(sell3, _Digits); double tpsell3 = sell3-tp*_Point; tpsell3 = NormalizeDouble(tpsell3, _Digits); if(tp==0){tpsell3=0;} double slsell3 = sell3+sl*_Point; slsell3 = NormalizeDouble(slsell3, _Digits); if(sl==0){slsell3=0;} double sell4 = sell3-TVD4*_Point; sell4 = NormalizeDouble(sell4, _Digits); double tpsell4 = sell4-tp*_Point; tpsell4 = NormalizeDouble(tpsell4, _Digits); if(tp==0){tpsell4=0;} double slsell4 = sell4+sl*_Point; slsell4 = NormalizeDouble(slsell4, _Digits); if(sl==0){slsell4=0;} if(sparam=="BuyButton") { Comment (sparam+" was pressed"); int orderb4 = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume4,buy4,slip,slbuy4,tpbuy4,NULL,MagicBuy,0,clrBlue); int orderb3 = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume3,buy3,slip,slbuy3,tpbuy3,NULL,MagicBuy,0,clrBlue); int orderb2 = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume2,buy2,slip,slbuy2,tpbuy2,NULL,MagicBuy,0,clrBlue); int orderb1 = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume1,buy1,slip,slbuy1,tpbuy1,NULL,MagicBuy,0,clrBlue); } if(sparam=="SellButton") { Comment (sparam+" was pressed"); int orders4 = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume4,sell4,slip,slsell4,tpsell4,NULL,MagicSell,0,clrBlue); int orders3 = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume3,sell3,slip,slsell3,tpsell3,NULL,MagicSell,0,clrBlue); int orders2 = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume2,sell2,slip,slsell2,tpsell2,NULL,MagicSell,0,clrBlue); int orders1 = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume1,sell1,slip,slsell1,tpsell1,NULL,MagicSell,0,clrBlue); } if(sparam=="OrderButton") { Comment (sparam+" was pressed"); int orderb4 = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume4,buy4,slip,slbuy4,tpbuy4,NULL,MagicBuy,0,clrBlue); int orders4 = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume4,sell4,slip,slsell4,tpsell4,NULL,MagicSell,0,clrBlue); int orderb3 = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume3,buy3,slip,slbuy3,tpbuy3,NULL,MagicBuy,0,clrBlue); int orders3 = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume3,sell3,slip,slsell3,tpsell3,NULL,MagicSell,0,clrBlue); int orderb2 = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume2,buy2,slip,slbuy2,tpbuy2,NULL,MagicBuy,0,clrBlue); int orders2 = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume2,sell2,slip,slsell2,tpsell2,NULL,MagicSell,0,clrBlue); int orderb1 = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume1,buy1,slip,slbuy1,tpbuy1,NULL,MagicBuy,0,clrBlue); int orders1 = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume1,sell1,slip,slsell1,tpsell1,NULL,MagicSell,0,clrBlue); } if(sparam=="PendingCloseButton") { ClosePendingOrders(MagicBuy); ClosePendingOrders(MagicSell); } if(sparam=="AllCloseButton") { CloseAllOrders(MagicBuy); CloseAllOrders(MagicSell); } if(sparam=="NewTPButton") { // Chart Output Comment ("New Taking Profit has been updated"); double buynewtp = Ask + tp*_Point; buynewtp = NormalizeDouble(buynewtp, _Digits); double sellnewtp = Bid - tp*_Point; sellnewtp = NormalizeDouble(sellnewtp, _Digits); if(tp==0){ buynewtp=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) { int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),OrderStopLoss(),buynewtp,0,clrAqua); } // New Take Profit for Sell if(OrderType()==OP_SELL) { 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 + tsl*_Point; sellnewsl = NormalizeDouble(sellnewsl, _Digits); if(tsl==0){ buynewsl=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) { int BuyModify = OrderModify (OrderTicket(),OrderOpenPrice(),buynewsl,OrderTakeProfit(),0,clrAqua); } // New StopLoss for Sell if(OrderType()==OP_SELL) { int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),sellnewsl,OrderTakeProfit() ,0,clrBlue); } } } } } } } void OnDeinit(const int reason) { OurInterface.Destroy(reason); } void SetVolume1(string volumeText1) { double newVolume1 = StringToDouble(volumeText1); if (newVolume1 < 0) { Print("Invalid volume specified"); return; } TradeVolume1 = newVolume1; } void SetVolume2(string volumeText2) { double newVolume2 = StringToDouble(volumeText2); if (newVolume2 < 0) { Print("Invalid volume specified"); return; } TradeVolume2 = newVolume2; } void SetVolume3(string volumeText3) { double newVolume3 = StringToDouble(volumeText3); if (newVolume3 < 0) { Print("Invalid volume specified"); return; } TradeVolume3 = newVolume3; } void SetVolume4(string volumeText4) { double newVolume4 = StringToDouble(volumeText4); if (newVolume4 < 0) { Print("Invalid volume specified"); return; } TradeVolume4 = newVolume4; } void SetTVD1(string TVD1Text) { double newTVD1 = StringToDouble(TVD1Text); if (newTVD1 < 0) { Print("Invalid volume specified"); return; } TVD1 = newTVD1; } void SetTVD2(string TVD2Text) { double newTVD2 = StringToDouble(TVD2Text); if (newTVD2 < 0) { Print("Invalid volume specified"); return; } TVD2 = newTVD2; } void SetTVD3(string TVD3Text) { double newTVD3 = StringToDouble(TVD3Text); if (newTVD3 < 0) { Print("Invalid volume specified"); return; } TVD3 = newTVD3; } void SetTVD4(string TVD4Text) { double newTVD4 = StringToDouble(TVD4Text); if (newTVD4 < 0) { Print("Invalid volume specified"); return; } TVD4 = newTVD4; } void SetTP(string TPText) { double newTP = StringToDouble(TPText); if (newTP < 0) { Print("Invalid volume specified"); return; } tp = newTP; } void SetSL(string SLText) { double newSL = StringToDouble(SLText); if (newSL < 0) { Print("Invalid volume specified"); return; } sl = newSL; } void SetTSL(string TSLText) { double newTSL = StringToDouble(TSLText); if (newTSL < 0) { Print("Invalid volume specified"); return; } tsl = newTSL; } void SetFH(string FHText) { int newSL = StrToInteger(FHText); if (newSL < 0) { Print("Invalid volume specified"); return; } first_start_hour = newSL; // StringToInteger } void SetFM(string FMText) { int newSL = StrToInteger(FMText); if (newSL < 0) { Print("Invalid volume specified"); return; } first_start_min = newSL; } void SetFAP(string FAPText) { string newSL = FAPText; first_AMPM = newSL; } void SetSH(string SHText) { int newSL = StrToInteger(SHText); if (newSL < 0) { Print("Invalid volume specified"); return; } second_start_hour = newSL; } void SetSM(string SMText) { int newSL = StrToInteger(SMText); if (newSL < 0) { Print("Invalid volume specified"); return; } second_start_min = newSL; } void SetSAP(string SAPText) { string newSL = SAPText; second_AMPM = newSL; } void SetTH(string THText) { int newSL = StrToInteger(THText); if (newSL < 0) { Print("Invalid volume specified"); return; } third_start_hour = newSL; } void SetTM(string TMText) { int newSL = StrToInteger(TMText); if (newSL < 0) { Print("Invalid volume specified"); return; } third_start_min = newSL; } void SetTAP(string TAPText) { string newSL = TAPText; third_AMPM = newSL; } void Order() { double buy1 = Ask+TVD1*_Point; buy1 = NormalizeDouble(buy1, _Digits); double tpbuy1 = buy1+tp*_Point; tpbuy1 = NormalizeDouble(tpbuy1, _Digits); if(tp==0){tpbuy1=0;} double slbuy1 = buy1-sl*_Point; slbuy1 = NormalizeDouble(slbuy1, _Digits); if(sl==0){slbuy1=0;} double buy2 = buy1+TVD2*_Point; buy2 = NormalizeDouble(buy2, _Digits); double tpbuy2 = buy2+tp*_Point; tpbuy2 = NormalizeDouble(tpbuy2, _Digits); if(tp==0){tpbuy2=0;} double slbuy2 = buy2-sl*_Point; slbuy2 = NormalizeDouble(slbuy2, _Digits); if(sl==0){slbuy2=0;} double buy3 = buy2+TVD3*_Point; buy3 = NormalizeDouble(buy3, _Digits); double tpbuy3 = buy3+tp*_Point; tpbuy3 = NormalizeDouble(tpbuy3, _Digits); if(tp==0){tpbuy3=0;} double slbuy3 = buy3-sl*_Point; slbuy3 = NormalizeDouble(slbuy3, _Digits); if(sl==0){slbuy3=0;} double buy4 = buy3+TVD4*_Point; buy4 = NormalizeDouble(buy4, _Digits); double tpbuy4 = buy4+tp*_Point; tpbuy4 = NormalizeDouble(tpbuy4, _Digits); if(tp==0){tpbuy4=0;} double slbuy4 = buy4-sl*_Point; slbuy4 = NormalizeDouble(slbuy4, _Digits); if(sl==0){slbuy4=0;} // Open Sell Limit double sell1 = Bid-TVD1*_Point; sell1 = NormalizeDouble(sell1, _Digits); double tpsell1 = sell1-tp*_Point; tpsell1 = NormalizeDouble(tpsell1, _Digits); if(tp==0){tpsell1=0;} double slsell1 = sell1+sl*_Point; slsell1 = NormalizeDouble(slsell1, _Digits); if(sl==0){slsell1=0;} double sell2 = sell1-TVD2*_Point; sell2 = NormalizeDouble(sell2, _Digits); double tpsell2 = sell2-tp*_Point; tpsell2 = NormalizeDouble(tpsell2, _Digits); if(tp==0){tpsell2=0;} double slsell2 = sell2+sl*_Point; slsell2 = NormalizeDouble(slsell2, _Digits); if(sl==0){slsell2=0;} double sell3 = sell2-TVD3*_Point; sell3 = NormalizeDouble(sell3, _Digits); double tpsell3 = sell3-tp*_Point; tpsell3 = NormalizeDouble(tpsell3, _Digits); if(tp==0){tpsell3=0;} double slsell3 = sell3+sl*_Point; slsell3 = NormalizeDouble(slsell3, _Digits); if(sl==0){slsell3=0;} double sell4 = sell3-TVD4*_Point; sell4 = NormalizeDouble(sell4, _Digits); double tpsell4 = sell4-tp*_Point; tpsell4 = NormalizeDouble(tpsell4, _Digits); if(tp==0){tpsell4=0;} double slsell4 = sell4+sl*_Point; slsell4 = NormalizeDouble(slsell4, _Digits); if(sl==0){slsell4=0;} int orderb4 = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume4,buy4,slip,slbuy4,tpbuy4,NULL,MagicBuy,0,clrBlue); int orders4 = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume4,sell4,slip,slsell4,tpsell4,NULL,MagicSell,0,clrBlue); int orderb3 = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume3,buy3,slip,slbuy3,tpbuy3,NULL,MagicBuy,0,clrBlue); int orders3 = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume3,sell3,slip,slsell3,tpsell3,NULL,MagicSell,0,clrBlue); int orderb2 = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume2,buy2,slip,slbuy2,tpbuy2,NULL,MagicBuy,0,clrBlue); int orders2 = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume2,sell2,slip,slsell2,tpsell2,NULL,MagicSell,0,clrBlue); int orderb1 = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume1,buy1,slip,slbuy1,tpbuy1,NULL,MagicBuy,0,clrBlue); int orders1 = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume1,sell1,slip,slsell1,tpsell1,NULL,MagicSell,0,clrBlue); } 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(); } }