PineCodersTASC

TASC 2023.06 Stochastic Distance Oscillator

█ OVERVIEW

This script implements the stochastic distance oscillator (SDO), a momentum indicator introduced by Vitali Apirine in an article featured in TASC's June 2023 edition of Traders' Tips. The SDO is a variation of the classic stochastic oscillator and is designed to identify overbought and oversold levels, as well as detect bull and bear trend changes.

█ CONCEPTS

Unlike the classic stochastic oscillator, which compares an asset's price to its past price range, the SDO measures the size of the current distance relative to the maximum-minimum distance range over a set number of periods. The current distance is defined as the distance between the current price and the price n periods ago.

The readings of the SDO can be used to identify the following states of the asset price:
  • Uptrend state: the oscillator crosses over 50 from a non-uptrend state.
  • Downtrend state: the oscillator crosses under -50 from a non-downtrend state.
  • Overbought state: the oscillator is in an uptrend and crosses -50 for the first time.
  • Oversold state: the oscillator is in a downtrend and crosses 50 for the first time.
  • Trend continuity: the oscillator crosses 0 in the direction of the current trend.
The script indicates these five conditions using on-chart signals and background coloring.


█ CALCULATIONS

The SDO is calculated as follows:

1. Calculate the distance between the current price and the price n periods ago, as well as the maximum and minimum distances for the selected lookback period. The author recommends using one of two values of n, 14 or 40 bars.

2. Calculate the time series %D that represents the relation between the asset's current distance and its distance range over a loockback period:
%D = (Abs(current distance) − Abs(minimum distance)) / (Abs(maximum distance) − Abs(minimum distance)) * 100

3. Use the calculated %D to obtain the SDO:
  • If the closing price is above the close n periods ago, SDO = %D
  • If the closing price is below the close n periods ago, SDO = −%D
  • If the closing price equals the close n periods ago or the current distance equals the minimum distance, SDO = 0
4. Smooth the SDO using an exponential moving average (​EMA). The author recommends using an EMA in the range from 3 to 6.

Adjustable input parameters include the number of periods n, the lookback period for calculating %D, the smoothing EMA length, and the overbought/oversold threshold level.

Tools and ideas for all Pine coders: www.tradingview.com/u/PineCoders/
Pine news broadcasts: t.me/PineCodersSquawkBox or twitter.com/PineCoders
TASC: traders.com/
Script open-source

Dans le véritable esprit de TradingView, l'auteur de ce script l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par le règlement. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.

Vous voulez utiliser ce script sur un graphique ?