A Flexible Price Deviation Indicator/Function: FxDeviation
FxDeviation is a super indicator that plots a wide variety of deviation or displacement functions on a chart from within a single indicator. It is a "sister" indicator to the flexible ribbon plotting indicator, RibbonsPlotter.
FxDeviation plots the deviation of the current price from any center line reference point that can be created by RibbonsPlotter.
Fig 1. Bollinger Band Ribbons and sister indicator FxDeviation showing the closing price deviation value from the center line.
This Bollinger Band (Ribbon), for example, is one type of well-known indicator where the centerline is defined to be a simple moving average and the vertical displacement used to calculate the bands above and below this moving average is some multiple of the standard deviation. The closing price on the right most bar is almost 2 bands below the center line. The corresponding deviation, measured in units of standard deviation from the moving average center line, is -1.95. When defining the deviation in units of standard deviation, the deviation is also known as the Z-Score.
However, FxDeviation is capable of plotting many other types of deviations, such as ATR units, percentage of price, standard error, etc.
FxDeviation can also plot multiple deviations on the same chart. For example, the following chart shows the simultaneous plot of the deviation of the high (green) and the low (red) of each bar from a linear regression center line:
Fig. 2 Deviation of High and Low of each bar from a Linear Regression center line.
FxDeviation must use the same input parameters for the center line and deviation function as the RibbonsPlotter indicator for the output to reflect the corresponding price action in the ribbon indicator.
FxDeviation's flexibility arises from the fact that the user can specify the center line function independently from the displacement function making it extremely flexible.
The centerline, or reference, is specified by the user by an input parameter RefID, and may be any of the following functions:
The Jurik Moving Average function requires the user purchase this Tradestation add-on from Jurik Research. The call to this function is commented out as most users will not be licensed to use this function. Those that are licensed may uncomment out the appropriate section of code in function FxDeviation to implement this feature.
The user may specify the deviation function used to produce the ribbons independently from the centerline (reference) function by specifying an input parameter, DevID. The deviation function may be any of the following:
Why Use the FxDeviation Indicator?
The FxDeviation indicator consolidates the ability to plot a large variety of deviations into a single indicator. This indicator then can replace several other indicators and provides a consistent user interface for this collection of functions.
The values plotted by the indicator originate from a corresponding multi-purpose FxDeviation function called by the indicator. This function may also be called from a strategy. Since the same function generates values for both the strategy and the FxDeviation indicator, the user can be assured that the values will be the same, provided the input parameters match.
A single multi-purpose deviation function has many benefits to the developer of automated trading strategies:
RibbonPlotter is capable of producing a wide variety of ribbon plots. Some of the examples shown below represent the most common and well-known ribbon or band functions. The sister function, FxDeviation, is shown immediately below and indicates the deviation of the closing price from the center line.
Price1 thru Price3 are the input prices used to calculate deviations from the center line. The user could, for example, plot the deviation of the high and low and the close of each bar on a single graph.
RefPrice is the price used to calculate the reference line from which deviation is measured. It can be, for example, Close, or if additional filtering of the center line is desired, AvgPrice.
RefID selects the function to use to calculate the centerline(s).
The other functions used to calculate the centerline (AMA, EMA, LR, etc.) are numbers in order of their length parameters following RefID. To select an exponential moving average centerline, for example, the user would enter 2 since EMALength appears in the second position following RefID. The user would specify a RefID of 3, 4 or 5 to choose a centerline consisting of a linear regression line, a Kaufman moving average or a Tillson T3 moving average, respectively, as this is the order that their corresponding length parameters appear in the input parameter list.
DevID is the value of the deviation function used to measure units of deviation from the PriceRef.
Ref1-Ref5 are references value that will also be display, if they are non-zero. For example, to draw a zero reference line on deviation graph, use a non-zero number very close to zero, such as 0.00001, as shown to the right. If you want to see when the deviation function reaches + or - 2.0, then add two additional reference values, Ref1 = +2 and Ref2 = -2.