check if there is trading tomorrow automatically

 

Hello,

Im trying to automate a function that close position, if tomorrow is not a trading day in as specific symbol.

I managed to check if tomorrow is saturday/sunday but I don't know how to check if tomorrow is a holiday for example.

How can I check if tomorrow is a trading day?


Thank you,

Yu.

 
yuv98: How can I check if tomorrow is a trading day?

Market holidays depends on your specific broker (and in the case of multiple servers, the specific server jurisdiction.) You will have to code it specifically for your broker. You wouldn't expect a Japanese broker to recognize US Independence day, would you?

 
yuv98:

Hello,

Im trying to automate a function that close position, if tomorrow is not a trading day in as specific symbol.

I managed to check if tomorrow is saturday/sunday but I don't know how to check if tomorrow is a holiday for example.

How can I check if tomorrow is a trading day?


Thank you,

Yu.


something like this?

input bool AvoidHolidays=true;

MqlDateTime CurrentTime;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void OnTick()  {

   TimeCurrent(CurrentTime);

   if ( AvoidHolidays ) 
   {
      if ( CurrentTime.mon==1 && CurrentTime.day_of_week==1 && CurrentTime.day>=15 && CurrentTime.day<=21 ) return;      //1月的第三个星期一   马丁·路德·金纪念日
      if ( CurrentTime.mon==2 && CurrentTime.day_of_week==1 && CurrentTime.day>=15 && CurrentTime.day<=21 ) return;      //2月的第三个星期一   总统日
      if ( CurrentTime.mon==5 && CurrentTime.day_of_week==1 && CurrentTime.day>=25 && CurrentTime.day<=31 ) return;      //5月的最后一个星期一  阵亡将士纪念日
      if ( CurrentTime.mon==7 && CurrentTime.day==4 ) return;                                                            //7月4日 美国独立日
      if ( CurrentTime.mon==9 && CurrentTime.day_of_week==1 && CurrentTime.day>=1 && CurrentTime.day<=7 ) return;        //9月的第一个星期一   劳工日
      if ( CurrentTime.mon==11 && CurrentTime.day_of_week==4 && CurrentTime.day>=22 && CurrentTime.day<=28 ) return;     //11月的第四个星期四  感恩节
      if ( CurrentTime.mon==11 && CurrentTime.day_of_week==5 && CurrentTime.day>=23 && CurrentTime.day<=29 ) return;     //11月的第四个星期五  感恩节
      if ( ( CurrentTime.mon==12 && CurrentTime.day>=24 ) || ( CurrentTime.mon==1 && CurrentTime.day<=3 ) ) return;      //圣诞新年假期
   }
}
 

Thats great thanks!

But what I mean is-is there API that automatically get it from the broker?

I guess it doesn't exist..

Thanks!

Reason: