OPEN-SOURCE SCRIPT

CHOP Zone Entry Strategy + DMI/PSAR Exit

Atualizado
This is a Strategy with associated visual indicators and Long/Short and Reverse/Close Position Alerts for the Choppiness Index (CHOP). It is used to determine if the market is choppy (trading sideways) or not choppy (trading within a trend in either direction). CHOP is not directional, so a DMI script was ported into this strategy to allow for trend confirmation and direction determination; it consists of an Average Directional Index (ADX), Plus Directional Indicator (+DI) and Minus Directional Indicator (-DI). In addition, a Parabolic SAR is also included to act as a trailing stop during any strong trends.

Development Notes
---------------------------
This indicator, and most of the descriptions below, were derived largely from the TradingView reference manual. Feedback and suggestions for improvement are more than welcome, as well are recommended Input settings and best practices for use.

tradingview.com/support/solutions/43000501980-choppiness-index-chop/
tradingview.com/support/solutions/43000502250-directional-movement-dmi/
tradingview.com/support/solutions/43000502597-parabolic-sar-sar/

Recommend using the below DMI and PSAR indicators in conjunction with this script to fully visualize and understand how entry and exit conditions are chosen. Variable inputs should correlate between the scripts for uniformity and visual compatibility.

Directional Movement Index (DMI) + Alerts

Parabolic SAR


THANKS to LazyBear and his Momentum Squeeze script for helping me quickly develop a momentum state model for coloring the Chop line by trend.

Strategy Description
---------------------------
CHOP produces values that determine whether the market is choppy or trending. The closer the value is to 100, the higher the choppiness levels, while the closer it is to 0, the stronger the market is trending. Territories for both levels, and their associated upper and lower thresholds, are popularly defined using the Fibonacci Retracements, 61.8 and 38.2.

Basic Use
---------------------------
CHOP is often used to confirm the market condition to help you stay out of sideways markets and only enter when there is movement or imminent explosions. When readings are above the upper threshold, continued sideways movement may be expected, while readings below the lower threshold are typically indicative of a continuing trend. It is also used to anticipate upcoming trendiness changes, with the general belief that extended periods of consolidation (sideways movement) are followed by extended periods of strong, trending, directional movement, and vice versa.

One limitation in this index is that you must be cautious in deciding whether the range or trend will likely continue, or if it will reverse.

Confidence in price action and trend is higher when two or more indicators are in agreement -- while this strategy combines CHOP with both DMI and PSAR, we would still recommend pairing with other indicators to determine entry or exit trade opportunities.

Recommend also choosing 'Once Per Bar Close' when creating alerts.

Inputs
---------------------------
Strategy Direction - an option to only trade Short, Long, Both, or only in the direction of the Trend (Follow Trend is the Default).

Sensitivity - an incremental variable to test whether the past n candles are in the same trend state before triggering a delayed long or short alert (1 is the Default). Can help filter out noise and reduces active alerts.

Show Chop Index - two visual styles are provided for user preference, a visible Chop line with a background overlay, or a compact column and label only view.

Chop Lookback Period - the time period to be used in calculating CHOP (14 is the Default).

Chop Offset - changing this number will move the CHOP either forwards or backwards relative to the current market (0 is the Default).

Smooth Chop Line and Length - if enabled, the entered time period will be used in calculating a smooth average of the index (Enabled and 4 are the Defaults).

Color Line to Trend Direction - toggles whether the index line is colored to visually depict the current trend direction (Enabled is the Default).

Color Background - toggles the visibility of a background color based on the index state (Enabled is the Default).

Enable DMI Option - if enabled, then entry will be confirmed by and dependent on the ADX Key Level, with any close or reversal confirmed by both ADX and +/-DI to determine whether there is a strong trend present or not (Enabled is the Default).

ADX Smoothing - the time period to be used in calculating the ADX which has a smoothing component (14 is the Default).

DI Length - the time period to be used in calculating the DI (14 is the Default).

ADX Key Level - any trade with the ADX above the key level is a strong indicator that it is trending (23 to 25 is the suggested setting).

Enable PSAR Option - enables trailing stop loss orders (Enabled is the Default).

PSAR Start - the starting value for the Acceleration Force (0.015 is our chosen Default, 0.02 is more common).

PSAR Increment - the increment in which the Acceleration Force will move (0.001 is our chosen Default, 0.02 is more common).

PSAR Max Value - the maximum value of the Acceleration Factor (0.2 is the Default).

Color Candles Option - an option to transpose the CHOP condition levels to the main candle bars. Note that the outer red and green border will still be distinguished by whether each individual candle is bearish or bullish during the specified timeframe.

Note too that if both DMI and PSAR are deselected, then close determinations will default to a CHOP reversal strategy (e.g., close long when below 38.2 and close short when above 61.8). Though if either DMI or PSAR are enabled, then the CHOP reversal for close determination will automatically be disabled.

Indicator Visuals
---------------------------
For the candle colors, black indicates tight chop (45 to 55), yellow is loose chop (38.2 to 45 and 55 to 61.8), dark purple is trending down (< 38.2), and dark blue is trending up (> 61.8).

The background color has additional shades to differentiate a wider range of more levels…
• < 30 is dark purple
• 30 to 38.2 is purple
• 38.2 to 45 is light purple
• 45 to 55 is black
• 55 to 61.8 is light blue
• 61.8 to 70 is blue
• > 70 is dark blue

Long, Short, Close, and Reverse labels are plotted on the Chop line, which itself can be colored based on the trend. The chop line can also be hidden for a clean and compact, columnar view, which is my preferred option (see example image below).

snapshot

Visual cues are intended to improve analysis and decrease interpretation time during trading, as well as to aid in understanding the purpose of this strategy and how its inclusion can benefit a comprehensive trading plan.

DMI and Trend Strength
---------------------------
To analyze trend strength, the focus should be on the ADX line and not the +DI or -DI lines.  An ADX reading above 25 indicates a strong trend, while a reading below 20 indicates a weak or non-existent trend.  A reading between those two values would be considered indeterminable. Though what is truly a strong trend or a weak trend depends on the financial instrument being examined; historical analysis can assist in determining appropriate values.

DMI exits trade when ADX is below the user selected key level (e.g., default is 25) and when the +/- DI lines cross (e.g., -DI > +DI exits long position and +DI > -DI exits short position).

PSAR and Trailing Stop
---------------------------
PSAR is a time and price based indicator that excels at measuring direction and duration, though not the actual strength of a trend, which is why we use this in conjunction with DMI. It is also included in this script as a trailing stop option to maximize gains during strong trends and to mitigate any false ADX strengthening signals.

This creates a parabola that is located below the candle during a Bullish trend and above during a Bearish trend. A buy or reversal is signaled when the price crosses above or below the Parabolic SAR.

Long/Short Entry
---------------------------
1. CHOP must be over 61.8 (long) or under 38.2 (short).
2. If DMI is enabled, then the ADX signal line must be above the user selected Key Level (default is 25).
3. If Sensitivity is selected, then that past candle must meet the criteria in step 1, as well as all the intermediate candles in between.
4. If "Follow Trend" is selected and PSAR is enabled, then a long position can only open when the momentum and PSAR are in an uptrend, or short when both are in a downtrend, to include all intermediate candles if the Sensitivity option is set on a past candle.

Close/Reverse
---------------------------
1. If DMI is enabled, then a close flag will be raised when the ADX signal drops below the Key Level (of 25), and -DI crosses over +DI (if long), or +DI crosses over -DI (if short).
2. If PSAR is enabled, then a close flag will be raised when the current trend state is opposite the last state.
3. If both DMI and PSAR are disabled, then a close flag will be raised if the Chop line drops under 38.2 (if long) or goes over 61.8 (if short).
4. If a Long or Short Entry is triggered on the same candle as any of the above close flags, then the position will be reversed, else the position will be closed.

Strategy Alerts
---------------------------
1. Long Entry
2. Short Entry
3. Reverse
4. Close

The provided backtest result is based on a position sizing of 10% equity with 100k initial capital. When testing SPX, disabling the DMI performed the best, but EURUSD performed poorly without it enabled, and TSLA had a small reduction in net profit. Timeframe likewise differed between commodities with TSLA performing best at 30M, SPX at 15M, and EURUSD at 4H. I do not plan on using this as a standalone strategy, but I also was expecting better results with the inclusion of EMI and PSAR to compliment the CHOP. Key elements of this script will likely be included in future, more holistic strategies.

Disclaimer
---------------------------
Past performance may not be indicative of future results. Due to various factors, including changing market conditions, the strategy may no longer perform as well as in historical backtesting. This post and the script are not intended to provide any financial advice. Trade at your own risk.

No known repainting, though there may be if an offset is introduced in the Inputs. I did my best not to code any other variables that repaint, but cannot fully attest to this fact.
Notas de Lançamento
Version 1.1

- Cleaned up selectable option to display Chop Index as a Line, Colored Line (using Momentum Trend), Colored Line (using PSAR Trend), or as Columns.

- Added option to color Chop Index line by PSAR trend direction, as opposed to only the momentum trend. This is useful to also help understand when a position exit is triggered by a PSAR reversal.

- Changed Follow Trend to only use the momentum or PSAR, not both. PSAR is the default in all cases unless the trend line with momentum is explicitly displayed. Note that the noisy nature of the momentum line could result in a missed Bullish or Bearish entry.

- Updating script description image to show companion DMI indicator with only Exit conditions shown. This is useful in understanding how a position exit is triggered by DI crossover or ADX trend below the key level.

snapshot
Notas de Lançamento
Version 1.2

- Removed Input to enable Smooth Line. This has redundant functionality -- the default Smooth Length is still 4, but changing this value to 1 has the same effect as disabling the Smooth Line checkbox.

- Reorganized Input selections for readability and user efficiency.
CHOPChop ZoneDirectional Movement Index (DMI)DMIentryexitMomentum Indicator (MOM)Parabolic Stop and Reverse (PSAR)psarreversezone

Script de código aberto

No verdadeiro espírito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam compreendê-lo e analisá-lo. Parabéns ao autor! Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações é regida pelas Regras da Casa. Você pode favoritá-lo para usá-lo em um gráfico.

Quer usar esse script no gráfico?


My Published Scripts:
tradingview.com/u/IronCasper/

Aviso legal