• Sign up >>

Redraw at new day

To add comments, please log in or register
cronofobico
10
cronofobico  

I'm building an EA that uses last day's maximum and minimum price.

For now, I'm coding this on OnInit():


   // SETTING MIN AND MAX OF LAST DAY
   MqlRates PriceDataTableDaily[];  
   CopyRates(_Symbol,PERIOD_D1,0,1,PriceDataTableDaily);
   
   lastHigh = PriceDataTableDaily[0].high;
   lastLow = PriceDataTableDaily[0].low;
   
   HLineCreate(
      0,
      "Max",
      0,
      lastHigh,
      clrRed,
      STYLE_SOLID,
      1,
      false,
      false,
      true,
      0);
      
   HLineCreate(
      0,
      "Min",
      0,
      lastLow,
      clrRed,
      STYLE_SOLID,
      1,
      false,
      false,
      true,
      0);


The problem is that these lines are drawn at the start of the EA and never changes (eg: when day changes). I tried coding this in OnTick() but it doesn't work.


Is there a way to know when the day changes? If so, how can I recalculate the lastLow and lastHigh when it happens?

(Please MQL5 code, I found a lot of MQL4 possible answers that I can't implement)

William Roeder
20384
William Roeder  
Of course, it doesn't move. You can only create an object once. You need to move it.
Anthony Garot
3530
Anthony Garot  

cronofobico:

Is there a way to know when the day changes?

On the daily chart, you know the day changes when the SERIES_LASTBAR_DATE changes. Look up "IsNewBar" in this forum.

cronofobico:

If so, how can I recalculate the lastLow and lastHigh when it happens?

Much like you are doing now with CopyRates, but do this when the new bar occurs. That's when you move your lines.

And don't forget to check your return values. CopyRates() may or may not give you what you expect, so check it.

cronofobico
10
cronofobico  
William Roeder:
Of course, it doesn't move. You can only create an object once. You need to move it.

A good example of a non-explanatory answer. I didn't know about this.


Anthony Garot:

On the daily chart, you know the day changes when the SERIES_LASTBAR_DATE changes. Look up "IsNewBar" in this forum.

Much like you are doing now with CopyRates, but do this when the new bar occurs. That's when you move your lines.

And don't forget to check your return values. CopyRates() may or may not give you what you expect, so check it.

I checked the IsNewBar and it might get me where I want. I'll test it and let you know.

I'm using CopyRates() to get the last maximum and minimum value of last day. Am I doing it wrong?

To add comments, please log in or register