+1 888 340 6572 



Post new topic Reply to topic 
How to get previous days high, low   [ ]
Author Message
#1 posted 18 Mar 2012 

Status: Offline
Posts: 1055
Thanks Received: 195 times
Thanks Given: 604 times
Joined: 23 Nov 2010
Hello

I got a little problem

I want to get the high of the last trading session that start @ 5:00 pm until 04:59:59 the following day

I did try
- HighD(), but it the high occurred in the same day, it won't return the good value for the session
- DailyHigh[ ] but it does't return an appropriate value and same value for any days back.

Will I have to write code to read these values within the time that I decide.

Martin


#2 posted 18 Mar 2012 

Status: Offline
Posts: 1912
Thanks Received: 379 times
Thanks Given: 127 times
Joined: 21 Jul 2007
Hi arjfca

I am assuming you have the binary search function to get the offsets using date and time. So if worst came to worst, you could
1/ use the binary function to get the offset of the first bar of the range of time (session, day, anything). Call this OldOffset.
2/ use the binary search function to get the offset of the last bar of the range of time (session, day, anything) . call this NewOffset


OffsetDiff = OldOffset - NewOffset + 1;

Now uses these functions.

HighestValueOfTheRange = Highest(high, OffsetDiff)[NewOffset];
LowestValueOfTheRange = Lowest(low, OffsetDiff)[NewOffset];

It has been a while since I used this and tested it. I am adding the 1 from memory. I am assuming my memory serves me correctly. You can actually put code inside the functions that highest/lowest uses to debug them if you want.

If you inspect the code inside the highest or lowest function what it ends up doing is a sequential search backwards using the offset info you provide to know when to start the search and end the search.

John



For this message the author bowlesj3 has received thanks:
arjfca


#3 posted 19 Mar 2012 

Status: Offline
Posts: 128
Thanks Received: 68 times
Thanks Given: 36 times
Joined: 19 Mar 2011
A possible alternative:

Add the same symbol to your chart as a second instrument, Data2. It should be added as a minute-based chart, using a session that matches the time period of the daily session (5:00 PM to 4:59 PM in your case).

Then, change the number of minutes for the chart to the number of minutes in that session. For example, if the session runs continuously from 5:00 PM to 4:59 PM -- without any interruptions -- then data2 should be set to a chart with 1440-minute bars (60 minutes times 24 hours). You should end up with data2 being a 1440-minute bar that lasts from 5:00 PM to 4:59 PM.

In your code, you can then reference the data2 series to get the "daily" highs, lows, etc. for that session. E.g.:

Code:
HighestVal = High of Data2;



For this message the author Xyzzy has received thanks:
arjfca


#4 posted 19 Mar 2012 

Status: Offline
Posts: 1055
Thanks Received: 195 times
Thanks Given: 604 times
Joined: 23 Nov 2010
Hello Xyzzy

Your solution is possible, It's just that I didn't wanted to had a second instrument in the study.

I did found my solution late last night by coding it. I look for the High and low for the last # period when a bar + the time of start of the day.

See my post here
viewtopic.php?f=1&t=10154#p48728

Martin



Post new topic Reply to topic