การสร้างปุ่ม Button ทำไมไม่สามารถ เบ็คเทสได้ครับ
พอเขียนเสร็จมันใช้ได้เฉพาะการ forward test ครับ มันต้องเขียนอะไรเพิ่มเติมหรือเปล่าครับ
//+------------------------------------------------------------------+
//| Create the Close button |
//+------------------------------------------------------------------+
bool Create_CloseButton(const long chart_ID=0, // chart's ID
const string name="Button_Close", // button name
const int sub_window=0, // subwindow index
const int x=100,// X coordinate
const int y=250,// Y coordinate
const int width=170, // button width
const int height=40, // button height
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring
const string text="Close All", // text
const string font="Courier New", // font
const int font_size=16, // font size
const color clr=clrWhite, // text color
const color back_clr=clrGreen, // background color
const bool back=false // in the background
)
{
//--- reset the error value
ResetLastError();
//--- create the button
ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0);
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| Create the Close button |
//+------------------------------------------------------------------+
bool Create_CloseBuyStopButton(const long chart_ID=0, // chart's ID
const string name="Button_BuyStop", // button name
const int sub_window=0, // subwindow index
const int x=200,// X coordinate
const int y=250,// Y coordinate
const int width=170, // button width
const int height=40, // button height
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring
const string text="Close BuyStop", // text
const string font="Courier New", // font
const int font_size=16, // font size
const color clr=clrWhite, // text color
const color back_clr=clrGreen, // background color
const bool back=false // in the background
)
{
//--- reset the error value
ResetLastError();
//--- create the button
ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0);
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
void CloseOrder()
{
//Close Long Order
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUYLIMIT)
{
//-------------------------------------------------------------------------------------------------
double CloseBuyLimit=OrderDelete(OrderTicket());
//-------------------------------------------------------------------------------------------------
//ChartSetInteger(0,CHART_COLOR_FOREGROUND,clrSteelBlue);
//-------------------------------------------------------------------------------------------------
}
if(OrderType()==OP_SELLLIMIT)
{
//-------------------------------------------------------------------------------------------------
double CloseSellLimit=OrderDelete(OrderTicket());
//-------------------------------------------------------------------------------------------------
//ChartSetInteger(0,CHART_COLOR_FOREGROUND,clrSteelBlue);
//-------------------------------------------------------------------------------------------------
}
if(OrderType()==OP_BUYSTOP)
{
//-------------------------------------------------------------------------------------------------
double CloseBuyStop=OrderDelete(OrderTicket());
//-------------------------------------------------------------------------------------------------
//ChartSetInteger(0,CHART_COLOR_FOREGROUND,clrSteelBlue);
//-------------------------------------------------------------------------------------------------
}
if(OrderType()==OP_SELLSTOP)
{
//-------------------------------------------------------------------------------------------------
double CloseSellStop=OrderDelete(OrderTicket());
//-------------------------------------------------------------------------------------------------
//ChartSetInteger(0,CHART_COLOR_FOREGROUND,clrSteelBlue);
//-------------------------------------------------------------------------------------------------
}
}
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//---
if(id==CHARTEVENT_OBJECT_CLICK)
{
if(sparam=="Button_Close")
{
CloseOrder();
ObjectSetInteger(0,"Button_Close",OBJPROP_STATE,false);
}
}
}
//+------------------------------------------------------------------+