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

 

[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?

 
PERIOD_CURRENT
 
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?

 

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

 
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

 
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? 

 
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