How to navigate/move the chart to an created object or datetime

 

Few questions about chart navigation with MQL (programming, not UI use):

1) How can I navigate/move/focus the chart to an existing object If I know the object name? (in a similar way when I click show in the objects list)

2) How can I navigate/move/focus the chart to a specified datetime?

 
Perhaps you should read the manual (Edited by moderator). ChartNavigate - Chart Operations - MQL4 Reference
 
  1. Use the "ObjectFind()" to get a specified named object and then use "ObjectGetTimeByValue()" to get its date/time.
  2. Get the Charts Symbol and Period with the functions "ChartSymbol()" and "ChartPeriod()".
  3. With the date and time (from step 1), find the bar shift with the "iBarShift()" function for the specified symbol and period obtained in the step 2.
  4. Disable the auto scrolling of the chart with the "ChartSetInteger()" function and the CHART_AUTOSCROLL property with a value of "0" equivalent to "false".
  5. Obtain the chart's current bar positioning, using the "ChartGetInteger()" function and the properties CHART_FIRST_VISIBLE_BAR and CHART_VISIBLE_BARS.
  6. Calculate the required bar positioning offset and then use the function "ChartNavigate()" to position the chart according to your requirements.
 

Thank you a lot FMIC!

Such step by step description was exaclty what I was looking for! Thank you!

 
Fernando Carreiro:
  1. Use the "ObjectFind()" to get a specified named object and then use "ObjectGetTimeByValue()" to get its date/time.
  2. Get the Charts Symbol and Period with the functions "ChartSymbol()" and "ChartPeriod()".
  3. With the date and time (from step 1), find the bar shift with the "iBarShift()" function for the specified symbol and period obtained in the step 2.
  4. Disable the auto scrolling of the chart with the "ChartSetInteger()" function and the CHART_AUTOSCROLL property with a value of "0" equivalent to "false".
  5. Obtain the chart's current bar positioning, using the "ChartGetInteger()" function and the properties CHART_FIRST_VISIBLE_BAR and CHART_VISIBLE_BARS.
  6. Calculate the required bar positioning offset and then use the function "ChartNavigate()" to position the chart according to your requirements.
how to calculate the required bar positiong offset?
 
Fernando Carreiro #:
  1. Use the "ObjectFind()" to get a specified named object and then use "ObjectGetTimeByValue()" to get its date/time.
  2. Get the Charts Symbol and Period with the functions "ChartSymbol()" and "ChartPeriod()".
  3. With the date and time (from step 1), find the bar shift with the "iBarShift()" function for the specified symbol and period obtained in the step 2.
  4. Disable the auto scrolling of the chart with the "ChartSetInteger()" function and the CHART_AUTOSCROLL property with a value of "0" equivalent to "false".
  5. Obtain the chart's current bar positioning, using the "ChartGetInteger()" function and the properties CHART_FIRST_VISIBLE_BAR and CHART_VISIBLE_BARS.
  6. Calculate the required bar positioning offset and then use the function "ChartNavigate()" to position the chart according to your requirements.

Both CHART_FIRST_VISIBLE_BAR and CHART_VISIBLE_BARS are read only properties.

Chart Properties - Chart Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5


  But strangely I can modify CHART_FIRST_VISIBLE_BAR but cannot modify  CHART_VISIBLE_BARS.  I have searched through documentation, does not seem to be able to control how many bars to display in a chart.

Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Properties
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Properties
  • www.mql5.com
Chart Properties - Chart Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: