| DYO: Close outside Bollinger Bands |
![]()
Q: You very kindly sent s DYO. I would like to find out if the DYO could be expanded to also show the difference between the close of that prior bar and the upper bollinger band if the close is above or the lower bollinger band if that close is below.
A:
Note the use of the -1 Bar Offset on Lines A, B, and C, in keeping with wanting to test the prior bar's relationship to the Bollinger Bands. The Bollinger Band study is on the chart, and then this DYO.
Line D and E test if the Close in GV[3] is above the Upper Band in GV[1], and when this is so, the Expression on Line E calculates the spread, which shows in the Section 1 window using the [E] in the Message Text.
Line F and G do the same thing for calculating the spread when the Close is below the Lower Band, and the answer is in the Message Text in the [G] reference.