OPEN-SOURCE SCRIPT

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.
OscillatorsStochastic Oscillatortascvitaliapirine

開源腳本

在真正的TradingView精神中,這個腳本的作者以開源的方式發佈,這樣交易員可以理解和驗證它。請向作者致敬!您可以免費使用它,但在出版物中再次使用這段程式碼將受到網站規則的約束。 您可以收藏它以在圖表上使用。

想在圖表上使用此腳本?


Tools and ideas for all Pine coders: tradingview.com/u/PineCoders/
Pine news broadcasts: t.me/PineCodersSquawkBox or twitter.com/PineCoders
TASC: traders.com/
更多:

免責聲明