There is a problem of unsynchronisation of charts to the left and right of the total time line. I would like the bars to be synchronised by time for the whole width of the chart.
I suggest the developers to think again (perhaps, to put it up for discussion) about the possibility of visualising the chart with and without "holes"-bars. In this case, it would be only visualisation, i.e. "holes" bars would not be available in MQL5.
Dmitry, it would probably be easier to do it via CHARTEVENT_CLICK instead of looping...
here's an example of synchronising charts of one currency
//------------------------------------------------------------------ OnChartEvent void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam) { if (id==CHARTEVENT_CLICK) { long cid=ChartFirst(); long fbar=ChartGetInteger(ChartID(), CHART_FIRST_VISIBLE_BAR); datetime tm[], tm1[]; int rez=CopyTime(Symbol(), Period(), 0, fbar, tm); if (rez<fbar) return; while (cid!=-1) { ChartSetInteger(cid, CHART_AUTOSCROLL, false); ChartSetInteger(cid, CHART_SHIFT, false); if (cid!=ChartID() && ChartSymbol(cid)==Symbol()) { rez=CopyTime(ChartSymbol(cid), ChartPeriod(cid), TimeCurrent(), tm[0], tm1); if (rez<0) break; ChartNavigate(cid, CHART_END, rez-ChartGetInteger(cid, CHART_WIDTH_IN_BARS)+2); ChartRedraw(cid); } cid=ChartNext(cid); } } }
and that's it!
Dimitri, it would probably be easier to do via CHARTEVENT_CLICK instead of looping...
here is an example of synchronising charts of one currency
and that's it!
Not everything is so simple. Your function synchronises bars on the left edge of the chart, which is not very convenient for visual study of history. You should also disable chart offset, which is also not very convenient (although, it's a matter of taste). The developers would add the ability to get and set the indentation from the right edge or navigation by time in general, many functions are made in such a universal style that you can pass the bar number or time. Also, the event is processed only for the chart on which the script works.
----------------------------------------------------------------------------------------------------------------
OnChartEvent
OnChartEvent() is a handler of the ChartEvent group of events:
...
...
The function can be called only in EAs and must have void type and 4 parameters:
----------------------------------------------------------------------------------------------------------------
Event handling works only in Expert Advisors. There can be only one Expert Advisor on a chart, you should not take the place of an Expert Advisor with auxiliary and practically useless ones. This is my conviction that auxiliary tools that are not directly related to trade execution should not be made in the form of Expert Advisors, with a few exceptions of extreme necessity.
OnChartEvent
OnChartEvent() is a handler for the ChartEvent event group:
...
...
Thefunction can be called only in Expert Advisors and must have void type and 4 parameters:
----------------------------------------------------------------------------------------------------------------
Event processing works only in Expert Advisors. There can be only one Expert Advisor on a chart, you should not take the place of an Expert Advisor with auxiliary and practically useless ones. This is my conviction that auxiliary tools not directly related to trade execution should not be made in the form of Expert Advisors, with a few exceptions of extreme necessity.
This is no longer the case, keep an eye on the announcements - https://www.mql5.com/ru/forum/23/page4:
MetaTrader 5 Client Terminal build 245
- Terminal: Fixed the error of accounting for free margin funds in assets (in the Exposure tab).
- Terminal: Fixed operation of the "Chart on foreground" chart property.
- Terminal: Fixed and redesigned print preview window for chart.
- Terminal: Fixed a bug in working with temporary global variables.
- Terminal: Combined the "Standard" and "Charts" toolbars.
- MQL5: Corrections on crashes and forum messages
- MQL5: Changed the principle of operation of Copy* functions for Expert Advisors and scripts - now the functions will wait for downloading and building the requested data. The waiting time for requested data will not exceed 30 seconds. A more detailed description will be available in the MQL5 Help in the nearest future.
- MQL5: Added possibility of event processing by custom indicators, similar to Expert Advisors. A more detailed description will be available in the MQL5 Help in the near future.
.
It's not that simple. Your function synchronises bars on the left edge of the chart, which is not very convenient for visual study of history.
But it is possible to synchronise bars by any edge. and provide the trader with buttons for choosing - by centre, by right, by left....
The chart displacement should also be disabled, which is also not very convenient (although it is a matter of taste).
The developers would add the ability to get and set the indentation from the right edge or navigation by time in general, many functions are made in such a universal style that you can pass the bar number or time.
this feature is available by the way. CHART_SHIFT_SIZE
see the example ObjChartSample.mq5
Something seems to be wrong with CHART_FIRST_VISIBLE_BAR.
If you make ChartNavigate() to a number obviously larger than the number on which you can view the chart, then
ChartGetInteger(ChartID(),CHART_FIRST_VISIBLE_BAR) becomes greater than Bars(ChartSymbol(ChartID()),ChartPeriod(ChartID())).
Example in script 2.mq5. Run the script, wait a bit.
something tells me the terminal's not up to speed.
because if you run the script immediately again, it works the first time.
Maybe we need to control the time
Maybe SeriesInfoInteger will help?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
sChartsSynchroScroll:
The script provides a synchronous scrolling for all charts opened in the client terminal.
The script should be executed only on one chart. The red markers will be created on all of the opened charts after the script running. While scrolling of any chart, the other charts will be scrolled automatically so the bars with the same time will under these lines.
The input parameters of the script are absent.
Author: Дмитрий