How can I set the EA to know the chart timeframe

 

Hi all,

I am writing a simple EA to email alert me when there is moving average crossover. eg


SendMail(Symbol() + " 20>50","Date and Time : "+TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)+" \n"+"Currency      : "+Symbol()    +"");


I would like to know how do I add code, so that I know the timeframe of the chart the EA

eg M1,M5,H1,H4


Some of you might comment I shall know the timeframe of the chart since I am the one that put the EA into.

I am going to put the EA into EURUSD H1 and EURUSD D1

so, I want to know the moving average crossover happen at chart H1 or chart D1


Thanks a lot first

From

erekit

http://100k2.blogspot.com

 
erekit:

Hi all,

I am writing a simple EA to email alert me when there is moving average crossover. eg



I would like to know how do I add code, so that I know the timeframe of the chart the EA

eg M1,M5,H1,H4


Some of you might comment I shall know the timeframe of the chart since I am the one that put the EA into.

I am going to put the EA into EURUSD H1 and EURUSD D1

so, I want to know the moving average crossover happen at chart H1 or chart D1


Thanks a lot first

From

erekit

http://100k2.blogspot.com



You can use
Period( )
 

Try this.

string tf;

switch(Period())
{
  case 1: tf="M!"; break;
  case 5: tf="M5"; break;
  case 15: tf="M15"; break;
  case 30: tf="M30"; break;
  case 60: tf="H1"; break;
  case 240: tf="H4"; break;
  case 1440: tf="D1"; break;
}

SendMail(Symbol() + " " + tf + " 20>50","Date and Time : "+TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)+" \n"+"Currency      : "+Symbol()    +"");
 
string  Period.text;                        // Export to OpenNew.
int init(){
    int     tf[]        = { PERIOD_M1,  PERIOD_M5,  PERIOD_M15, PERIOD_M30,
                            PERIOD_H1,  PERIOD_H4,  PERIOD_D1,  PERIOD_W1,
                            PERIOD_MN1  };                              
    string  TFtext[]    = { "M1",       "M5",       "M15",      "M30",
                            "H1",       "H4",       "D1",       "W1",
                            "MN1"       };  
    for(int index=0; tf[index] < Period(); index++){}
    Period.text         = TFtext[index];
 
Thanks Matutin.
 

I just need know the Period() then I can code it already.

Anyway, thanks wackena and WHRoeder

Thanks all again

Reason: