HighTick


A Flexible Stop Strategy

A flexible stops function, StopsFlexible, has been previously described. This was developed to allow a single function to calculate a wide variety of stop values. The same function was also used to create a StopsFlexible indicator.

In this post, the function has been used to create a corresponding StopsFlexible strategy.

The benefits of doing so are worth enumerated again.

Advantages of Using: StopsFlexible (Function, Indicator and Strategy)

  1. Coding duplication is markedly reduced, lessening the possibility of errors and making code maintenance more efficient.
  2. When used in a chart, the type of stop can be varied by simply changing an input parameter. This is more convenient than manually locating and inserting a new indicator from a large collection of stop indicators.
  3. Indicators using function StopsFlexible can display the differences in behavior of several different types of stops simultaneously, giving the user a graphical representation of each on the chart and visually revealing their unique behaviors. Such a graphical comparison assists in the selection of the most appropriate stop without the need for formal backtesting.
  4. When used in a strategy, optimization can exercise many types of stops using StopsFlexible, not just a single type of stop. In this manner, the best type of stop can be determined for the trading system being tested rather than only varying the "distance" of a single type of stop from the price reference.
  5. Blended Stops can can easily be created. For example, one blended stop could be: the sum of 1% of price plus 1.5 ATR units. Optimization can test blended stops efficiently to determine if the unique characteristics of blended stops can extract more profit from a trading system than traditional stops.
Which Stop is Best?

The StopsFlexible Strategy now provides a tool to answer that question. Not only can the magnitude of the stop be varied by the strategy optimizer, but the type of stop can now be varied. Complex blended stops can also be tested to determine if they have merit in trading systems.

Can A Trailing Stop Be the Basis of a Trading System?

The following screen shows a simple trading system based on an 1.5 Average True Range ratchet stop:

1.5 ATR Trailing Stop Trading System

Figure 1. 1.5 ATR Trailing Ratchet Stop on Gold Futures

The strategy performance report for a 10 year period follows:

 

Figure 2. Equity Curve - 1.5 ATR Trailing Stop Reversal System - Gold Futures - 10 years

The performance summary is shown below:

Strategy Performance Summery 1.5 ATR Trailing Stop Trading System - Gold Futures x 10 years

Figure 3. Strategy Performance Summary -1.5 ATR Trailing Stop Reversal System - Gold Futures - 10 years

Are Stop Reversal Trading Systems of Value?

The equity curve for gold above was a bit ragged but nevertheless showed some promise as a potential trading system. Optimizing the same system for S&P futures, however, failed to produce acceptable results:

Figure 4. Equity Curve - 1.7 ATR Trailing Stop Reversal System - S&P500 Futures - 10 Years

Further testing and optimizing the system in several other markets similarly failed to yield any consistent results. Most equity curves exhibited long periods of sideways movement or erratic behavior. I suspect that the behavior with Gold was an aberrancy and therefore would not recommend trading such a system.

Trailing stop reversal systems would be expected to perform reasonably well in strong trending markets and be penalized with whipsaws in sideways markets. If a good function were available to discriminate trends from sideways movement to filter the trades, a trailing stop reversal trading system might be more useful.

In fact, discriminating trend from non-trending markets, and doing so quickly without much lag, is an important component of almost all trading systems since the desired direction of the trade in a trending markets (with the trend) is the exact opposite of the appropriate direction in sideways market (counter trend).

I have always been curious to see if a trailing stop existed that would make a good reversal trading system. Now that a tool is available to test this further, I would encourage others to continue this exploration.

StopsFlexible as an Exit Strategy Only

The StopsFlexible Strategy was not originally intended to be a trading system in itself. That capability was only an afterthought facilitated by adding two additional input parameters to the strategy:

AllowStopEntry(true) Enter trade on hitting the stop if not already in a position
ReverseOnStop(true) Permit position reversal on hitting stop loss if TradeDirection allows

Normally, these input parameters should be left as False. In that case, the StopsFlexible Strategy operates in the way it was originally intended: as an exit strategy only supplementing other strategy components handling entries and profit targets.

With the input parameters AllowStopEntry = False, and ReverseOnStop = False, the StopsFlexible strategy will handle only trade exits. This is accomplished by the strategy monitoring MarketPosition and submitting orders for trailing stops only for non-zero values (currently in a trade, long or short).

If other strategy components that have been applied to the chart enter a position then the StopsFlexible Strategy automatically springs into action placing a trailing stop according to the settings of its input parameters. This is the only way I use the strategy in live trading. However, playing with it as a trading system is educational and lets you efficiently test wide variety of standard as well as unusual stops.

StopsFlexible Strategy Input Parameters

 

 

ShowActiveStopsOnly determines if the strategy will plot only the active stop (below price action if long trade, above price action if short trade) or both stops regardless of current position. Regardless of this setting, no plotting is done during strategy optimizations.

PlotLength indicates how many bars back from the current bar the trailing stops will be displayed. When research trading systems, this can be set to a large number (2000+) to allow the stops to display far back in history on the chart. In normal trading use, it is sufficient to show the trailing stops on the current visible portion of the chart, so the length can then be a much smaller number equal to the number of bars being displayed on the chart.

PlotWidth indicates how thick the trailing stop lines will be plotted.

HStopColor and LStopColor indicate the color of the plotted lines for the high stop and the low stop.

StopLineType specifies whether stop line will be solid, dashed or dotted line by entering the reserved words Tool_Solid, Tool_Dashed or Tool_Dotted, respectively.

RTOnly indicates whether the strategy will trade historical bars (false) or real time only (true).

ProfitTargetPts and StopLossPts set profit targets and fixed stop loss limits in addition to the trailing stops calculated by the strategy.

TradeDirection determines if the system will trade in the long direction (1), the short direction (-1), or both (0).

Maximum Trades determine the maximum number of trades the strategy will take. A high number is used if the strategy is used as a trading system).

AllowStopEntry and ReverseOnStop are both true when the strategy is set to continuously trade as a stop reversal system. When both are false, the strategy will only exit trades entered manually or by other strategy components also applied to the chart.

StrategyStartBar and StrategyStopBar are used to limit the bars during which trading can occur. Mainly used when debugging the operation of a trading system. The values represent the BarNumber on the chart that the strategy starts and stops. If zero, strategy is run on the entire chart.

HighRef and LowRef are the reference values from which the stop is measured.

Length is the length the MinList or MaxList of the reference values to delay the stop movement by Length bars.

SmoothRef is a simple average smoothing length applied to the HighRef and LowRef values.

UseKAMA is true if Kaufman Adaptive Moving Average of HighRef and LowRef is to be used as reference point for stop.

EffRatioLength, FastAvgLength and SlowAvgLength are Kaufman adaptive moving average input paremeters.

ATRLength, JATRLength, StdErrLength are the lengths used to calculate the ATR, Jurik ATR and standard error values. Jurik functions are disabled in code and can be uncommented to enable if the user has purchased the Jurik moving average function from Jurik Research.

StopPts, StopPct, StopATR, StopJurikATR and StopStdErr are the multipliers uses to calculate the stops based on points, price percentage, ATR units, Jurik ATR units and standard error.

HighRefTrig and LowRefTrig are the reference values for the values that will trigger the high stop (above the price action), low stop (below the price action).

SmoothTrigRef is the smoothing length applied to HighRefTrig and LowRefTrig above.

ResetPts, ResetPct, ResetATR, ResetJATR, and ResetStdErr are the number of points, percentage, ATR units, Jurik ATR units or standard error units that will be the initial stop setting after a stop has been triggered. Normally only one of these is non-zero, as the user generally chooses one type of stype to use.

Downloads

Initial posted version: 01/16/10

Latest Update: 01/14/13

*.ELD files are compiled for TS 9.1

All ELD and code text files packaged here:

StopsFlexible.zip

The code may be visualized here:

Strategy StopsFlexible

Function StopsFlexible

Indicator StopsFlexible

 

 

 

Bookmark and Share