TrendCylinder (Expo) for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
nGLHFIm.png

Author Message:
The TrendCylinder is a dynamic trading indicator designed to capture trends and volatility in an asset's price. It provides a visualization of the current trend direction and upper and lower bands that adapt to volatility changes. By using this indicator, traders can identify potential breakouts or support and resistance levels. While also gauging the volatility to generate trading ranges. The indicator is a comprehensive tool for traders navigating various market conditions by providing a sophisticated blend of trend-following and volatility-based metrics.
More Details : https://www.tradingview.com/v/PFFQXniH/

CODE:
CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
# https://www.tradingview.com/v/PFFQXniH/
#// ~~ © Zeiierman {
# indicator("TrendCylinder (Expo)", overlay = true)
# Converted by Sam4Cok@Samer800    - 09/2023
#// ~~ Inputs {
input MovAvgType = AverageType.EXPONENTIAL;
input closingPrice     = close;
input MovAvgLength     = 200;
input volatilityPeriod = 100;    # "Period"
input trendFactor      = 9.0;    # 'Factor'
input trendStep        = 0.7;    #  "Step"
input atrLength = 200;

def na = Double.NaN;
DefineGlobalColor("line", CreateColor(41,98,255));
DefineGlobalColor("up", CreateColor(73,56,147));
DefineGlobalColor("dn", CreateColor(134,36,88));

#// ~~  Initialize Variables
def  trendFact = 1 / trendFactor;
def  trendPow = 1 / Power(2, volatilityPeriod);
def nATR = ATR(Length = atrLength);
def averageTrueRange = if IsNaN(nATR) then 0 else nATR;
#// ~~  Function to determine the trend direction
script determineTrendDirection {
    input direction = close;
    def diff = direction - direction[1];
    def dir = if (diff) > 0 then 1 else
              if (diff) < 0 then -1 else 0;
    plot out = dir;
}
#// ~~  Calculate Trend Direction
def currentTrend;
def crrTrend = currentTrend[1];
def scaledStandardDev = (averageTrueRange * trendFactor);
def trendDir = determineTrendDirection(crrTrend);
def trendDirection = trendDir * (scaledStandardDev);
def priceTrendDiff   = if (closingPrice - crrTrend) > 0 then
                       closingPrice - crrTrend else crrTrend - closingPrice;
def reciprocalFactor  = (scaledStandardDev * trendFact * trendPow);

#// ~~ Calculate the Current Trend
def trendAdjustment   = if priceTrendDiff > scaledStandardDev * trendStep then
                        (closingPrice + crrTrend) / 2 else
                        trendDirection * reciprocalFactor + crrTrend;
currentTrend      = trendAdjustment;

#// ~~  Calculate Upper and Lower Bands
def stvVal = StDev(closingPrice, volatilityPeriod);
def ema1 = MovingAverage(MovAvgType, stvVal, MovAvgLength);
def ema = ema1;
def upperBand = currentTrend + scaledStandardDev - averageTrueRange - ema;
def lowerBand = currentTrend - scaledStandardDev + averageTrueRange + ema;

#/ ~~ Plot
def isTrendConsistent = trendDirection == trendDirection[1];
def colorForPlot      = reciprocalFactor == 0;

plot Trend   = currentTrend;                                  # "Trend Line"
def Upper   = if isTrendConsistent then upperBand else na;    # "Upper Band"
def Lower   = if isTrendConsistent then lowerBand else na;    # "Lower Band"
trend.AssignValueColor(if colorForPlot then GlobalColor("line") else GlobalColor("dn"));

def upVal = Trend + (Upper - Trend)/2;
def dnVal = Trend - (Trend - Lower)/2;
AddCloud(Upper, upVal, GlobalColor("up"), GlobalColor("up"), no);
AddCloud(dnVal, Lower, GlobalColor("dn"), GlobalColor("dn"), no);


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