How to get previous days high, low

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1200
Joined: 23 Nov 2010
Has thanked: 699 times
Been thanked: 218 times

How to get previous days high, low

Postby arjfca » 18 Mar 2012

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

bowlesj3
Posts: 1915
Joined: 21 Jul 2007
Has thanked: 128 times
Been thanked: 388 times

Re: How to get previous days high, low

Postby bowlesj3 » 18 Mar 2012

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
These users thanked the author bowlesj3 for the post:
arjfca

Xyzzy
Posts: 147
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 72 times

Re: How to get previous days high, low

Postby Xyzzy » 19 Mar 2012

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: Select all

HighestVal = High of Data2;
These users thanked the author Xyzzy for the post:
arjfca

arjfca
Posts: 1200
Joined: 23 Nov 2010
Has thanked: 699 times
Been thanked: 218 times

Resolve: How to get previous days high, low

Postby arjfca » 19 Mar 2012

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


Return to “MultiCharts”