refresh objects ?

 
Hi,
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(); 
 
Use ObjectMove() or ObjectSet() to change position of existing 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);
        }
    }


 
Thanks Irtron.
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);    
     }
 
Thanks Irtron.
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... :)

 
The problem is not only about the latter end of the line ---- say today's lowest price is 1.2300, the indicator draws a line at 1.2300, then price becomes 1.2295, but that line is still at 1.2300.
 
The problem is not only about the latter end of the line ---- say today's lowest price is 1.2300, the indicator draws a line at 1.2300, then price becomes 1.2295, but that line is still at 1.2300.
There are two ObjectSet() calls that move both ends of the line. The same lines follow today's Low and High. No line creating and setting all the properties after deleting the lines every time.
 
The problem is not only about the latter end of the line ---- say today's lowest price is 1.2300, the indicator draws a line at 1.2300, then price becomes 1.2295, but that line is still at 1.2300.
There is another problem in my example though. I've missed the fact that the right end of the line should follow zero bar. ObjectMove does the trick. Here is the fix:
            if (ObjectSet(name, OBJPROP_PRICE1, d))
                ObjectMove(name, 1, Time[0], d); 



 
Now I could fully understand your code. Quite subtle......I've learnd a lot from this code. Thanks, Irtron !!!
 
BTW, you said:"Graphic object functions might have a considerable performance penalty", does that include LABEL objects ?
 
BTW, you said:"Graphic object functions might have a considerable performance penalty", does that include LABEL objects ?
I suppose so.
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.
 
Ok, I'll try to use COMMENT instead.
Reason: