Download MetaTrader 5
To add comments, please log in or register
Do you know C++? MQL5 has much in common with it. Just try it yourself!
slavename
64
slavename 2014.07.09 19:30 

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
whroeder1
13644
whroeder1 2014.07.09 20:07  
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.
slavename
64
slavename 2014.07.09 20:19  
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)? 

whroeder1
13644
whroeder1 2014.07.09 20:32  
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()
slavename
64
slavename 2014.07.09 20:48  
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:

 

whroeder1
13644
whroeder1 2014.07.10 00:43  
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.
Ian Venner
2583
Ian Venner 2014.07.10 05:43  
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.

/
To add comments, please log in or register