Author Message:
The DPO operates by calculating the difference between the current closing price and a moving average of the closing price, adjusted for volatility using the True Range method. This difference is then smoothed over a user-defined period to create the oscillator. Additionally, Bollinger Bands are applied to the oscillator itself, providing visual cues for volatility and potential breakout signals.
More details: https://www.tradingview.com/script/MDtuDzTh-Dynamic-Price-Oscillator-Zeiierman/
CODE:
CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
#// ~~ © Zeiierman {
#// ~~ Tooltips {
#Hint length: Defines the lookback period for the oscillator and Bollinger Bands calculation. Increasing this value will consider a longer history, potentially smoothing out the oscillator and making the Bollinger Bands wider, leading to fewer signals. Decreasing this value will make the oscillator more sensitive to recent price changes, and the Bollinger Bands will become narrower, possibly increasing the number of signals.
#Hint smoothingFactor: "Determines how much the oscillator's calculation is smoothed. A higher smoothing factor reduces noise and makes the oscillator's line smoother, which may help in identifying the dominant trend more clearly but can delay signal generation. A lower smoothing factor makes the oscillator more responsive to recent price movements, which can be beneficial for short-term trading strategies but may increase the risk of false signals.
#indicator("Dynamic Price Oscillator (Zeiierman)"
# Converted by Sam4Cok@Samer800 - 01/2025
Declare lower;
input timeframe = AggregationPeriod.MIN;
input colorBars = yes;
input length = 33;
input smoothingFactor = 5;
def na = Double.NaN;
def cap = GetAggregationPeriod();
def tf = Max(cap, Timeframe);
#// ~~ Function to calculate True Range {
Script tr {
input h = high;
input l = low;
input c = close;
def tr1 = h - l;
def tr2 = AbsValue(h - c[1]);
def tr3 = AbsValue(l - c[1]);
def tr = Max(tr1,Max(tr2, tr3));
plot out = tr;
}
#// ~~ Function to calculate Bollinger Bands {
Script bollingerBands {
input src = close;
input length = 33;
input mult = 2;
def basis = Average(src, length);
def dev = mult * stdev(src, length);
def upper = basis + dev;
def lower = basis - dev;
plot up = upper;
plot lo = lower;
}
#// ~~ Adjusted Price based on True Range {
def tr = tr(high(Period = tf), low(Period = tf), close(Period = tf));
def volAdjPrice = ExpAverage(tr, length);
#// ~~ Price calculation {
def priceChange = (close(Period = tf) - close(Period = tf)[length]);
def priceDelta = (close(Period = tf) - volAdjPrice);
def avg = (priceDelta + priceChange) / 2;
def oscillator = ExpAverage(avg, smoothingFactor);
#// ~~ Bollinger Bands on Oscillator {
def bbHigh = bollingerBands(oscillator, length*5, 1).up;
def bbLow = bollingerBands(oscillator, length*5, 1).lo;
def bbHighExp = bollingerBands(oscillator, length*5, 2).up;
def bbLowExp = bollingerBands(oscillator, length*5, 2).lo;
def mean = (bbHighExp + bbLowExp) /2;
#// ~~ Plot {
plot DynamicPriceOsc = oscillator; # "Dynamic Price Oscillator"
plot DynamicMean = mean; # "Dynamic Mean"
plot BollHi = bbHigh; # "Bollinger High"
plot BollEpandHi = bbHighExp; # "Expanded Bollinger High"
plot BollLo = bbLow; # "Bollinger Low"
plot BollEpandLo = bbLowExp; # "Expanded Bollinger Low"
DynamicPriceOsc.SetLineWeight(2);
DynamicPriceOsc.AssignValueColor(if oscillator >= BollEpandHi then Color.GREEN else
if oscillator >= BollHi then Color.DARK_GREEN else
if oscillator <= BollEpandLo then Color.RED else
if oscillator <= BollLo then Color.DARK_RED else CreateColor(227, 161, 54));
DynamicMean.SetStyle(Curve.SHORT_DASH);
DynamicMean.SetDefaultColor(Color.GRAY);
BollEpandHi.SetDefaultColor(Color.GREEN);
BollHi.SetDefaultColor(Color.DARK_GREEN);
BollEpandLo.SetDefaultColor(Color.RED);
BollLo.SetDefaultColor(Color.DARK_RED);
AddCloud(DynamicPriceOsc, BollEpandHi, Color.GREEN, Color.CURRENT);
AddCloud(BollEpandLo, DynamicPriceOsc, Color.RED, Color.CURRENT);
AddCloud(if DynamicPriceOsc >= BollHi then DynamicPriceOsc else na, BollHi, Color.DARK_GREEN); #, Color.CURRENT);
AddCloud(if DynamicPriceOsc <= BollLo then BollLo else na, DynamicPriceOsc, Color.DARK_RED); #, Color.CURRENT);
AssignPriceColor(if !colorBars then Color.CURRENT else
if oscillator >= BollEpandHi then Color.GREEN else
if oscillator >= BollHi then Color.DARK_GREEN else
if oscillator <= BollEpandLo then Color.RED else
if oscillator <= BollLo then Color.DARK_RED else Color.GRAY);
#-- END of CODE