This example shows how to obtain the High and Low 3 or more days back. For Today's, Yesterday's, or the High and Low from 2 Days back, the Daily Price Lines tool would be a quick way to harvest the values and store in Global Variable for use in DYOs.

The idea is this: Have a flag for 1st bar of new Day, and use the flag event to shift rightward the GV array which retains a series of saved values of Yesterday's High and Yesterday's Low. Then each position in the array is the H and L of some prior day in sequence.
Line A and B put yesterday values in GV [10] and [15]. Line C tests if this is the first bar of the globex session, and if so then shifts the GV array rightward 1 position, starting at the Read GV location of 10 and doing a quantity of 10 elements. So [18] goes into [19] and [17] into [18] etc and [10] into [11]. Thus the Day 3 high will have shifted into [12] and Day 3 Low will have shifted into [17] on the day that is today. These values in [12] and [17] are plotted bgy Line F and G. That means Day 4 HL would be in [13] and [18], and Day 5 HL would be in [14] and [19], just in case you are interested in them as well. Day 2 values are in [11] and [16], and yesterday's High and Low are in [10] and [15].
In summary, we shift once per day and that is controlled by C, D and E. And on Line C, I threw up the yellow stripe so you see the time of day of the shift, ie at start of new globex session. The yellow stripe is where you see the H & L value stair step to a new level. The YH and YL dotted lines are from a Daily Price Lines I put on the chart, and is unrelated to the solution shown by this DYO.

Values plotted on Jan 9th are the High and Low from Jan 6th, ie 3 days back as per the DYOs design objective.
The notation of [#] like on Line E means a GV set of size specified in the Number field. The Line E Shift Right shifts a GV set of size 10, meaning we will work with 10 adjacent Global Variables in the GV array. The starting point of the set is the Read GV index, meaning 10 through 19 because the Read GV index is 10 in the example.

Here is the visual of the GV array showing the High values in 10 through 14, and the Low values in 15 through 19. You can see the values shifting rightward if you compare the values with their source on the chart. Perhaps it would have been clearer to have parked current values in 14 and 19 and shifted leftward. Then the older values would be on left side, ie [10] is oldest high, and [14] is recent high.
read more » DYO: Quarterly High and Low
Last modified 8/25/09 3:05 PM
|