I needed to have a third trading session, one for each global banking session, so I updated the code to speak in terms of Asian, European and US sessions. Not sure if anyone else needs this, but I thought I'd post it should the need arise.magft wrote:BTW the time checking script by George had to be modified to work correctly. I think it now works without issues.
Externs:
Code: Select all
extern string tt="----Trading hours----";
extern string Trade_Hours= "Set Session Trading Hours";
extern string Trade_Hoursi= "Use 24 hour, Server time";
extern string Trade_Hours_E= "Europe Session 7:00-12:00";
extern string Start_TimeE = "7:00";
extern string End_TimeE = "12:00";
extern string Trade_Hours_U= "US Session 13:00-16:00";
extern string Start_TimeU = "13:00";
extern string End_TimeU = "17:00";
extern string Trade_Hours_A= "Asia Session 23:00-4:00";
extern string Start_TimeA = "0:00";
extern string End_TimeA = "4:00";
Code: Select all
bool CheckTradingTimes()
{
datetime AsiaBeg, AsiaEnd, EuropeBeg, EuropeEnd, USBeg, USEnd;
//datetime Now = TimeLocal(); //use local time
datetime Now = TimeCurrent(); //use broker time
//we need to cast our conversions into the current date
AsiaBeg = StrToTime(TimeToStr(Now,TIME_DATE)+" "+ Start_TimeA);
AsiaEnd = StrToTime(TimeToStr(Now,TIME_DATE)+" "+ End_TimeA);
EuropeBeg = StrToTime(TimeToStr(Now,TIME_DATE)+" "+ Start_TimeE);
EuropeEnd = StrToTime(TimeToStr(Now,TIME_DATE)+" "+ End_TimeE);
USBeg = StrToTime(TimeToStr(Now,TIME_DATE)+" "+ Start_TimeU);
USEnd = StrToTime(TimeToStr(Now,TIME_DATE)+" "+ End_TimeU);
bool Asia = false;
//Check normal case for morning , 7:00-13:00
if (AsiaBeg < AsiaEnd && (Now >= AsiaBeg && Now < AsiaEnd))
Asia = true;
//Check to see if AsiaBeg to AsiaEnd spans 00:00, e.g. 22:00 - 04:00
if (AsiaEnd < AsiaBeg && (Now >= AsiaBeg || Now < AsiaEnd))
Asia = true;
bool Europe = false;
//Check normal case for Europe , 17:00 - 22:00
if (EuropeBeg < EuropeEnd && (Now >= EuropeBeg && Now < EuropeEnd))
Europe = true;
//Check to see if EuropeBeg-EuropeEnd spans 00:00, 22:00 - 04:00
if (EuropeEnd < EuropeBeg && (Now >= EuropeBeg || Now < EuropeEnd))
Europe = true;
bool US = false;
//Check normal case for US , 17:00 - 22:00
if (USBeg < USEnd && (Now >= USBeg && Now < USEnd))
US = true;
//Check to see if USBeg-USEnd spans 00:00, 22:00 - 04:00
if (USEnd < USBeg && (Now >= USBeg || Now < USEnd))
US = true;
return(Asia || Europe || US);
}//bool CheckTradingTimes()
Code: Select all
ScreenMessage = StringConcatenate(ScreenMessage,Gap, "Trading hours", NL);
if (Start_TimeA == "00:00" && End_TimeA == "24:00") ScreenMessage = StringConcatenate(ScreenMessage,Gap, " 24H trading", NL);
else
{
ScreenMessage = StringConcatenate(ScreenMessage,Gap, " Asian Session: ", Start_TimeA," - ", End_TimeA, NL);
ScreenMessage = StringConcatenate(ScreenMessage,Gap, " European Session: ", Start_TimeE," - ", End_TimeE, NL);
ScreenMessage = StringConcatenate(ScreenMessage,Gap, " US Session: ", Start_TimeU," - ", End_TimeU, NL);
}//else
EDIT: OK, it does change "b-r-o-k-e-r" to "criminal" in code.
George
