Hi guys, is there a method to get the current timeframe of the chart?
I need to use this for allowing the EA to only run on 1H, or 4H time frames and alert if any other time frame is activated to turn off the EA.
Thanks,
Found a solution, but it does depends on the number of Bars being different between timeframes
here is the method, in case someone needs it
int checkTimeFrame() { if(Bars!=iBars(Symbol(),PERIOD_H4)) { Alert("Wrong chart timeframe"); return(0); } }
Hi guys, is there a method to get the current timeframe of the chart?
I need to use this for allowing the EA to only run on 1H, or 4H time frames and alert if any other time frame is activated to turn off the EA.
Thanks,
Asked earlier today . . . https://www.mql5.com/en/forum/139280
Why does it matter what timeframe the chart is ?
I do it this way ...
int init(){ ... if( Period()!= PERIOD_M5 ){ Comment("ERROR: You must use M5 timeframe"); MessageBox( "ERROR: Needs M5 timeframe.\nRun Aborted", ADVISORNAME, MB_ICONSTOP ); abort=true; return( -1 ); } return(0); } //--------------------------------------------------------------------------------------+ int start(){ if( abort ) return( 0 ); ... }
Why does it matter what timeframe the chart is ?
I only want my EA to run on H4, and skip all other time frames.
I only want my EA to run on H4, and skip all other time frames.
I understand that . . . but why does it have to run on H4 to trade H4 ? not saying what you are doing is wrong, but you do have other options that you should be aware of
- For my new EA experiment, there is an order every new bar, if signals show a buy or a sell.
- If trading on H1, there are 4x more trades, which increases EA's market exposure.
- Using H4 timeframe gives the EA enough break between trades.
- Also when I start MT4, and I open a new chart, it defaults to H1, and I miss this sometimes and go ahead and apply the EA to H1, and let it run...
- To prevent human error, and to limit the number of trades, I programatically check for H4, only then allow the EA to trade.
Well he is pointing out that anything you can do on an H4 chart you can also do on an M1 chart (for example) if you modify the code to avoid any references to the chart specific variables. Instead of using Time[] you would use iTime() for example. You will still be using your chosen timeframe for all your trade decisions by accessing the data using functions rather than the built in arrays.
Close[] -> iClose()
Open[] -> iOpen()
Well he is pointing out that anything you can do on an H4 chart you can also do on an M1 chart (for example)
Well he is pointing out that anything you can do on an H4 chart you can also do on an M1 chart (for example) if you modify the code to avoid any references to the chart specific variables. Instead of using Time[] you would use iTime() for example. You will still be using your chosen timeframe for all your trade decisions by accessing the data using functions rather than the built in arrays.
Close[] -> iClose()
Open[] -> iOpen()
- 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 guys, is there a method to get the current timeframe of the chart?
I need to use this for allowing the EA to only run on 1H, or 4H time frames and alert if any other time frame is activated to turn off the EA.
Thanks,