Volatility Trend (Zeiierman) for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
kyVuCOw.png


Author Message:
The Volatility Trend (Zeiierman) is an indicator designed to help traders identify and analyze market trends based on price volatility. By calculating a dynamic trend line and volatility-adjusted bands, the indicator provides visual cues to understand the current market direction, potential reversal points and volatility.
More Details : https://www.tradingview.com/v/ZrEdJ42P/

CODE:

CSS:
# https://www.tradingview.com/v/ZrEdJ42P/
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0
#indicator("Volatility Trend (Zeiierman)", overlay = true)
# Converted by Sam4Cok@Samer800    - 11/2023

input trendLength        = 20;      # "Trend Control"
input trendDynamicLength = 100;     # "Trend Dynamic"
input volatilityControl  = 10;      # "Volatility"
input volatilitySensitivity  = 0.5;  # "Sensitivity"
input squeezeControl         = 1;    # "Squeeze Control"
input ScalpingMode         = no;     # "Enable Scalping Trend (For BTC)"

def na = Double.NaN;

DefineGlobalColor("Up", CreateColor(41, 98, 255));
DefineGlobalColor("Dn", CreateColor(136, 14, 79));
DefineGlobalColor("dup", CreateColor(73, 56, 147));
DefineGlobalColor("ddn", CreateColor(134, 36, 88));

#trendDirectionFunction(dir) =>
script trendDirectionFunction {
    input trendir = close;
    def diff = trendir - trendir[1];
    def dir = if diff > 0 then 1 else
             (if diff < 0 then -1 else 0);
    plot out = dir;
}
#// Function to calculate standard deviation
script stddev_function {
    input src_ = close;
    input p = 20;
    input squeezeControl = 1;
    input shorttermtrend = yes;
    def bar_index = BarNumber();
    def mean = Average(src_, p);
    def sum_diff_sq;
    if bar_index < p {
        sum_diff_sq = 0.0;
    } else {
        sum_diff_sq = fold i = 0 to p with q do
                      q + Power(src_[i] - mean, 2);
    }
    def stdev = if shorttermtrend then Sqrt(sum_diff_sq / close * p * squeezeControl) else
                                       Sqrt(sum_diff_sq / p * squeezeControl);
    plot out = stdev;
}
#/ Var
def trend;
#// Call Trend Direction
def trendDirection = trendDirectionFunction(trend[1]);
#// Call Scaled StdDev
def scaledStdDev = stddev_function(trend[1], trendLength, squeezeControl, ScalpingMode) * volatilityControl;
def priceTrend   = AbsValue(close - trend[1]);

#// Calculate the Trend
def trendAdjustment = if priceTrend > scaledStdDev then (close + trend[1]) / 2 else
                 trendDirection * (scaledStdDev * (1 / volatilityControl) * (1 / trendDynamicLength)) + trend[1];
trend = trendAdjustment;

#// Get Upper and Lower Bands
def upper = trend + (volatilitySensitivity * scaledStdDev);
def lower = trend - (volatilitySensitivity * scaledStdDev);

#/Plot
def col = trendDirection == 1;
def trueTrend = trendDirection == trendDirection[1];

plot trend_ = if trueTrend then trend else na;    # "Trend Line"
plot upper_ = if trueTrend then upper else na;    # "Upper Circle Line"
plot lower_ = if trueTrend then lower else na;    # "Lower Circle Line"

trend_.AssignValueColor(if col then GlobalColor("Up") else GlobalColor("Dn"));
upper_.AssignValueColor(if col then GlobalColor("dDn") else GlobalColor("dDn"));
lower_.AssignValueColor(if col then GlobalColor("dUp") else GlobalColor("dUp"));


def halfUp = upper_ - (upper_ - trend_) / 2;
def haldDn = trend_ - (trend_ - lower_) / 2;

AddCloud(upper,  halfUp,  GlobalColor("dDn"));
AddCloud(haldDn,  lower,  GlobalColor("dUp"));

# 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
502 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