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?
int chartPeriod = ChartPeriod(0);
ChartSetSymbolPeriod(0, NULL, PERIOD_M1);
ChartScreenShot(0, Symbol()+"_"+(string)Period()+".gif", 640, 480);
ChartSetSymbolPeriod(0, NULL, chartPeriod);
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.
To add comments, please log in or register