How to adjust timeframe for chart using code

 

When an Expert Advisor is attached to a chart, the timeframe is manually applied by clicking M1, M5, H1, etc. This timeframe controls how often the EA receives a market tick. Each market tick runs all the code in the start() method.

How can I programmatically change the time frame from D1, to H4, to H1, etc. -- thereby having the EA "sleep" for long periods of time until, for example, Tuesday at 2:15PM Eastern Standard Time (this time is for illustrative purposes only. IT HAS NO MEANING IN THE MARKETPLACE!).

Essentially, what I need is an EA that only trades at one specific time one a single day of the week.

Am I thinking about this wrong? Maybe MetaTrader code can simply start a chart using D1, delete that chart, start another chart using H4, delete that, etc.?

 

"This timeframe controls how often the EA receives a market tick."

...No, ticks come when the dealer sends you a tick. Has nothing to do with chart timeframe.

"Am I thinking about this wrong?"

...Yes.

Simplistic example, maybe for 15m chart:

if(TimeDayOfWeek(Time[0]) == 2 && TimeHour(Time[0]) == 14 && TimeMinute(Time[0]) == 15) {

...decide to take a trade, or not

}

 

Hello, actually I was looking the same.
And found this function in MQL4


ChartSetSymbolPeriod(0,Symbol(),PERIOD_M5);


above code will change current chart to M5.


Hope this help for those who search the same things

Reason: