这里是文章模块栏目内容页
绝地求生辅助菜单(MT4量化交易编程—EA添加手动辅助按钮菜单模块)


代码如下:

  //---

ButtonCreate(0,"Buy",0,5,250,50,20,0,"Buy2"); ButtonCreate(0,"平多单",0,57,250,50,20,0,"平多单");

ButtonCreate(0,"Sell",0,5,272,50,20,0,"Sell2");ButtonCreate(0,"平空单",0,57,272,50,20,0,"平空单");

ButtonCreate(0,"只做多",0,5,294,50,20,0,"只做多");ButtonCreate(0,"只做空",0,57,294,50,20,0,"只做空");

//---

return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{//---

ObjectDelete(0,"Buy");

ObjectDelete(0,"Sell");

ObjectDelete(0,"平多单");

ObjectDelete(0,"平空单");

ObjectDelete(0,"只做多");

ObjectDelete(0,"只做空");

//----

// Comment("");

//----

// return;

}

//+------------------------------------------------------------------+

//| ChartEvent function |

//+------------------------------------------------------------------+

void OnChartEvent(const int id,

const long &lparam,

const double &dparam,

const string &sparam)

{

//---

double result=0;

if(id==CHARTEVENT_OBJECT_CLICK && sparam=="Buy"&&ObjectGetInteger(0,"Buy",OBJPROP_STATE))

{

result=OrderSend(Symbol(), OP_BUY,lots2, Ask, slippage*db, 0, 0, comt+"b1", Magic, 0, Blue);

}

if(id==CHARTEVENT_OBJECT_CLICK && sparam=="Sell"&&ObjectGetInteger(0,"Sell",OBJPROP_STATE))

{

result=OrderSend(Symbol(), OP_SELL, lots2, Bid, slippage*db, 0, 0, comt+"s1", Magic, 0, Red);

}

if(id==CHARTEVENT_OBJECT_CLICK && sparam=="平多单"&&ObjectGetInteger(0,"平多单",OBJPROP_STATE))

{

//if(OrderProfit()>=2)

CloseAllOrdersBuy();

}

if(id==CHARTEVENT_OBJECT_CLICK && sparam=="平空单"&&ObjectGetInteger(0,"平空单",OBJPROP_STATE))

{

//if(OrderProfit()>=2)

CloseAllOrdersSell();

}

// /*

if(id==CHARTEVENT_OBJECT_CLICK && sparam=="只做多"&&ObjectGetInteger(0,"只做多",OBJPROP_STATE))

{

if(NOShort==false)

NOShort=true;

}

if(id==CHARTEVENT_OBJECT_CLICK && sparam=="只做空"&&ObjectGetInteger(0,"只做空",OBJPROP_STATE))

{

if(NOLong==false)

NOLong=true;

}

// */

}

//+------------------------------------------------------------------+

bool ButtonCreate(const long chart_ID=0, // chart's ID

const string name="Button", // button name

const int sub_window=0, // subwindow index

const int x=0, // X coordinate

const int y=0, // Y coordinate

const int width=40, // button width

const int height=15, // button height

const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring

const string text="Button", // text

const string font="Arial", // font

const int font_size=8, // font size

const color clr=clrBlack, // text color

const color back_clr=C'236,233,216', // background color

const color border_clr=clrRed,//clrNONE, // border color

const bool state=false, // pressed/released

const bool back=false, // // in the background

const bool selection=false, // highlight to move

const bool hidden=true, // hidden in the object list

const long z_order=0) // priority for mouse click

{

//--- reset the error value

ResetLastError();

//--- create the button

if(!ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0))

{

Print(__FUNCTION__,

": failed to create the button! Error code = ",GetLastError());

return(false);

}

//--- set button coordinates

ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);

ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

//--- set button size

ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);

ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);

//--- set the chart's corner, relative to which point coordinates are defined

ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);

//--- set the text

ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

//--- set text font

ObjectSetString(chart_ID,name,OBJPROP_FONT,font);

//--- set font size

ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);

//--- set text color

ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

//--- set background color

ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);

//--- set border color

ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);

//--- display in the foreground (false) or background (true)

ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

//--- set button state

ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state);

//--- enable (true) or disable (false) the mode of moving the button by mouse

ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

//--- hide (true) or display (false) graphical object name in the object list

ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

//--- set the priority for receiving the event of a mouse click in the chart

ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

//--- successful execution

return(true);

}

//+----------------------------------

收藏
0
有帮助
0
没帮助
0
相关内容