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.
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 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
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.
Pine news broadcasts: t.me/PineCodersSquawkBox or twitter.com/PineCoders
Nello spirito di condivisione promosso da TradingView, l'autore (al quale vanno i nostri ringraziamenti) ha deciso di pubblicare questo script in modalità open-source, così che chiunque possa comprenderlo e testarlo. Puoi utilizzarlo gratuitamente, ma il riutilizzo del codice è subordinato al rispetto del Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.