#property strict #include CAppDialog OurInterface; #include CButton SellButton,BuyButton; #include CEdit LotSize,pricetradingedit,TP1,TP2,TP3,SL; #include CLabel LotLabel,pricetradingLabel,TP1Label,TP2Label,TP3Label,SLLabel; int slip=20; double TradeVolume = 0.01; double pricetrading=0; double tp1 = 0; double tp2 = 0; double tp3= 0; double sl= 0; double slnew = sl; int MagicBuyTP =000111500; int MagicSellTP = 000222500; double MaxAccountBalance = AccountBalance(); double MinAccountBalance = 1000000; double InitialAccountBalance = AccountBalance(); const string LotName = "Lot_Volume"; const string pricetrading_value = "pricetrading_value"; const string TP1_Value = "TP1_Value"; const string TP2_Value = "TP2_Value"; const string TP3_Value = "TP3_Value"; const string SL_Value = "SL_Value"; int OnInit() { pricetrading = Ask; ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true); OurInterface.Create(0,"TP1 TP2 TP3",0,50,70,250,340); 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)); pricetradingLabel.Create(0,"pricetrading",0,10,40,50,60); OurInterface.Add(pricetradingLabel); pricetradingLabel.Text("Price:"); pricetradingedit.Create(0,pricetrading_value,0,90,40,160,60); OurInterface.Add(pricetradingedit); pricetradingedit.Text(string(pricetrading)); TP1Label.Create(0,"TP1Label",0,10,70,50,90); OurInterface.Add(TP1Label); TP1Label.Text("TP1:"); TP1.Create(0,TP1_Value,0,90,70,160,90); OurInterface.Add(TP1); TP1.Text(string(tp1)); TP2Label.Create(0,"TP2Label",0,10,100,50,120); OurInterface.Add(TP2Label); TP2Label.Text("TP2:"); TP2.Create(0,TP2_Value,0,90,100,160,120); OurInterface.Add(TP2); TP2.Text(string(tp2)); TP3Label.Create(0,"TP3Label",0,10,130,50,150); OurInterface.Add(TP3Label); TP3Label.Text("TP3:"); TP3.Create(0,TP3_Value,0,90,130,160,150); OurInterface.Add(TP3); TP3.Text(string(tp3)); SLLabel.Create(0,"SLLabel",0,10,160,50,180); OurInterface.Add(SLLabel); SLLabel.Text("SL:"); SL.Create(0,SL_Value,0,90,160,160,180); OurInterface.Add(SL); SL.Text(string(sl)); BuyButton.Create(0,"BuyButton",0,10,190,70,210); OurInterface.Add(BuyButton); BuyButton.Text("Buy"); SellButton.Create(0,"SellButton",0,80,190,160,210); OurInterface.Add(SellButton); SellButton.Text("Sell"); OurInterface.Run(); return(INIT_SUCCEEDED); } void OnTick() { double CurrentAccountBalance = AccountBalance(); if (MaxAccountBalance < AccountBalance()) MaxAccountBalance = AccountBalance(); if (MinAccountBalance > AccountBalance()) MinAccountBalance = AccountBalance(); // TP1 and TP2 Setting for (int b= OrdersTotal()-1;b>=0;b--) { if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol()==Symbol()) { // TP1 for Buy if(OrderType()==OP_BUY && OrderMagicNumber()==MagicBuyTP) { if (Bid>tp1+50*_Point && OrderStopLoss()tp2+50*_Point && OrderStopLoss()tp1) { slnew = tp1+50*_Point; slnew = NormalizeDouble(slnew, _Digits); int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),slnew,OrderTakeProfit(),0,clrBlue); }} // TP2 for Sell if(OrderType()==OP_SELL && OrderMagicNumber()==MagicSellTP) { if (Asktp2) { slnew = tp2+50*_Point; slnew = NormalizeDouble(slnew, _Digits); int SellModify = OrderModify (OrderTicket(),OrderOpenPrice(),slnew,OrderTakeProfit(),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()); } // 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 == pricetrading_value) { string volumeText = ObjectGetString(0, pricetrading_value, OBJPROP_TEXT); pricetrading = StringToDouble(volumeText); ObjectSetString(0, pricetrading_value, OBJPROP_TEXT, string(pricetrading)); return; } if(sparam == TP1_Value) { string volumeText = ObjectGetString(0, TP1_Value, OBJPROP_TEXT); tp1 = StringToDouble(volumeText); ObjectSetString(0, TP1_Value, OBJPROP_TEXT, string(tp1)); return; } if(sparam == TP2_Value) { string volumeText = ObjectGetString(0, TP2_Value, OBJPROP_TEXT); tp2 = StringToDouble(volumeText); ObjectSetString(0, TP2_Value, OBJPROP_TEXT, string(tp2)); return; } if(sparam == TP3_Value) { string volumeText = ObjectGetString(0, TP3_Value, OBJPROP_TEXT); tp3 = StringToDouble(volumeText); ObjectSetString(0, TP3_Value, OBJPROP_TEXT, string(tp3)); 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 an object was clicked if(id==CHARTEVENT_OBJECT_CLICK) { if(sparam=="BuyButton" || sparam=="OrderButton") { if (pricetrading>Ask) BuyStopOrder(MagicBuyTP); if (pricetradingBid) SellLimitOrder(MagicSellTP); } }} void OnDeinit(const int reason) { OurInterface.Destroy(reason); } void BuyStopOrder(int MagicBuy) { double buy = pricetrading; buy = NormalizeDouble(buy, _Digits); double slbuy = sl; slbuy = NormalizeDouble(slbuy, _Digits); double tpbuy = tp3; tpbuy = NormalizeDouble(tpbuy, _Digits); int orderbuystop = OrderSend (_Symbol,OP_BUYSTOP,TradeVolume,buy,slip,slbuy,tpbuy,NULL,MagicBuy,0,clrBlue); } void SellStopOrder(int MagicSell) { double sell = pricetrading; sell = NormalizeDouble(sell, _Digits); double slsellnew = sl; slsellnew = NormalizeDouble(slsellnew, _Digits); double tpsellnew = tp3; tpsellnew = NormalizeDouble(tpsellnew, _Digits); int ordersell = OrderSend (_Symbol,OP_SELLSTOP,TradeVolume,sell,slip,slsellnew,tpsellnew,NULL,MagicSell,0,clrGreen); } void BuyLimitOrder(int MagicBuy) { double buy = pricetrading; buy = NormalizeDouble(buy, _Digits); double slbuy = sl; slbuy = NormalizeDouble(slbuy, _Digits); double tpbuy = tp3; tpbuy = NormalizeDouble(tpbuy, _Digits); int orderlimitstop = OrderSend (_Symbol,OP_BUYLIMIT,TradeVolume,buy,slip,slbuy,tpbuy,NULL,MagicBuy,0,clrBlue); } void SellLimitOrder(int MagicSell) { double sell = pricetrading; // Ask+8*_Point; sell = NormalizeDouble(sell, _Digits); double slsellnew = sl; slsellnew = NormalizeDouble(slsellnew, _Digits); double tpsellnew = tp3; tpsellnew = NormalizeDouble(tpsellnew, _Digits); int ordersell = OrderSend (_Symbol,OP_SELLLIMIT,TradeVolume,sell,slip,slsellnew,tpsellnew,NULL,MagicSell,0,clrGreen); }