DYO: TTM Trend Indicator example
|
Q: I am attempting to write a DYO Study that generates the "information" in the TTM Trend Indicator. The indicator is a chart with modified Heikin-Ashi candles. I don’t want to draw the actual candles. I want to plot a little square that indicates the color of the candles.
The TTM Trend Indicator calculates the normal Heikin-Ashi candles, and their normal color. Then it checks the previous six candles. If the body (open vs. close) of the current Heikin-Ashi candle is inside the body of an earlier Heikin-Ashi candle, the color of the current candle is changed to that of the earlier candle.
A:
The color squares are shown at the top of the chart. Green is used for the Up Trend and Red for the Down Trend. The template puts on the Heikin-Ashi study to calculate the HA Open and Close. The HA candles do not need to be shown on the chart, but the study does need to be present.
On the Heikin-Ashi property form, the HA Close is being saved in GV[1], and the HA Open is being saved in GV[2]. These values are used to in the DYO to establish the initial candle body color for the HA candle.
This is a complex DYO and available as template 1520-TTMTrend. A discussion of each line of the DYO will be given to explain the steps that implement the TTM Trend Indicator.
Line A reads the HA Close in Global Variable [1] and compares it to the HA Open in GV[2]. Line A is thus an array of Boolean flags where True represents an Up Candle body and False represents a Down Candle body. This array of flags will be used for remembering the color of prior candles. The content of Line A will also be modified for those candles that are 'inside' of a prior candle body and need to assume the prior candle body's color.
Line B is setting a number for the size of the look back distance. The value of 6 is being saved in GV[1] for use by a powerful statement on Line C.
Line C will examine a set of HA candle bodies, and compare the current candle body to the members of the set. The size of the set will be the parameter in GV[1], which in our example is 6. Line C's result will be the index nearest the current candle index whose candle body covers the current candle body. If the current candle body is not inside of any of the candle bodies in the set, then Line C will return a value of zero. This result is saved in GV[3].
Line D will test the result of Line C and when the result is zero, execution will skip down to Line G in the DYO. Lines E and F are executed when the current candle body is 'inside' of a prior candle body, and the index for this prior candle body was stored in GV[3] by Line C.
Line E will calculate the number of bars away the prior candle body is from the current candle body by subtracting the indexes for the 2 candles. For, example if the index position for the current candle is 820 and the index for the earlier candle is 818, then the earlier bar is 2 bars away from the current bar. This distance away, or offset is saved in GV[4].
Line F moves the value form GV[4] into the Offset field of Line G and makes it a negative number in the process of the move. This enables Line G to read the Boolean flag from Line A from the correct index position for this earlier bar. This Boolean flag read from Line A by Line G is saved in GV[5].
Line H moves the flag from GV[5] into the current position of Line A, as a possible override of the candle body color to be used for the current candle. Finally, Line I and J will test the Boolean flag in GV[5] and display the block marker using the color Green or Red.
Template: 1520-TTMTrend
Last modified 8/8/08 1:50 PM
|