Changing period means you close the current chart and open a new one with the new period. So of course you get a bad symbol, because you now have a bad ID. In addition you try to use ChartNext with the invalid ID.
Get the current chart ID. Get the next chart ID. Change the current chart. Do not look at the current chart/current ID.
Thanks WHRoeder1.
In the end I implemented the solution at the top of this thread: https://www.mql5.com/en/forum/140692
Change Timeframe on chart fuction or script
- www.mql5.com
Hi is there a way for change Timeframe only on select chart? I found this script but it changes Timeframe on all charts...
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello
I have a function in my EA:
I have several buttons on my charts to change the period for all charts. I click a button, and the whole lot switch, but when I click another button, ChartSymbol() appears to return a null symbol like the chart ID is now not valid, but the print statement appears to correctly list the chart ID in the print statement, and I notice the charts IDs do not change from one invocation of a chart set to the next.
The function returns the error
when one of the buttons (i.e. a function call with the _period set to one of the PERIOD_xx enumerated period integers) is clicked for the second time.
I think this is a bug as I had these buttons working for months, and then suddenly they stopped working.
Big thanks in advance, particularly for anyone who can recreate this problem.