Download MetaTrader 5

How to set time frame of bar chart in program not in the chart

To add comments, please log in or register
Sign up for MQL5.community to leave your comments!
king1898
243
king1898 2013.11.15 14:49 

int OnInit()
  {
//--- Get handle for KD indicator
   KDHandle1=iStochastic(NULL,0,K_Period,D_Period,3,MODE_SMA,STO_LOWHIGH);

...

We can set indicator _Period=0 as current time frame as bar chart, but how we can change the time frame of bar chart in our code? Thanks!  

Documentation on MQL5: Date and Time / TimeCurrent
Documentation on MQL5: Date and Time / TimeCurrent
  • www.mql5.com
Date and Time / TimeCurrent - Documentation on MQL5
Alain Verleyen
Moderator
30742
Alain Verleyen 2013.11.15 15:36  
king1898:

int OnInit()
  {
//--- Get handle for KD indicator
   KDHandle1=iStochastic(NULL,0,K_Period,D_Period,3,MODE_SMA,STO_LOWHIGH);

...

We can set indicator _Period=0 as current time frame as bar chart, but how we can change the time frame of bar chart in our code? Thanks!  

Please use SRC button when you post code. Thank you.

By the way, I don't understand your question.

king1898
243
king1898 2013.11.16 03:45  

When I set indicator parameter named "_Period"=0 it means set current time frame with bar chart, if i change the time frame of the bar chart such as changing 5 minutes to 1 hour by right click chart and change as below picutre, the EA will change the time frame from 5 minutes to 1 hour.

change time frame

My question is how to write code to change the time frame of bar chart  in my EA. Thanks!

Rodrigo Malacarne
Moderator
9903
Rodrigo Malacarne 2013.11.16 13:55  

Please take a look at the Docs: https://www.mql5.com/en/docs/constants/chartconstants/enum_timeframes 

You could use something like

KDHandle1=iStochastic(NULL,PERIOD_M5,K_Period,D_Period,3,MODE_SMA,STO_LOWHIGH);
Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
  • www.mql5.com
Standard Constants, Enumerations and Structures / Chart Constants / Chart Timeframes - Documentation on MQL5
To add comments, please log in or register