**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**.

**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**.

**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:

**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:

- Simple Arithmetic Moving Average (AMA)
- Exponential Moving Average (EMA)
- Linear Regression Line (LR)
- Kaufman Adaptive Moving Average (KAMA)
- Tillson T3 Triple Exponential Moving Average (T3)
- Jurik Moving Average (JMA)
- Volume Weighted Average Price (VWAP)
- Fixed value (zero, for example, will plot the deviation function about the zero axis)

**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:

- Standard Deviation (Bollinger Bands)
- Standard Error (Jon Andersen Bands)
- Average True Range – ATR (Keltner Bands)
- Jurik Average True Range JATR (ATR using Jurik Moving Average)
- Percentage
- Points

## 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:

- This is the perfect indicator to use in a Reversion To The Mean type of trading strategy, or a strategy that relies on price deviation from a reference value to initiate trades.
- The optimizer can test many different types of trading strategies without altering the basic strategy coding since the optimization process can, for example, switch between Bollinger Band, Keltner Band and Percentage Band deviations without requiring a manual manipulation or duplication of the strategy code.
- Code revisions and updates can be done in a single location, without the necessity of duplicating the changes throughout several different indicators or strategies.
- A consistent user interface across many separate functions makes makes the code more user-friendly and therefore less prone to inadvertent errors.

## FxDeviation Examples

**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.

**Bollinger Ribbons** are formed from an arithmetic moving average center-line and a **StdDev **displacement function.

This chart shows bands at displacements of 1, 2 and 3 standard deviations.

The bands characteristically widen when the price is trending and narrow during consolidation.

The closing price of the last bar is just above the 2nd lower band. **FxDeviation** shows the deviation value is **-1.95**

**Anderson Ribbons**use a linear regression centerline and a

**StdErr**deviation function.

Each band represents one standard error increment away from the centerline.

The linear regression centerline hugs the price more closely than a moving average, and standard error bands do not expand significantly when the price action is trending, unlike with **Bollinger Bands**. Instead, narrow bands indicate the price is trending consistently close to the regression line. Wide bands suggest increasing volatility of price away from the regression line and are typically seen during a break in a trend.

This ribbon represents a **Jurik Moving Average (JMA) **centerline and a percentage deviation from the centerline.

The propriety **Jurik Moving Average** is popular because of its smoothness and low lag. It must be purchased as an add-on to Tradestation.

The **Tillson T3 Moving Average **is similar and has almost the smoothness and low lag of the Jurik, and is available to Tradestation users as a built-in function. The **Tillson T3 Moving Average** also available for use in **FxDeviation**.

## FxDeviation Input Parameters

**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**.

**Downloads**

Initial posted version: **01/23/11**

Latest Update: 10/15/15

All ELD and code text files packaged here:

( *.ELD files are compiled for TS 9.1 )

Users of earlier versions fo Tradestation may compile the code

from the etext files included in the above *.zip file.

The code may be visualized here: