DYOs support logic to branch through the use of Go To statements. It is possible to skip over a group of lines, which basically is a Begin..End block and jump back in the DYO listing which implements looping.
The following example calculates an average volume where the values being averaged occur at the same time period each day. It illustrates if the volume at mid day is excessive, or the volume at session open is normal, higher or lower. You do not get this insight by just doing a regular moving average of all adjacent volume values.

This example is a template you can download named Time-Volume using the Internet Services form.

Let me discuss the template design.
I have applied the template to a 1 hour chart, day session only, of ES and there are 7 hourly bars per day. So if I am working on the 10:00 bar, I know that 7 bars earlier is the 10:00 bar for yesterday, etc. So on Line A lets set a parameter for this time interval of 7 as the number of bars to jump back to find the same time bar in a prior day. This jump back distance is the number of bars to jump back, and will be my 'delta' distance.
Line B is the number of bars to fetch for the average, and a 10 is our 10-period moving average parameter. If you want a different average, edit the number on Line B. With the parameters in place, there are 3 more things I need to initialize.
I am going to read bar values back in time using there index reference. So Line C initializes a GV point to the current bar's Index. This will be GV [3] and I need two more GVs initialized to zero, so GV [4] will be where I sum the volume values and GV [5] will be our counter for the number of times we iterate through a loop. Line D sets [4] and [5] to zero.
Ok, now for the action to be done inside of our loop which is Line E through Line G. Line E will get our index pointer and decrement it by the delta size and resave in the index GV [3]. Line F will get the volume at the Index position read by GV [3] and also add in the value from the number field which is reading the contents of [4] which is our sum. This summation is rewritten back to GV [4]. Line G is the new Go To IF statement and it says to go back up to Line E based on a condition.
The Selection shows Inc(Value); Test (Value < #) so it is a composite statement that will increment the contents of Value, which is our counter GV [5].... THEN it will test the result to see if it is below our Period limit in GV[2]. The Inc(Value) thrown in on the Go TO just saves a step in incrementing the counter, which is going to be a common use item for looping. The increment read GV[5], added 1, and resaved in GV[5] directly. The result of G is Boolean, and not the counter value, and we have no use for this result so the Write GV on Line G is left on zero. When our count arrives at 10, our Period parameter, the looping passes to H instead of to E.
Now we can read the sum in [4] and divide by the Period in [2] and plot this as a red curve line.
Line J is just a little illustration of controlling the background color for the Section message. The message Text is the average from Line H and the current bar's volume value using [$V]. The message shows on 2 lines because the text contains a comma to divide the message. The character with the [H`] is the character on the tilde key and is just a formatting control to show this as an integer. Same with the ` with the [$V`] it shows result as an integer format to eliminate the .00
Line Logic is set to the Boolean result of Line I and Line I is a simple test of whether the Average written by Line H to GV [0] is below the bar's Volume. When the test is True, the background of the section message will be green and when it is false the section message will be red. This is a quick visual if the volume is below the average (red) or above the average (green). This kind of matches the red/green coloring I used in the bands on the other template.
This template illustrate several techniques, such as initializing parameters, reading bar values elsewhere on the chart, looping, plotting, coloring the section background, and showing values in integer format. The template is intended to be a teaching example, but should have use as well.
Last modified 8/24/09 1:49 PM
|