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.
Close Price of Prior Day at selected time
- TJ
- Posts: 7774
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
try this:
you have to look up the definition of SessionEndTime in the manual.
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.
- Bruce DeVault
- Posts: 438
- Joined: Jan 19 2010
- Location: Washington DC
- Been thanked: 2 times
- Contact:
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.
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.
- RobotMan
- Posts: 375
- Joined: Jul 12 2006
- Location: Los Altos, California, USA
- Has thanked: 31 times
- Been thanked: 13 times
- Contact:
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.
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.
- TJ
- Posts: 7774
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
I'd like to obtain the closing price from the PRIOR day. ....
- RobotMan
- Posts: 375
- Joined: Jul 12 2006
- Location: Los Altos, California, USA
- Has thanked: 31 times
- Been thanked: 13 times
- Contact:
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.
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.
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
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
- TJ
- Posts: 7774
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
What is the chart resolution and instrument?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
Hi TJ
Its Crude oil (QCL# in IQfeed) using a 15 min bar resolution.
I'm still having troubles.
thanks for any help
Its Crude oil (QCL# in IQfeed) using a 15 min bar resolution.
I'm still having troubles.
thanks for any help
What is the chart resolution and instrument?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
- TJ
- Posts: 7774
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
Please post your effort for debug.Hi TJ
Its Crude oil (QCL# in IQfeed) using a 15 min bar resolution.
I'm still having troubles.
thanks for any help
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#p44078Please post your effort for debug.Hi TJ
Its Crude oil (QCL# in IQfeed) using a 15 min bar resolution.
I'm still having troubles.
thanks for any help