Dynamic Price Oscillator (Zeiierman) for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
HYiCJ34.png

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
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
411 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top