Download MetaTrader 5

[LOOK] How can I set my indicator to change the time-frame when I switch to other time-frame?

To add comments, please log in or register
MQL5 Cloud Network speeds up calculations. Try it!
Musngi
301
Musngi 2016.11.23 18:04 

[LOOK] How can I set my indicator to change the time-frame when I switch to other time-frame? I want to know the best way to do it. 

Here's my code:

iMA("EURUSD", Period(), 14, 0, MODE_SMA, PRICE_CLOSE, 0); // Here I used Period() function to get the current TF

 What happen to previous data in other time-frame? Is it separate data recorded for each time-frame?

Marco vd Heijden
Moderator
4705
Marco vd Heijden 2016.11.23 18:48  
PERIOD_CURRENT
Musngi
301
Musngi 2016.11.23 19:26  
Marco vd Heijden:
PERIOD_CURRENT

I tried to test the PERIOD_CURRENT in start() but it don't work.

if(PERIOD_CURRENT == PERIOD_M30) // If I use Period() function it works
{  
    Alert("Period: 30 minutes");
}

How do you use PERIOD_CURRENT to auto-change the indicator time-frame when switching in other Time-frame?

What happen to previous data in other time-frame? Is it separate data recorded for each time-frame?

Marco vd Heijden
Moderator
4705
Marco vd Heijden 2016.11.23 20:58  

PERIOD_CURRENT will always be the actual period.

You are trying to use it in reverse.

Chart Timeframes

All predefined timeframes of charts have unique identifiers. The PERIOD_CURRENT identifier means the current period of a chart, at which a mql5-program is running.

ENUM_TIMEFRAMES

ID

Description

PERIOD_CURRENT

Current timeframe

PERIOD_M1

1 minute

PERIOD_M2

2 minutes

PERIOD_M3

3 minutes

PERIOD_M4

4 minutes

PERIOD_M5

5 minutes

PERIOD_M6

6 minutes

PERIOD_M10

10 minutes

PERIOD_M12

12 minutes

PERIOD_M15

15 minutes

PERIOD_M20

20 minutes

PERIOD_M30

30 minutes

PERIOD_H1

1 hour

PERIOD_H2

2 hours

PERIOD_H3

3 hours

PERIOD_H4

4 hours

PERIOD_H6

6 hours

PERIOD_H8

8 hours

PERIOD_H12

12 hours

PERIOD_D1

1 day

PERIOD_W1

1 week

PERIOD_MN1

1 month

Keith Watford
Moderator
9624
Keith Watford 2016.11.23 23:35  
Musngi:

I tried to test the PERIOD_CURRENT in start() but it don't work.

if(PERIOD_CURRENT == PERIOD_M30) // If I use Period() function it works
{  
    Alert("Period: 30 minutes");
}

How do you use PERIOD_CURRENT to auto-change the indicator time-frame when switching in other Time-frame?

What happen to previous data in other time-frame? Is it separate data recorded for each time-frame?

PERIOD_CURRENT and PERIOD_M30 are enumerations

so

if(PERIOD_CURRENT == PERIOD_M30)

is the same as

if(0 ==30)

of course, it will never be true

Musngi
301
Musngi 2016.11.24 06:24  
Keith Watford:

PERIOD_CURRENT and PERIOD_M30 are enumerations

so

if(PERIOD_CURRENT == PERIOD_M30)

is the same as

if(0 ==30)

of course, it will never be true

I forgot to tell I used MT4 not MT5.

Can you please give me sample code of how can my indicator auto switch if I click other time-frame? 

Keith Watford
Moderator
9624
Keith Watford 2016.11.24 08:05  
Can you please give me sample code of how can my indicator auto switch if I click other time-frame?


Your code already does that

iMA("EURUSD", Period(), 14, 0, MODE_SMA, PRICE_CLOSE, 0);       // Here I used Period() function to get the current TF


I forgot to tell I used MT4 not MT5.


Would you like this moved to the MQL4 section, it makes more sense to post there

To add comments, please log in or register