Download MetaTrader 5

Vline 50 bars after the current time/bar - page 3

To add comments, please log in or register
Mladen Rakic
83903
Mladen Rakic  

Move the call to Display_Vlines() from the OnChartEvent() to OnCalculate()

Or click on the chart whenever you want to refresh it :) As simple click on the chart will do the way your code is written. But you have more issues with that code (starting from the fact that your Current_Time is fixed to the time when indicator is attached or reloaded)

Thierry Ramaniraka
364
Thierry Ramaniraka  
Mladen Rakic:

Move the call to Display_Vlines() from the OnChartEvent() to OnCalculate()

Or click on the chart whenever you want to refresh it :) As simple click on the chart will do the way your code is written. But you have more issues with that code (starting from the fact that your Current_Time is fixed to the time when indicator is attached or reloaded)

Hello mladen,
Already tried, but didn't work.
When a new bar comes (tested on M1), the Vlines stay in place et do not refresh and replace on their new bar.
I have to change the time frame...

Any idea why ?

Mladen Rakic
83903
Mladen Rakic  
Thierry Ramaniraka:

Hello mladen,
Already tried, but didn't work.
When a new bar comes (tested on M1), the Vlines stay in place et do not refresh and replace on their new bar.
I have to change the time frame...

Any idea why ?

Adjust time for existing objects. ObjectCreate() does not adjust time component for objects already existing
Thierry Ramaniraka
364
Thierry Ramaniraka  
Mladen Rakic:
Adjust time for existing objects. ObjectCreate() does not adjust time component for objects already existing

And what can adjust the time please ?

Mladen Rakic
83903
Mladen Rakic  
Thierry Ramaniraka:

And what can adjust the time please ?

ObjectSetInteger() for time component - see the details here : https://www.mql5.com/en/docs/objects/objectsetinteger
Documentation on MQL5: Object Functions / ObjectSetInteger
Documentation on MQL5: Object Functions / ObjectSetInteger
  • www.mql5.com
//|                                               Table of Web Colors| //|                         Copyright 2011, MetaQuotes Software Corp | //|                                        https://www.metaquotes.net | //| Array of web colors                                              |...
whroeder1
17824
whroeder1  
datetime time2 = Time[0]+(Datas_BarShift_Time-1)*PeriodSeconds();
datetime time3 = Time[0]+(Datas_BarShift_Time2-1)*PeriodSeconds();
datetime Current_Time = TimeCurrent();
These are globally declared variables, they are initialized once on load. They don't update unless you assign to them. Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent and prices are valid.
Thierry Ramaniraka
364
Thierry Ramaniraka  
Mladen Rakic:

Move the call to Display_Vlines() from the OnChartEvent() to OnCalculate()

Or click on the chart whenever you want to refresh it :) As simple click on the chart will do the way your code is written. But you have more issues with that code (starting from the fact that your Current_Time is fixed to the time when indicator is attached or reloaded)

Hello,
I have tried again and it's ok now...maybe it was to late for me yesterday.
thank you.

123
To add comments, please log in or register