Close Price of Prior Day at selected time

Questions about MultiCharts and user contributed studies.
lnuara
Posts: 2
Joined: 31 Jan 2010

Close Price of Prior Day at selected time

Postby lnuara » 01 Mar 2010

I'd like to obtain the closing price from the PRIOR day. Specifically the 4pm closing price and NOT the end of the trading day - which might have after hours trading.

I've tried CloseD(1) but it gives me the last trade of the day - including after hours trading.

I'm hopeful that there is a simple trick that I'm missing. NOTE, in addtion to the 4pm price - for certain instruments the time might be 2:30 pm, so I'd love function (or method) that allows me to pinpoint the time of the close, that would be great.

PS - I'll need this for TWO Instruments (data1 and data2)

Thanks.

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

Postby TJ » 09 Mar 2010

try this:

Code: Select all

var:
session.close(0);

if time = SessionEndTime(1, 2) then session.close = close ;


you have to look up the definition of SessionEndTime in the manual.

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 09 Mar 2010

Well, depending on the type and size of bars in question, what you may want to do is something like time >= sessionendtime(1,2) and time[1] < sessionendtime(1,2) (or use "crosses above" and close[1] if you prefer, and if after hours times are included) because the bar might not end exactly at the end of the session, but TJ is on just the right track otherwise. You'll also want to check for situations where there's no bar at or after the end of the session (this can happen for instance with tick bars on thinly traded instruments) - to deal with this, it's best to update a variable continuously with the closing price as long as the bar time is <= the session end time - then at the start of the next session, just copy that most recent value to YesterdayClose etc. and start tracking a new session in the same way. The alternative is to trap the specific situation where the date changes but there wasn't yet a bar at or after the end of the session when e.g. date > date[1] or time < time[1] yet the closing price for today hasn't been set, and then reference close[1]. This isn't as clean programmatically but you can do this if you don't want the extra variable tracked for whatever reason.

With SessionEndTime, the first argument whether it's specifically a regular session (in this case, it is), and the second argument is the session number you wantt o reference. For instance, SessionEndTime(1,2) is the second regular session of the day. Thus, you may need to adjust that number accordingly, depending on how your instrument and time frames are set up.

User avatar
RobotMan
Posts: 375
Joined: 12 Jul 2006
Location: Los Altos, California, USA
Has thanked: 31 times
Been thanked: 13 times
Contact:

Postby RobotMan » 09 Mar 2010

I can confirm that Bruce's method is a better way to go. Here's why: Lets say a session is listed in QM as ending at 15:15, but in charting the last tick actually has a time stamp of 15:14:59. The code will never set the variable.
I actually have set a flag (see: http://forum.tssupport.com/viewtopic.php?t=5560), but Bruce's method is just as good.

The same thing is true of a session open.

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

Re: Close Price of Prior Day at selected time

Postby TJ » 09 Mar 2010

I'd like to obtain the closing price from the PRIOR day. ....

User avatar
RobotMan
Posts: 375
Joined: 12 Jul 2006
Location: Los Altos, California, USA
Has thanked: 31 times
Been thanked: 13 times
Contact:

Postby RobotMan » 09 Mar 2010

Hi TJ,

Yeah, I just assumed he wouldn't use CloseD anymore, because it is sort of anachronistic. If you look inside the function code, it never references the actual open or close; it looks for "date<>date[1]" and then sets an array element. I guess it is ok if you are looking at daily data or RTH data.

The better way to do it is use the logic that Bruce suggested and set a variable (let's say session.close1) then on the next day, sort this down to another variable (let's say session.close2) and then re-set session.close1. Now he can always call session.close1 or session.close2 intraday during the live session. This would also work with an array.

The lesson I learned about EL is: use a "custom 1 line" indicator and enter the function you are curious about in the input formula then see how it looks in the chart. If it looks fishy, then figure out why. In this case, CloseD always resets at midnight.

thutch
Posts: 52
Joined: 16 Sep 2011
Has thanked: 16 times
Been thanked: 10 times

Re: Close Price of Prior Day at selected time

Postby thutch » 28 Sep 2011

Hi all,

I'm fairly new to MC and am trying to do as the original poster, namely to compare the current bar's price to that of the session close X days ago. E.g. compare the closing price of the current bar (on a Monday say) to the closing price of the bar ending 17:15 ET last Thursday.

I have followed the examples above, but am still coming up short.

Would someone kindly post as simple an example as you possible can?

many thanks

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

Re: Close Price of Prior Day at selected time

Postby TJ » 28 Sep 2011

Hi all,

I'm fairly new to MC and am trying to do as the original poster, namely to compare the current bar's price to that of the session close X days ago. E.g. compare the closing price of the current bar (on a Monday say) to the closing price of the bar ending 17:15 ET last Thursday.

I have followed the examples above, but am still coming up short.

Would someone kindly post as simple an example as you possible can?

many thanks
What is the chart resolution and instrument?

thutch
Posts: 52
Joined: 16 Sep 2011
Has thanked: 16 times
Been thanked: 10 times

Re: Close Price of Prior Day at selected time

Postby thutch » 04 Oct 2011

Hi TJ

Its Crude oil (QCL# in IQfeed) using a 15 min bar resolution.

I'm still having troubles.

thanks for any help


Hi all,

I'm fairly new to MC and am trying to do as the original poster, namely to compare the current bar's price to that of the session close X days ago. E.g. compare the closing price of the current bar (on a Monday say) to the closing price of the bar ending 17:15 ET last Thursday.

I have followed the examples above, but am still coming up short.

Would someone kindly post as simple an example as you possible can?

many thanks
What is the chart resolution and instrument?

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

Re: Close Price of Prior Day at selected time

Postby TJ » 04 Oct 2011

Hi TJ

Its Crude oil (QCL# in IQfeed) using a 15 min bar resolution.

I'm still having troubles.

thanks for any help
Please post your effort for debug.

thutch
Posts: 52
Joined: 16 Sep 2011
Has thanked: 16 times
Been thanked: 10 times

Re: Close Price of Prior Day at selected time

Postby thutch » 05 Oct 2011

Hi TJ

Its Crude oil (QCL# in IQfeed) using a 15 min bar resolution.

I'm still having troubles.

thanks for any help
Please post your effort for debug.
I have found a closer problem example and have stated my issue there (more clearly hopefully). Please refer to viewtopic.php?f=1&t=7317&p=44078#p44078


Return to “MultiCharts”