
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
Just a small (typo) correction : it is ChartSetSymbolPeriod(0,NULL,0) not ChartSetSymbol(0,NULL,0)
Yes of course, thanks, fixed.
PS: when the time frame data is loaded for the first time since the terminal started (the target time frame or the chart time frame), that will not work either
Using ChartSetSymbolPeriod() is like using a hammer to kill a fly, I don't use it myself anymore, but that's the Metaquotes recommended solution so I preferred to stay simple : it "works in most cases".
Yes of course, thanks, fixed.
Using ChartSetSymbolPeriod() is like using a hammer to kill a fly, I don't use it myself anymore, but that's the Metaquotes recommended solution so I preferred to stay simple : it "works in most cases".
Thank you.
I just did a test, the solution works.
https://www.mql5.com/en/docs/chart_operations/chartsetsymbolperiod
ChartSetSymbolPeriod
Changes the symbol and period of the specified chart. The function is asynchronous, i.e. it sends the command and does not wait for its execution completion. The command is added to chart messages queue and will be executed after processing of all previous commands.
...
Note
The symbol/period change leads to the re-initialization of the Expert Advisor attached to a chart.
The call of ChartSetSymbolPeriod with the same symbol and timeframe can be used to update the chart (similar to the terminal's Refresh command). In its turn, the chart update triggers re-calculation of the indicators attached to it. Thus, you are able to calculate an indicator on the chart even if there are no ticks (e.g., on weekends).
https://www.mql5.com/en/docs/chart_operations/chartsetsymbolperiod
ChartSetSymbolPeriod
Changes the symbol and period of the specified chart. The function is asynchronous, i.e. it sends the command and does not wait for its execution completion. The command is added to chart messages queue and will be executed after processing of all previous commands.
...
Note
The symbol/period change leads to the re-initialization of the Expert Advisor attached to a chart.
The call of ChartSetSymbolPeriod with the same symbol and timeframe can be used to update the chart (similar to the terminal's Refresh command). In its turn, the chart update triggers re-calculation of the indicators attached to it. Thus, you are able to calculate an indicator on the chart even if there are no ticks (e.g., on weekends).
The documentation is misleading, this function not only reinitialize the indicators attached on a chart, but all indicators/EAs/scripts attached to all charts using the considered symbol. Say you have X indicators on Y charts, they can all send this "refresh" command and will all receive the messages from the queue, resulting in a cascade of updates. That's why I talked about a hammer for a fly.
With basic indicators it's not a problem, with heavy and complex indicators it's a hell.
Yes, it seems that MT5 has some stupid behaviour. I'm also struggling with the "weekend" problem.
I found that this code is problematic:
It gives 0 to me when I'm switching between time frames.
When I'm switching between M1/M5/M15/M30/H1 it works well, but above H1 it doesnt work and gives 0 (although there are bars on the chart, the indicator cannot "see" them).
I have no idea. Extremely annoying.
I tried this example to update the bars and get the proper value, but no success.
I did a test,iBars() works well.
"weekend" problem can be solved by calling ChartSetSymbolPeriod(...).
On MT4: Unless the current chart is that specific pair/ TF referenced, you must handle 4066/4073 errors before accessing prices.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4
The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero the first call.
On MT5: Unless the chart is that specific pair/ TF, you must Synchronize the terminal Data from the Server.
Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum
Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum
Thank you for the shared expierence.
It is very important to check "Synchronize" in MT5 coding when refer to different pair/TF.
From the Test 1, After the chart A received another "tick message" ,it called OnCalculate() again,and then the MA-MTF worked.
Now,the problem can be solved by send a message to the chart message queue.
The documentation is misleading, this function not only reinitialize the indicators attached on a chart, but all indicators/EAs/scripts attached to all charts using the considered symbol. Say you have X indicators on Y charts, they can all send this "refresh" command and will all receive the messages from the queue, resulting in a cascade of updates. That's why I talked about a hammer for a fly.
With basic indicators it's not a problem, with heavy and complex indicators it's a hell.
Yes, all charts with the same symbol will receive the message one or more times, and call OnCalculate(..) again, but there is no calling OnInit().
I Modified some codes,and did test as below:
In MA-MTF.mq5
Test 6: 4 charts. Chart A without any indicator, Chart B/C/D with "test_event_trigger"
load the "MA-MTF" to the chart A, it will send "message " to all charts with "GBPUSD"...
The test result:
Before loading the "MA-MTF" to the chart A :
After loading the "MA-MTF" to the chart A :
Chart A: got message 1 time
Chart B: got message 2 times
Chart C: got message 1 time
Chart D: got message 2 times
After testing, check the journal, there is no calling OnInit() :
-----
All files (screenshots and mq5) are attached.
All tests I did under the conditions:
1. MT5 : Version 5.0, Build 2072, June 07,2019
2. Disconnected to the server ( turn off the WIFI).
After testing, check the journal, there is no calling OnInit() :
Of course there is no OnInit() call, why are you expecting that ?
Only OnCalculate() is called.
Of course there is no OnInit() call, why are you expecting that ?
Only OnCalculate() is called.
The documentation is misleading, this function not only reinitialize the indicators attached on a chart, but all indicators/EAs/scripts attached to all charts using the considered symbol. Say you have X indicators on Y charts, they can all send this "refresh" command and will all receive the messages from the queue, resulting in a cascade of updates. That's why I talked about a hammer for a fly.
With basic indicators it's not a problem, with heavy and complex indicators it's a hell.
The OnInit() is not called,so there is no re-initialization of indicator.