refresh objects ?
if (showline != 0)
{
string name;
double d;
int i;
name = "LINE7";
d = iHigh(NULL, PERIOD_D1, 0);
i = 2;
for (;;)
{
if (ObjectSet(name, OBJPROP_PRICE1, d))
ObjectSet(name, OBJPROP_PRICE2, d);
else
{
ObjectCreate(name, OBJ_TREND, 0, iTime(NULL, PERIOD_D1, 0), d, Time[0], d);
ObjectSet(name, OBJPROP_COLOR, Blue);
ObjectSet(name, OBJPROP_RAY, 0);
}
i--;
if (i <= 0)
break;
name = "LINE8";
d = iLow(NULL, PERIOD_D1, 0);
}
}
I can't understand:
if (ObjectSet(name, OBJPROP_PRICE1, d))
ObjectSet(name, OBJPROP_PRICE2, d);
And I find a way to solve the prob:
dh=iHigh(NULL,PERIOD_D1,0);
dl=iLow(NULL,PERIOD_D1,0);
if(showline != 0)
{
if(ObjectFind("LINE7")==0) ObjectDelete("LINE7");
if(ObjectFind("LINE8")==0) ObjectDelete("LINE8");
ObjectCreate("LINE7",OBJ_TREND,0,iTime(NULL,PERIOD_D1,0),dh,Time[0],dh);
ObjectSet("LINE7", OBJPROP_COLOR, Blue);
ObjectSet("LINE7", OBJPROP_RAY, 0);
ObjectCreate("LINE8",OBJ_TREND,0,iTime(NULL,PERIOD_D1,0),dl,Time[0],dl);
ObjectSet("LINE8", OBJPROP_COLOR, Blue);
ObjectSet("LINE8", OBJPROP_RAY, 0);
}
I can't understand:
if (ObjectSet(name, OBJPROP_PRICE1, d))
ObjectSet(name, OBJPROP_PRICE2, d);
Refer to the documentation "MQL4: ObjectSet"
bool ObjectSet( string name, int index, double value) Changes the value of the specified object property. If the function succeeds, the returned value will be TRUE. Otherwise, it will be FALSE.
In the condition above you merely move the other end of the line if if the first ObjectSet succeeds meaning the line exists that is most likely scenario.
Otherwise you create the line and set its properties once.
And I find a way to solve the prob:
dh=iHigh(NULL,PERIOD_D1,0);
dl=iLow(NULL,PERIOD_D1,0);
if(showline != 0)
{
if(ObjectFind("LINE7")==0) ObjectDelete("LINE7");
if(ObjectFind("LINE8")==0) ObjectDelete("LINE8");
ObjectCreate("LINE7",OBJ_TREND,0,iTime(NULL,PERIOD_D1,0),dh,Time[0],dh);
ObjectSet("LINE7", OBJPROP_COLOR, Blue);
ObjectSet("LINE7", OBJPROP_RAY, 0);
ObjectCreate("LINE8",OBJ_TREND,0,iTime(NULL,PERIOD_D1,0),dl,Time[0],dl);
ObjectSet("LINE8", OBJPROP_COLOR, Blue);
ObjectSet("LINE8", OBJPROP_RAY, 0);
}
Graphic object functions might have a considerable performance penalty. Just count how many times the functions are called in you solution (a workaround actually).
Well, if you have a cpu that is capable to map human genome in minutes and don't mind paying electricity bills for the overhead, whatever... :)
if (ObjectSet(name, OBJPROP_PRICE1, d))
ObjectMove(name, 1, Time[0], d);
The main problem with graphic functions is that they refer graphic objects by their name given by a string variable no matter it's either a line or a label or something else. Every function seeks the object in the list by comparing given name with each object name. This might be rather slow if there are hundreds of objects even if the names are stored with a hash mechanism.
Anybody please help me with the following code, which is in an indicator that draw lines showing ceiling and floor of today's price......it uses DAY HIGH and LOW price as quote. The problem is: when price breaks thru (i.e. new ceiling/floor price occurs) , the lines do not refresh automatically...... untill I switch to D1 chart and then switch back. I tried to add "windowredraw", but it didn't work.
dh=iHigh(NULL,PERIOD_D1,0); dl=iLow(NULL,PERIOD_D1,0); if(showline==1) { ObjectCreate("LINE7",OBJ_TREND,0,iTime(NULL,PERIOD_D1,0),dh,Time[0],dh); ObjectSet("LINE7", OBJPROP_COLOR, Blue); ObjectSet("LINE7", OBJPROP_RAY, 0); ObjectCreate("LINE8",OBJ_TREND,0,iTime(NULL,PERIOD_D1,0),dl,Time[0],dl); ObjectSet("LINE8", OBJPROP_COLOR, Blue); ObjectSet("LINE8", OBJPROP_RAY, 0); } WindowRedraw();