为什么在 MQL4 中值改变时显示标签编号不改变?
Why doesn't display label number change when value changes in MQL4?
这是一个创建按钮的函数。
void CreateLabel(string labelname,string label,int xsize,int ysize,int xdist,int ydist,int bcolor,int fcolor) {
if(ObjectFind(0,labelname)<0) {
if(!ObjectCreate(0,labelname,OBJ_BUTTON,0,0,0)) {
Print(__FUNCTION__,
": failed to create the button! Error code = ",GetLastError());
return;
}
ObjectSetString(0,labelname,OBJPROP_TEXT,label);
ObjectSetInteger(0,labelname,OBJPROP_XSIZE,xsize);
ObjectSetInteger(0,labelname,OBJPROP_YSIZE,ysize);
ObjectSetInteger(0,labelname,OBJPROP_CORNER,CORNER_LEFT_UPPER);
ObjectSetInteger(0,labelname,OBJPROP_XDISTANCE,xdist);
ObjectSetInteger(0,labelname,OBJPROP_YDISTANCE,ydist);
ObjectSetInteger(0,labelname,OBJPROP_BGCOLOR,bcolor);
ObjectSetInteger(0,labelname,OBJPROP_COLOR,fcolor);
ObjectSetInteger(0,labelname,OBJPROP_FONTSIZE,8);
ObjectSetInteger(0,labelname,OBJPROP_HIDDEN,true);
//ObjectSetInteger(0,but_name,OBJPROP_BORDER_COLOR,ChartGetInteger(0,CHART_COLOR_FOREGROUND));
ObjectSetInteger(0,labelname,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ChartRedraw();
}
}
这里是函数调用
CreateLabel("EUROCSH4",IntegerToString(EUROCSH4,2),50 ,18,basket_x+i ,basket_y+40,C'35,35,35',clrWhite);
但是当我调用函数来改变 OBJPROP_TEXT 它没有改变。
将您的函数更改为:
void CreateLabel(string labelname,string label,int xsize,int ysize,int xdist,int ydist,int bcolor,int fcolor)
{
if(ObjectFind(0,labelname)<0)
{
if(!ObjectCreate(0,labelname,OBJ_BUTTON,0,0,0))
{
Print(__FUNCTION__,": failed to create the button! Error code = ",GetLastError());
return;
}
ObjectSetString(0,labelname,OBJPROP_TEXT,label);
ObjectSetInteger(0,labelname,OBJPROP_XSIZE,xsize);
ObjectSetInteger(0,labelname,OBJPROP_YSIZE,ysize);
ObjectSetInteger(0,labelname,OBJPROP_CORNER,CORNER_LEFT_UPPER);
ObjectSetInteger(0,labelname,OBJPROP_XDISTANCE,xdist);
ObjectSetInteger(0,labelname,OBJPROP_YDISTANCE,ydist);
ObjectSetInteger(0,labelname,OBJPROP_BGCOLOR,bcolor);
ObjectSetInteger(0,labelname,OBJPROP_COLOR,fcolor);
ObjectSetInteger(0,labelname,OBJPROP_FONTSIZE,8);
ObjectSetInteger(0,labelname,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,labelname,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ChartRedraw();
}
else
{
ObjectSetString(0,labelname,OBJPROP_TEXT,label);
}
}
这是一个创建按钮的函数。
void CreateLabel(string labelname,string label,int xsize,int ysize,int xdist,int ydist,int bcolor,int fcolor) {
if(ObjectFind(0,labelname)<0) {
if(!ObjectCreate(0,labelname,OBJ_BUTTON,0,0,0)) {
Print(__FUNCTION__,
": failed to create the button! Error code = ",GetLastError());
return;
}
ObjectSetString(0,labelname,OBJPROP_TEXT,label);
ObjectSetInteger(0,labelname,OBJPROP_XSIZE,xsize);
ObjectSetInteger(0,labelname,OBJPROP_YSIZE,ysize);
ObjectSetInteger(0,labelname,OBJPROP_CORNER,CORNER_LEFT_UPPER);
ObjectSetInteger(0,labelname,OBJPROP_XDISTANCE,xdist);
ObjectSetInteger(0,labelname,OBJPROP_YDISTANCE,ydist);
ObjectSetInteger(0,labelname,OBJPROP_BGCOLOR,bcolor);
ObjectSetInteger(0,labelname,OBJPROP_COLOR,fcolor);
ObjectSetInteger(0,labelname,OBJPROP_FONTSIZE,8);
ObjectSetInteger(0,labelname,OBJPROP_HIDDEN,true);
//ObjectSetInteger(0,but_name,OBJPROP_BORDER_COLOR,ChartGetInteger(0,CHART_COLOR_FOREGROUND));
ObjectSetInteger(0,labelname,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ChartRedraw();
}
}
这里是函数调用
CreateLabel("EUROCSH4",IntegerToString(EUROCSH4,2),50 ,18,basket_x+i ,basket_y+40,C'35,35,35',clrWhite);
但是当我调用函数来改变 OBJPROP_TEXT 它没有改变。
将您的函数更改为:
void CreateLabel(string labelname,string label,int xsize,int ysize,int xdist,int ydist,int bcolor,int fcolor)
{
if(ObjectFind(0,labelname)<0)
{
if(!ObjectCreate(0,labelname,OBJ_BUTTON,0,0,0))
{
Print(__FUNCTION__,": failed to create the button! Error code = ",GetLastError());
return;
}
ObjectSetString(0,labelname,OBJPROP_TEXT,label);
ObjectSetInteger(0,labelname,OBJPROP_XSIZE,xsize);
ObjectSetInteger(0,labelname,OBJPROP_YSIZE,ysize);
ObjectSetInteger(0,labelname,OBJPROP_CORNER,CORNER_LEFT_UPPER);
ObjectSetInteger(0,labelname,OBJPROP_XDISTANCE,xdist);
ObjectSetInteger(0,labelname,OBJPROP_YDISTANCE,ydist);
ObjectSetInteger(0,labelname,OBJPROP_BGCOLOR,bcolor);
ObjectSetInteger(0,labelname,OBJPROP_COLOR,fcolor);
ObjectSetInteger(0,labelname,OBJPROP_FONTSIZE,8);
ObjectSetInteger(0,labelname,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,labelname,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ChartRedraw();
}
else
{
ObjectSetString(0,labelname,OBJPROP_TEXT,label);
}
}