Download MetaTrader 5
To add comments, please log in or register
Add our Twitter channel to friends and follow the news!
mar
1143
mar 2015.04.14 07: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);
  }
Ovo Cz
2958
Ovo Cz 2015.04.14 08: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).
mar
1143
mar 2015.04.14 15: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?
Ovo Cz
2958
Ovo Cz 2015.04.14 18: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.

mar
1143
mar 2015.04.14 19:13  
Great idea with the other indicator. Just modified a standard indicator which runs all the time. Thank you!
/
To add comments, please log in or register