TrendIndicatorsLibrary "TrendIndicators"
This is a library of 'Trend Indicators'.
It aims to facilitate the grouping of this category of indicators, and also offer the customized supply of
the source, not being restricted to just the closing price.
Indicators (this is a work in progress):
1. Absolute DI (Directional Moviment Index) (Difference between DI+ and DI-).
Used in 'DMI Stochastic Extreme' by Barbara Star.
2. DMI
DI_Abs(lengthDI, smoothDI, typeMA, lengthMA)
@description Absolute DI (Directional Moviment Index).
Used in 'DMI Stochastic Extreme' by Barbara Star.
Difference between DI+ and DI-
Parameters:
lengthDI : (int) Length of DI+/DI-
smoothDI : (bool) Sets whether absolute DI should be smoothed
typeMA : (int) Type of moving average of smoothing
lengthMA : (int) Length for moving average of smoothing
Returns: (float) Absolute value of DI
dmi(diLength, adxSmoothing)
@description DMI (Directional Movement Index)
Same as ta.dmi()
Parameters:
diLength : (int) Length of DI+/DI-
adxSmoothing : (int) ADX Smoothing
Returns: Tuple of three DMI series: Positive Directional
Movement (+DI), Negative Directional Movement (-DI) and Average Directional Movement Index (ADX).
dmi(source, diLength, adxSmoothing)
@description DMI (Directional Movement Index)
Customized version of ta.dmi(), with custom source
Parameters:
source : (float) Source for DI+/DI-
diLength : (int) Length of DI+/DI-
adxSmoothing : (int) ADX Smoothing
Returns: Tuple of three DMI series: Positive Directional
Movement (+DI), Negative Directional Movement (-DI) and Average Directional Movement Index (ADX).
DI
JSS Table - RSI, DI+, DI-, ADXSimple table to show the values for indicators which can be used to initiate trades:
RSI: Long above 55 // Short below 45 // Choppy between 45-55
DI+: Long above 25
DI-: Short above 25
Note when to avoid trend trades:
- If DI+ and DI- are both below 25 then market is choppy
- If RSI is between 45-55 then market is choppy
Directional Index Macro IndicatorWhat is This For?
The default settings for this indicator are for BINANCE:BTCUSDT and intended to be used on the 3D timeframe to identify market trends. This indicator does a great job identifying whether the market is bullish, bearish, or consolidating. This can also work well on lower time frames to help identify when a trend is strong or when it's reversing.
Directional Index Rate of Change
Core to this indicator is the rate at which DI+ and DI- are moving away or towards each other. This is called The Rate of Change (ROC). "The ROC length dictates how many bars back you want to compare to the current bar to see how much it has changed. It is calculated like this:
(source - source /source ) * 100"
The rate of change is smoothed using an EMA. A shorter EMA length will cause the ROC to flip back and forth between positive and negative while a larger EMA length will cause the ROC to change less often. Since the rate of change is used to indicate periods of 'consolidation', you want to find a setting that doesn't flip back and forth too often. Between the DI+ and DI- is a blue centerline. Offset from this centerline is a channel that is used to filter out false crosses of the DI+ and DI-. Sometimes, the DI+ and DI- lines will come together in this channel and cross momentarily before resuming the direction prior to the cross. When this happens, you don't want to flip your bias too soon. The wider the channel, the later the indicator will signal a DI reversal. A narrower channel will call it sooner but risks being more choppy and indicating a false cross.
Indicator Status Line
This indicator has 4 values in the status line (in order):
DI+
DI-
Distance between DI+ and DI-
DI Rate of Change ( how quickly are DI+ and DI- moving away or towards center )
Indicator Plots
This indicator plots DI+ (green), DI- (red), and a center channel between DI- and DI+. Across the top of the indicator, red and green triangles indicate the market trend while the background changes to show whether the price is in an impulse wave or consolidating. This makes up 4 possible scenarios:
Bullish impulse wave ( green triangle up + green background )
Bullish consolidation ( green triangle up + yellow background )
Bearish impulse wave ( red triangle down + red background )
Bearish consolidation ( red triangle down + yellow background )
Summary
Combined with support and resistance levels, volume, and your other favorite indicators, this can be a useful tool for validating that your entries are not going against the trend.
Disclaimer
This is not financial advice. Do not take trades only based on the DI+ and DI- crossing. Always use multiple indicators to validate your entries and never take a trade when you aren’t emotionally grounded. Have a plan. Stick to the plan.
The screenshot for this strategy is of a manual historical review of BTC on the 3 day chart. The indicator was built to try and mimic the chart above. You’ll see that it nails it sometimes, is a little late sometimes, and chops around between consolidation and impulse waves when it should stay in consolidation. Share your settings if you are able to improve the choppiness without sacrificing catching the reversals early.
adx: Configurable ADX (library) Library "adx"
Calculate ADX (and its constituent parts +DI, -DI, ATR),
using different moving averages and periods.
adx(atrMA, diMA, adxMA, atrLen, diLen, adxLen, h, l, c)
Parameters:
atrMA : Moving Average used for calculating the Average True Range.
Traditionally RMA, but using SMA here and in adxMA gives good results too.
diMA : Moving Average used for calculating the Directional Index.
Traditionally, RMA.
adxMA : Moving Average used for calculating the Average Directional
Index. Traditionally RMA, but using SMA here and in atrMA gives good results
too.
atrLen : Length of the Average True Range.
diLen : Length of the Directional Index.
adxLen : Length (smoothing) of the Average Directional Index.
h : Candle's high.
l : Candle's low.
c : Candle's close.
Returns:
Average Directional Index + ΔDI± (Delta)Average Directional Index (ADX) and Difference between DI+ and DI- (ΔDI±), I call it Delta for short.
The idea explained:
ADX is a common indicator for analysing trend strength. Values over 25 usually indicate the symbol is in "trend mode", meaning there is a lot of momentum, upwards or downwards, - while values under 25 suggest it is in "range mode", the price moves sideways, lacking energy. Note that this indicator is not volume-based.
I moved the graph (red) down 25 points; this version shows positive values in "trend mode" (>25), and negative values in "range mode" (<25). The line sits at 0. The underlying code for the ADX is basically identical to the official TradingView built-in version.
Now the exciting part: DI+ and DI- are used to calculate the ADX. They are sometimes included in the ADX indicator chart, I included a version that shows them in the graphic, at the bottom. Traditionally, DI+ (green) crossing DI- (dark red) from below shows the beginning of an upward trend, and therefore a good LONG entry position. However, I noticed that this is usually not the case: this method responds very slowly to the actual price movement. At the point the indicator tells you to enter, the trend is usually already exhausted.
I found a better way to use this data; instead of waiting for both graphs to cross, meaning the difference in their respective values is 0, we look for the greatest possible difference. That is what the purple graph of my indicator shows (ΔDI±). It utilizes the zero-line we already created for the ADX. High positive values declare that the DI+ is much greater than the DI-, and vice versa. Delta is the greek letter used in mathematics for difference, so that is what I call this indicator.
How to use it:
When you look at the graph, low Delta values seem to be good entry points for LONG positions, high Delta values good exits. This is similar to how RSI and CCI work, which is why included them in the chart above (). However, this is only reliable, when the ADX is above 25, or 0 in this version, indicating the symbol is in "trend mode". This is important .
When you look at the examples in the chart, you can confirm that. The marked candles show good entry and exit points, with Delta being notably low/high (±25 seems to be a good threshold, the dashed lines sit at +30/-30), and the ADX above 0 (25). Now, you might have noticed that around mid-december the Delta actually registers the highest value for this symbol in the given time frame, indicating a strong SHORT after a steep climb. But, importantly , the ADX is not in "trend mode" as required for a clear signal, it is in "range mode": the price discovers this new level and takes a few days to get used to it. It does not fall. This shows why only the combination of both Delta and ADX gives desirable results.
I noticed that this seems to work best for 1D and 1H candles; if you find any other time frames or scenarios, let me know!
PLEASE NOTE THAT THIS IS BASED ON PERSONAL, EMPIRICAL OBSERVATIONS. PAST RESULTS DO NOT GUARANTEE SUCCESS IN THE FUTURE. DO NOT TAKE THIS AS INVESTMENT ADVICE!
Thanks to TradingView and robertkowalski for providing the basis on which the code is built. Credit goes to the appropriate developers/owners.
()
Let me know if you make any other observations, or find other ways to use the data!
Wolfs ADX + DII have created an alternative visualisation of the ADX + DI indicator created by MasaNakamura, credits to them for providing the source code! :-)
The histogram represents the distance between the DI+ and the DI-. The crossing of the histogram is equal to the crossing of the DI lines.
The ADX line is coloured based on the threshold.
This creates a clean representation of the ADX + DI.
ADX Di+ Di- [Gu5]Fill indicates Strong Trend
Cross indicates End of Trend
--
El relleno indica una fuerte tendencia cuando el Di supera "Level Trend"
El cruce de Di+ con Di- indica el fin de la tendencia
Cuando el valor del ADX es menor a "Level Range", estamos en Rango
ADX and DI With Coloured Histogram BUY/SELLWe display here the ADX has a colored histogram, which is
- green when ADX and DI+ are higher then DI-, while the ADX is increasing, meaning that we are in a potential uptrend--> we should rather be long (only buy if you have other concordant signals !)
- red when ADX and DI- are higher then DI+, while the ADX is increasing, meaning that we are in a potential downtrend --> we should rather be short (only sell if you have other concordant signals !)
- not visible if none of these conditions are met, meaning that the indicator do not show a potential trend --> don't use this indicator to buy or sell at this stage
ADX +- DiThis Adx +-Di is just a complete version of what the ADX is supposed to signal.
So you have:
15 (contraction), 20 (threshold), 30 (expansion), 40 (resistance) levels.
Below 20 the price is not trending
Above 30 the price is trending
Below 15 price has been in contraction for too long
Between 20 and 30 price is in a "transition zone".
I finally added a "Resistance" level (40), which has to be adapted to best represent the historical levels where price usually encounters resistance, and where the price can be declared "overtrending", which means a return to lower levels is likely to happen.
I've chosen mild colors, and set the Adx Color to White, because I use black background, you can easily change that.
Enjoy
-Maurice
ADX coded with DIAn easier to read implementation of ADX and DI, with colour indicating direction of trend, oscillator indicating strength of trend, and below threshold shown with a lack of colour (black).
ADX and RSI ComboThis indicator combines two separate Simple RSI indicators so you can show different periods together, as well as an ADX indicator with DI+ and DI-. I prefer to use one indicator to show the whole thing, instead of stacking the individual indicators.