Hi coders,
here is a little test script I made. My problem is that I would like to switch timeframes and do something when the timeframe has changed. But the problem is that ChartSetSymbolPeriod() is not executed immediately and so everything after that will be executed on the timeframe before. Does someone has an idea how to solve that problem?
This script always saves a screenshot of the chart before switching to the MN1.
"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 message queue and executed only after all previous commands have been processed."
"Changes the symbol and period of the specifiedchart. The function is asynchronous, i.e. it sends the command and doesnot wait for its execution completion. The command is added to chartmessage queue and executed only after all previous commands have beenprocessed."
You need a flag that can survive the reinit. Example using an EA:
#property strict bool FirstRun=true; int OnInit() { EventSetTimer(3); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { EventKillTimer(); } void OnTick() { } void OnTimer() { if(FirstRun) { FirstRun=false; Print("Changing timeframe"); ChartSetSymbolPeriod(0,NULL,PERIOD_MN1); } else { EventKillTimer(); Print("Taking screenshot"); ChartScreenShot(0,"Screenshot.png",1024,768); } }
alternatively, you can just wait until it is changed (in case you don't mind to wait here and loose the asynchronity)
void OnStart() { //--- ChartSetSymbolPeriod(0, _Symbol, PERIOD_MN1); while (ChartSymbol(0) != _Symbol && ChartPeriod(0) != PERIOD_MN1) { Sleep(1500); } ChartScreenShot(0, "test.gif", 1280, 720); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi coders,
here is a little test script I made. My problem is that I would like to switch timeframes and do something when the timeframe has changed. But the problem is that ChartSetSymbolPeriod() is not executed immediately and so everything after that will be executed on the timeframe before. Does someone has an idea how to solve that problem?
This script always saves a screenshot of the chart before switching to the MN1.