Changing the timeframe of the current chart causes problems

Back to topics list To post a new topic, please log in or register
avatar
370
mar 2015.04.14 09:14
 

Hi forum,

I made a script which should change the current timeframe to M1, then make a screenshot and change the timeframe back to the original one. But I always get a message from metatrader if the script should be terminated. I read in the documents that ChartSetSymbolPeriod() is asynchronous and doesn't wait for its execution completion. I believe this is the problem here. Can anyone help me?

void OnStart()
  {
   int chartPeriod = ChartPeriod(0);
   ChartSetSymbolPeriod(0, NULL, PERIOD_M1);
   ChartScreenShot(0, Symbol()+"_"+(string)Period()+".gif", 640, 480);
   ChartSetSymbolPeriod(0, NULL, chartPeriod);
  }

 

avatar
1109
Ovo 2015.04.14 10:07 #
 
Open a new chart (ChartOpen) with the desired timeframe, set a template, capture the chart (and close the chart, if you do not like it open).
avatar
370
mar 2015.04.14 17:30 #
 
Thanks, Ovo. That almost works. Now I have the problem that the M1 data is not fully loaded before the screenshot and therefore the M1 screenshot does not show the current chart. I tried RefreshRates() before the screenshot but that didn't help. Do you have an idea?
avatar
1109
Ovo 2015.04.14 20:02 #
 
mar:
Thanks, Ovo. That almost works. Now I have the problem that the M1 data is not fully loaded before the screenshot and therefore the M1 screenshot does not show the current chart. I tried RefreshRates() before the screenshot but that didn't help. Do you have an idea?

You can use Sleep command in the script, to allow a few seconds for data fetching. Or you may have another indicator which just calls iBars(_Symbol, PERIOD_M1) in OnCalculate; it will keep the M1 up to date.

avatar
370
mar 2015.04.14 21:13 #
 
Great idea with the other indicator. Just modified a standard indicator which runs all the time. Thank you!
Back to topics list  

To add comments, please log in or register