|
- //+------------------------------------------------------------------+
- //| ProjectName |
- //| Copyright 2018, CompanyName |
- //| http://www.companyname.net |
- //+------------------------------------------------------------------+
- #property copyright "573"
- #property link "https://www.mql5.com"
- #property version "1.00"
- #property strict
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- int OnInit()
- {
- anniu("closeall",clrWhite,260,30,"全部清仓");
- anniu("delgua",clrWhite,260,70,"删除挂单");
- anniu("closeallduo",clrWhite,260,110,"多单全平");
- anniu("closeallkong",clrWhite,260,150,"空单全平");
- //biaoqian("duotp","输入止盈价格",280,197,14,White);
- shurukuang("duotp",Black,350,190);
- anniu("duotpm",clrWhite,260,190,"多单止盈");
- shurukuang("kongtp",Black,350,230);
- anniu("kongtpm",clrWhite,260,230,"空单止盈");
- return(INIT_SUCCEEDED);
- }
- //+------------------------------------------------------------------+
- //| Expert deinitialization function |
- //+------------------------------------------------------------------+
- void OnDeinit(const int reason)
- {
- //---
- }
- //+------------------------------------------------------------------+
- //| Expert tick function |
- //+------------------------------------------------------------------+
- void OnTick()
- {
- //---
- }
- //+------------------------------------------------------------------+
- //| ChartEvent function |
- //+------------------------------------------------------------------+
- void OnChartEvent(const int id,
- const long &lparam,
- const double &dparam,
- const string &sparam)
- {
- if(id==CHARTEVENT_OBJECT_CLICK)
- {
- if(sparam=="closeall")
- {
- closeall();
- }
- if(sparam=="delgua")
- {
- delgua();
- }
- if(sparam=="closeallduo")
- {
- closeallduo();
- }
- if(sparam=="closeallkong")
- {
- closeallkong();
- }
- if(sparam=="duotpm")
- {
- string duotp=ObjectGetString(0,"duotp",OBJPROP_TEXT);
- //Alert ("输入框的文字为:"+duotp);
- modifyduo(StringToDouble(duotp));
- }
- if(sparam=="kongtpm")
- {
- string kongtp=ObjectGetString(0,"kongtp",OBJPROP_TEXT);
- //Alert ("输入框的文字为:"+kongtp);
- modifykong(StringToDouble(kongtp));
- }
- }
- }
- //+------------------------------------------------------------------+
- void anniu(string name,color yanse,int x,int y,string text,int changdu=0)
- {
- ObjectCreate(0,name,OBJ_BUTTON,0,0,0);
- ObjectSetInteger(0,name,OBJPROP_COLOR,yanse);
- ObjectSetInteger(0,name,OBJPROP_BGCOLOR,clrDarkGreen);
- ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
- ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
- if(changdu==0)
- {
- int as=StringLen(text);
- ObjectSetInteger(0,name,OBJPROP_XSIZE,as*20);
- }
- else
- {
- ObjectSetInteger(0,name,OBJPROP_XSIZE,changdu);
- }
- ObjectSetInteger(0,name,OBJPROP_YSIZE,30);
- ObjectSetString(0,name,OBJPROP_FONT,"Arial");
- ObjectSetString(0,name,OBJPROP_TEXT,text);
- ObjectSetInteger(0,name,OBJPROP_FONTSIZE,12);
- ObjectSetInteger(0,name,OBJPROP_BORDER_COLOR,clrOrange);
- ObjectSetInteger(0,name,OBJPROP_CORNER,1);
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void shurukuang(string name, color yanse, int x, int y)
- {
- ObjectCreate(0,name,OBJ_EDIT,0,0,0) ;
- ObjectSetInteger(0, name, OBJPROP_XDISTANCE,x) ;
- ObjectSetInteger(0, name, OBJPROP_YDISTANCE,y) ;
- //--- set object size
- ObjectSetInteger(0, name, OBJPROP_XSIZE, 81) ;
- ObjectSetInteger(0, name, OBJPROP_YSIZE,30) ;
- ObjectSetInteger(0, name, OBJPROP_FONTSIZE,14) ;
- //--- set the type of text alignmerk in the object
- ObjectSetInteger(0, name, OBJPROP_ALIGN, ALIGN_LEFT) ;
- //--- enable (true) or cancle (false) read-only mode
- ObjectSetInteger(0, name, OBJPROP_READONLY, false) ;
- //--- set the chart's corner, relative to which object coo
- ObjectSetInteger(0, name, OBJPROP_CORNER,1) ;
- //--- set text color
- ObjectSetInteger(0, name, OBJPROP_COLOR, yanse) ;
- //--- set border color
- ObjectSetInteger(0,name,OBJPROP_BORDER_COLOR,clrBlue);
- //--- display in the foreground (false) or background ()
- ObjectSetInteger(0,name,OBJPROP_BACK,false);
- ObjectSetString(0,name,OBJPROP_TEXT,"");
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void biaoqian(string name, string neirong,int x,int y,int daxiao,color yanse)
- {
- if(ObjectFind(name)<0)
- {
- ObjectCreate(name, OBJ_LABEL,0,0,0);
- ObjectSetText(name, neirong, daxiao, "宋体", yanse);
- ObjectSet(name, OBJPROP_XDISTANCE,x);
- ObjectSet(name, OBJPROP_YDISTANCE,y);
- ObjectSet(name, OBJPROP_CORNER,1);
- }
- else
- {
- ObjectSetText(name,neirong,daxiao,"宋体", yanse);
- WindowRedraw();
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void closeall()
- {
- int cnt, total;
- total=OrdersTotal();
- for(cnt=total-1;cnt>=0;cnt--)
- {
- OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
- if(OrderType()==OP_SELL)
- {
- OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
- }
- if(OrderType()==OP_BUY)
- {
- OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
- }
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void closeallduo()
- {
- int cnt, total;
- total=OrdersTotal();
- for(cnt=total-1;cnt>=0;cnt--)
- {
- OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
-
- if(OrderType()==OP_BUY)
- {
- OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
- }
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void closeallkong()
- {
- int cnt, total;
- total=OrdersTotal();
- for(cnt=total-1;cnt>=0;cnt--)
- {
- OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
- if(OrderType()==OP_SELL)
- {
- OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
- }
-
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void delgua()
- {
- int total = OrdersTotal();
- for(int i=total-1;i>=0;i--)
- {
- OrderSelect(i, SELECT_BY_POS);
- int type = OrderType();
- bool result = false;
-
- switch(type)
- {
- //Close pending orders
- case OP_BUYLIMIT :
- case OP_BUYSTOP :
- case OP_SELLLIMIT :
- case OP_SELLSTOP : result = OrderDelete( OrderTicket() );
- }
-
- if(result == false)
- {
- //Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
- //Sleep(3000);
- }
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void modifyduo(double duotp)
- {
- int t=OrdersTotal() ;
- for(int i=t-1; i>=0; i--)
- if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
- if(OrderSymbol()==Symbol())
- double p=MarketInfo(OrderSymbol(),MODE_POINT) ;
- if(OrderType()==OP_BUY)
- {
- OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(),OrderTakeProfit(),0,clrOrangeRed);
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void modifykong(double kongtp)
- {
- int t=OrdersTotal() ;
- for(int i=t-1; i>=0; i--)
- if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
- if(OrderSymbol()==Symbol())
- double p=MarketInfo(OrderSymbol(),MODE_POINT) ;
- if(OrderType()==OP_SELL)
- {
- OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(),OrderTakeProfit(),0,clrDodgerBlue);
- }
- }
复制代码 |
|