A Flexible Trailing Stop Strategy
The Anatomy of a Stop
Fig. 1. Bollinger Ribbons. Centerline is AMA, deviation is StdDev units.
The price from which the stop is offset (white line) to create a stop value.
Resetting the stop level serves two purposes: (1) it is much easier to see when a stop is hit, especially when the price trigger comes very close to but not quite touches the stop level, and (2) if a trade is re-entered in the same direction after stopping out, this reset padding can serve as the initial stop loss.
- Use UpperBandRef and LowerBandRef as centerlines for deviations ribbons (allows custom formulas to be specified).
- 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 bands about the zero axis, without any vertical price action)
The fixed value centerline allows the user to look at the deviation component of the bands without the vertical movement induced by the price action. With a fixed value of zero, RibbonPlotter will plot the deviation ribbons around the zero axis, and may be placed in a sub-graph below the main chart symbol.
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)
Why Use the RobbonPlotter Indicator?
RibbonsPlotter2 is an older version of RibbonsPlotter that uses function RibbonsCalc2 to calculate all values for the ribbons, instead of a local method RibbonsCalc. This makes RibbonsPlotter2 compatable with Tradestation versions prior to 9.0.
The function RibbonsCalc2 may also be called from a strategy. Since the same function generates values for both the strategy and the RibbonPlotter2 indicator, the user can be assured that the values will be the same, provided the input parameters match.
The single multi-purpose ribbon function RibbonsCalc2 has many benefits to the developer of automated trading strategies:
- 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 testing 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.
Bollinger Ribbons are formed from an arithmetic moving average center-line and a StdDev displacement function.
This chart shows bands at displace-ments of 1, 2 and 3 standard deviations.
The bands characteristically widen when price is trending and narrow during consolidation.
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.
The propriety Jurik Moving Average is popular because of it’s 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.
This Kaufman Adaptive Moving Average centerline shows relative horizontal tability centerline during consolidation. In combination with StdErr deviation bands makes an interesting basis for a Reversion to the Mean type of trading system.
These ribbons maintain a relative stable bandwidth.
This type of display allows a more useful comparison with the StdDevdisplacement function above.
It is easier to see the unique characteristics and differences between deviation functions when they are displayed about a fixed reference rather than following the price action.
RibbonPlotter Input Parameters
RefID selects the function to use to calculate the centerline(s). A value of 0 indicates the deviation function will be plotted centered about the zero axis, rather than following the price.
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.
NBands is the number of bands (ribbons) above and below to be plotted. StartMult is the multiplier to be used for the first band. The subsequent ribbons up to a total of NBands are drawn by adding Increment to the starting multiplier for the first band.
ShowCenterLine alllows the user to either display or not display the centerline for the ribbons.
DisplayParameters determines if the parameter values for the centerline and deviation function will be displayed on the graph in text, as was done in the samples shown. These text labels were drawn by the indicator instead of being added manually after the chart was produced.
CLVertPct, DevVertPct, CLHorizPct and DevHorizPct are the vertical and horizontal displacements (in percent of vertical or horizontal chart range) used to position the location of the text labels on the chart.
Further, the indicator encorporates “smart positioning” of the labels. If the price action is near the bottom edge of the chart and the user has specified that the label is to be drawn near the bottom of the chart, the program will automatically flip the label to the top of the chart to avoid overwriting the price action. The vertical displacement from the bottom edge of the chart specified by the user will be preserved, but instead this will become the vertical displacement from the top edge of the chart.
Initial posted version: 05/29/09
Latest Update: 11/02/13
*.ELD files are compiled for TS 9.1
All ELD and code text files packaged here:
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: