For currencies I have my sessions set up
Sun 22:00 - Mon 07:00
Mon 07:00 - Tues 07:00
etc.
These are London times. I want to reset an indicator on the first bar of a session so used
if time > sessionstarttime(0,1) and time[1] <= sessionstarttime(0,1) then........
Whatever parameters I use for sessionstarttime (e.g. sessionstarttime(1,2)) it returns 22:00.
I worked around the issue by using sessionendtime which returns 07:00.
Problem with sessionstarttime
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Problem with sessionstarttime
Hello Nick,
You need to select the same time zone both in Quote manager->Edit symbol->Sessions tab and Format->Instrument->Settings tab.
In this case you will have the same timestamps in the symbol sessions tab, on the chart and in PLE.
You need to select the same time zone both in Quote manager->Edit symbol->Sessions tab and Format->Instrument->Settings tab.
In this case you will have the same timestamps in the symbol sessions tab, on the chart and in PLE.
Re: Problem with sessionstarttime
The problem is not to do with exchange or local time (It happens however this is set). The problem is that the function sessionstarttime (and sessionendtime) returns the start of the very first session defined in QM. That is the only value ever returned.
So using my example even if you are processing a bar on Monday it returns the session start time from Sunday. So whichever day of the week the bar you are processing occurs on it returns 22:00.
So using my example even if you are processing a bar on Monday it returns the session start time from Sunday. So whichever day of the week the bar you are processing occurs on it returns 22:00.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Problem with sessionstarttime
That is correct. I had the same problem (with MC7.4) when the first session time of Monday was different from the session times from other days of the weeks. Calling SessionStartTime would return the first session time of Monday, even if it was called on another day of the week.The problem is not to do with exchange or local time (It happens however this is set). The problem is that the function sessionstarttime (and sessionendtime) returns the start of the very first session defined in QM. That is the only value ever returned.
So using my example even if you are processing a bar on Monday it returns the session start time from Sunday. So whichever day of the week the bar you are processing occurs on it returns 22:00.
I "solved" the problem by giving each day the same session start time in the QuoteManager, so that SessionStartTime() would return correct values.
I agree with you here that there seems to be an problem or bug with SessionStartTime.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Problem with sessionstarttime
This is neither a problem nor a bug. This is expected behaviour.
SessionNum - a numerical expression specifying the Session Number.
This value ranges from 1 to the maximum number of sessions present in Quote Manager->Edit symbol->Sessions tab.
Each line is counted starting from the first session.
SessionNum - a numerical expression specifying the Session Number.
This value ranges from 1 to the maximum number of sessions present in Quote Manager->Edit symbol->Sessions tab.
Each line is counted starting from the first session.
- Attachments
-
- session start-end time.png
- (31.93 KiB) Downloaded 1166 times
Re: Problem with sessionstarttime
Thanks for the detailed reply Henry.
Odd, I have re-applied the study to a new chart with a newly constructed session template and it seems OK. Guess that means I must have previously mucked something up though was aware how the sessionnumber parameter worked.
A side question is there a function that returns a number representing the session you are in? I want a way to know the start/end time for the current session whichever one it might be.
Odd, I have re-applied the study to a new chart with a newly constructed session template and it seems OK. Guess that means I must have previously mucked something up though was aware how the sessionnumber parameter worked.
A side question is there a function that returns a number representing the session you are in? I want a way to know the start/end time for the current session whichever one it might be.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Problem with sessionstarttime
Thanks Henry, I wasn't aware of that and read the help wrong.
Or replacing the 0 with 1 for a 'regular' session per day.
Depending on how many sessions you have defined per day, perhaps something like this (with one session per day):A side question is there a function that returns a number representing the session you are in? I want a way to know the start/end time for the current session whichever one it might be.
Code: Select all
SessionStartTime(0, DayOfWeek(ComputerDateTime) + 1);
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Problem with sessionstarttime
Unfortunately there is no prebuilt function that returns a number representing the current session you are in.A side question is there a function that returns a number representing the session you are in? I want a way to know the start/end time for the current session whichever one it might be.
I believe Josh has suggested a good workaround.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Problem with sessionstarttime
I've spend 4+ hours trying to make a function that returns the session begin time using the Session reserved words. Sounds simple enough, but my PowerLanguage skills are not suited to this challenge.
For example, when there are only 5 sessions (Mon, Tue, Wed, Thu, Fri) that all close on the same day, it's easy to get the begin and end time of each sessions when using the DayOfWeek(Date) substitute for the SessionNumber in the QuoteManager. The problems start however when an instrument starts trading on Sunday (like FX pairs).
Then I run into a runtime error since a correction for the DayOfWeek(Date) substitute is needed since DayOfWeek(Date) returns a zero for Sunday, which off course doesn't work since there's no SessionNumber of zero. So I use a work around for this:
However, if I then try to get the session begin time and session end time from an instrument with multiple sessions per day (say ES), another string of run time errors pops up. Okay, fair enough so we'll need to make an adjustment for those instruments:
At that point I was a little bit confident I got it solved -- until I changed the chart time to Exchange and guess what: the code generated on every symbol again run time errors. So, now I need to build in a check to see if the chart time settings are Local or Exchange. As far as I know, such a thing cannot be retrieved with PowerLanguage. So I'm quite stuck.
Hence my question:
For example, when there are only 5 sessions (Mon, Tue, Wed, Thu, Fri) that all close on the same day, it's easy to get the begin and end time of each sessions when using the DayOfWeek(Date) substitute for the SessionNumber in the QuoteManager. The problems start however when an instrument starts trading on Sunday (like FX pairs).
Then I run into a runtime error since a correction for the DayOfWeek(Date) substitute is needed since DayOfWeek(Date) returns a zero for Sunday, which off course doesn't work since there's no SessionNumber of zero. So I use a work around for this:
Code: Select all
sessionNumber = IFF(SessionStartDay(SessionType, 1) = 0, MinList(DayOfWeek(Date), 1), DayOfWeek(Date));
Code: Select all
Print("SessionCount: ", NumToStr(SessCount, 0), ", SessionNumber: ", NumToStr(sessionNumber, 0), " EndTime: ",
SessionEndTime(SessionType, SessionNumber * 2), " StartTime: ", SessionStartTime(SessionType, SessionNumber));
Hence my question:
- How can I retrieve the session begin time and session end time for symbols through PowerLanguage?
Re: Problem with sessionstarttime
Maybe SessionCountDay could help:
Code: Select all
variables:
zaehler( 0 ) ;
for zaehler = 1 to SessionCountDay(0, DayOfWeek(Date))
begin
print(" SessionNumber #:", NumToStr(zaehler, 0), Spaces(5 - StrLen(NumToStr(zaehler, 0))),
SessionStartTime(0, zaehler), " - ", SessionEndTime(0, zaehler));
end ;
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Problem with sessionstarttime
Thanks SP . I wasn't aware of the SessionCountDay function.Maybe SessionCountDay could help:
For FESX, it works correctly:
Code: Select all
FESX SessionNumber #:1 800.00 - 2200.00
Code: Select all
ES SessionNumber #:1 1700.00 - 830.00
For EURUSD (Spot, MB Trading) it returns nothing since the SessionCountDay function returns zero for this instrument.
I'll will experiment further with adding checks for this behaviour, but I'm afraid it's the same result as I had earlier.
Re: Problem with sessionstarttime
I decided to revisit this (as I am trading a couple of different instruments to my old faves).
Did anyone crack it so that it works for all instruments be it Spot FX, Globex, or any other exchange round the world??
I thought I had but still unpredictable sometimes when I load up a brand new instrument with different session parameters.
All I want to do is reset an indicator on the transition of the last bar of session x to the first bar of session y!!!!
Did anyone crack it so that it works for all instruments be it Spot FX, Globex, or any other exchange round the world??
I thought I had but still unpredictable sometimes when I load up a brand new instrument with different session parameters.
All I want to do is reset an indicator on the transition of the last bar of session x to the first bar of session y!!!!
Re: Problem with sessionstarttime
Can anyone explain what is the difference between AutoSession an RegularSession is supposed to be. They currently return identical values when used in any session function. The following code illustrates that.
Edit: Regular Session should only return the sessions with a tick in the checkbox on the session template? It doesn't.
Code: Select all
var: n(0);
once
begin
for n = 1 to sessioncount (0) begin
print (n," ",SessionStarttime(0,n)," ",sessionendtime(0,n));
end;
print ("_____________");
for n = 1 to sessioncount (1) begin
print (n," ",SessionStarttime(1,n)," ",sessionendtime(1,n));
end;
end;
Re: Problem with sessionstarttime
Im thinking something like this will work in most cases, its still not really satisfactory
Code: Select all
n(0),WeekDaySession(0);
once repeat until WeekDaySession >= 1 begin // get first weekday session
n = + 1;
WeekDaySession = SessionEndDay(1,n);
end;
if time > sessionendtime(0,WeekDaySession) and time[1] <= sessionendtime(0,WeekDaySession) .....bar is first bar of the first weekday session