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
How to get previous days high, low
Re: How to get previous days high, low
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
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
Re: How to get previous days high, low
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.:
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: Select all
HighestVal = High of Data2;
Resolve: How to get previous days high, low
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
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