ChartRedraw(0) and WindowRedraw() failures

 

I have read and tried every forum post about refreshing/updating charts on new bar.  I can't get any of them to work, even those that seem to be working for others.  For example the following two versions of the same one, both placed within start().  What am I doing wrong?!

 Edit:  I also tried it inline (example 3) to no avail...

//refresh on new bar
static datetime oldTime; //define the variable
if(oldTime == 0) oldTime = Time[0];

if(oldTime != Time[0] )
  {
    WindowRedraw();
    oldTime = Time[0];
  }
//refresh on new bar
static datetime oldTime; //define the variable
if(oldTime == 0) oldTime = Time[0];

if(oldTime != Time[0] )
  {
    ChartRedraw(0);
    oldTime = Time[0];
  }
//H4 150
ObjectCreate(ChartID(),h4ShortE,OBJ_HLINE,0,0, h4Short);
ObjectSetInteger(ChartID(),h4ShortE,OBJPROP_COLOR,clrBlue);
ObjectSetInteger(ChartID(),h4ShortE,OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(ChartID(),h4ShortE,OBJPROP_WIDTH,1);
ChartRedraw(0); //WindowRedraw(); also tried
 
alyehoud: I have read and tried every forum post about refreshing/updating charts on new bar. I can't get any of them to work, even those that seem to be working for others.  For example the following two versions of the same one, both placed within start(). What am I doing wrong?!

  1. Time[0] only changes when a new bar starts. Your code is for the detection of a new bar, which only triggers once per hour on the H1
  2. The chart redraws itself when you return from start/ontick.
    Delete the code and just return.
 
WHRoeder:
alyehoud: I have read and tried every forum post about refreshing/updating charts on new bar. I can't get any of them to work, even those that seem to be working for others.  For example the following two versions of the same one, both placed within start(). What am I doing wrong?!

  1. Time[0] only changes when a new bar starts. Your code is for the detection of a new bar, which only triggers once per hour on the H1
  2. The chart redraws itself when you return from start/ontick.
    Delete the code and just return.


WHRoeder, I think you may have written that code actually.  I read quite a few of yours posts on the topic.

Referring to your points:

1. correct, it should be detecting the new bar, and then running WindowRedraw(); but it's not redrawing - I tried it on the M1 chart by changing all variables (and left it overnight and no changes even still).  It's simply just not updating, unless I manually do it.

2. By 'delete the code', are you saying that it the whole thing is redundant and unnecessary (because it's not updating without the code, either)? 

 
alyehoud: WHRoeder, I think you may have written that code actually .. but it's not redrawing -
ObjectCreate(ChartID(),h4ShortE,OBJ_HLINE,0,0, h4Short);
ObjectSetInteger(ChartID(),h4ShortE,OBJPROP_COLOR,clrBlue);
ObjectSetInteger(ChartID(),h4ShortE,OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(ChartID(),h4ShortE,OBJPROP_WIDTH,1);
ChartRedraw(0); //WindowRedraw(); also tried
  1. Not my code, I've never used either redraw.
  2. How do you know it's not redrawing? How do you expect to see a Hline at zero?
  3. You don't even know that you're creating an object.
  4. See What are Function return values ? How do I use them ? - MQL4 forum
  5. See my TLine()
 
WHRoeder:
alyehoud: WHRoeder, I think you may have written that code actually .. but it's not redrawing -
  1. Not my code, I've never used either redraw.
  2. How do you know it's not redrawing? How do you expect to see a Hline at zero?
  3. You don't even know that you're creating an object.
  4. See What are Function return values ? How do I use them ? - MQL4 forum
  5. See my TLine()


I don't believe its redrawing because after it draws the initial lines, as the variable changes, the lines are static.  It's not until I manually do it (change time frame and back) that it corrects.  Hline is showing fine at time zero?

See this:

 

 
alyehoud: I don't believe its redrawing
Now you mention redrawing. That not the same as not drawing. It is drawing and refresh is irrelevant.
Do #4 and you will find your answer.
 
alyehoud:

I have read and tried every forum post about refreshing/updating charts on new bar.  I can't get any of them to work, even those that seem to be working for others.  For example the following two versions of the same one, both placed within start().  What am I doing wrong?!

 Edit:  I also tried it inline (example 3) to no avail...


Your problem is twofold

  1. You are wrongly assuming the new bar detection code doesn't work because the object didn't move.
  2. You are wrongly assuming the object will move when you redraw the chart because you used a variable h4short as a price coordinate.

The object with that name is created once, it doesn't matter how much you redraw the chart, ObjectCreate won't create the same object a second time unless you delete it.

If you want the object to move you should change the object's relevent coordinate parameter.

Use either ObjectSetDouble() with OBJPROP_PRICE or ObjectSet() with OBJPROP_PRICE1 to change the object's price coordinate.

 

Hello there, i think i have a problem relative to this Refreshing problem

The indicator i've coded should show arrows when crosses happens, but, unfortunately, it only show when i toggle timeframe (lige going to M5 and come back to the first timeframe)

I tried to use chartredraw and windowredraw but nothing happens. It still "lag"

 
Stop thinking; you do not have a refresh problem. Your code is broken; fix your broken code.
Reason: