last bar day

Questions about MultiCharts and user contributed studies.
turbofib
Posts: 213
Joined: 11 May 2013
Has thanked: 67 times
Been thanked: 1 time

last bar day

Postby turbofib » 19 Feb 2020

hi,

i need to find last bar in the trading day :

if i use date<>date[1] is not correct because i receive information after 1 bar...i want to know it the last day bar


Example:

i setting dax futures open 8.00 close 22.00 all days

last bar day is 2200!

I need to know the information at the 2200 clock

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: last bar day

Postby TJ » 19 Feb 2020

Try this:

Code: Select all

if TIME = 2200 then begin

turbofib
Posts: 213
Joined: 11 May 2013
Has thanked: 67 times
Been thanked: 1 time

Re: last bar day

Postby turbofib » 19 Feb 2020

thank TJ...but i want to calculare in automatic...
regardless of what instrument I use

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: last bar day

Postby TJ » 19 Feb 2020

Try this:

Code: Select all

if TIME = SessionEndTime then . . .

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: last bar day

Postby TJ » 19 Feb 2020

Go to the Wiki,
See : 8 PowerLanguage Keyword Reference
Look under : Sessions‎ (18 P)

turbofib
Posts: 213
Joined: 11 May 2013
Has thanked: 67 times
Been thanked: 1 time

Re: last bar day

Postby turbofib » 20 Feb 2020

if i code this with instrument "Es futures"

if time=SessionEndTime(1,1) then print(date,time," End Day");


i get this output :

1191210.00 1600.00 End Day

but time 16.00 is end session and not end day

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: last bar day

Postby rrams » 20 Feb 2020

turbofib, what you are asking for is somewhat complicated. You can accomplish it with code something like this:

Code: Select all

variables: dayfraction(0), nextsession(0); switch(BarType_ex) begin case 2: dayfraction=BarInterval/1440; // minutes case 3: dayfraction=BarInterval/24; // hours case 9: dayfraction=BarInterval/86400; // seconds default: RaiseRuntimeError("Invalid interval. Requires intraday data."); end; nextsession=IFF(CurrentSession(0)<SessionCount(0), CurrentSession(0)+1, 1); if DayFromDateTime(DateTime+dayfraction)<>DayFromDateTime(DateTime) or (SessionEndDay(0, CurrentSession(0))=DayOfWeek(Date) and SessionStartDay(0, nextsession)<>DayOfWeek(Date) and DateTime2ELTime(DateTime+dayfraction)>=SessionEndTime(0, CurrentSession(0))) then print("Last bar of day");
(I have not tested the code, so I don't know if it works.)

Unless you really know what you are doing, you should stick with just hard coding the last bar times for each symbol.
Because, for instance, the session functions can return wrong information if you use local time for your strategy and the exchange uses a different Daylight Saving Time.

I try to help as a thank you for the times that I needed help and not to prove anything.


Return to “MultiCharts”