High-Low Cloud Trend [ChartPrime] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
XulCddr.png


Author Message:
The High-Low Cloud Trend - ChartPrime indicator, combines the concepts of trend following and mean reversion into a dynamic cloud representation. This indicator constructs high and low bands based on lookback periods, which adjust dynamically to reflect market conditions. By highlighting the upper and lower extremes, it provides a visual gauge for potential reversals and continuation points.

CODE:

CSS:
#// Indicator for TOS
#// © ChartPrime
#indicator("High-Low Cloud Trend [ChartPrime]", overlay = true, max_labels_count = 500)
# Converted by Sam4Cok@Samer800  - 09/2024

input timeframe = AggregationPeriod.MIN;
input colorBars = yes;
input LookbackPeriod = 35;           # "Lookback Period"
input showMeanReversionPoints = yes; # "Mean Reversion Points"

def na = Double.NaN;
def current = GetAggregationPeriod();
def tf = Max(current, timeframe);
#// Calculate the highest and lowest over the lookback period
def highest  = Highest(high(Period = tf), LookbackPeriod); #  // Highest high over the lookback period
def lowest   = Lowest(low(Period = tf), LookbackPeriod); #  // Lowest low over the lookback period

#// Calculate the highest and lowest over a shorter period (1/3 of the original period)
def highest1 = Highest(high(Period = tf), LookbackPeriod / 4); #  // Highest high over the shortened lookback period
def lowest1  = Lowest(low(Period = tf), LookbackPeriod / 4); #  // Lowest low over the shortened lookback period

#// Logic to update the 'value' variable based on certain conditions
def state = {default "ini", "HHLL"};
def value;
switch (state[1]) {
case "HHLL" :
    value = if low(Period = tf)  == lowest then highest else
            if high(Period = tf) == highest then lowest else value[1];
    state = state[1];
default :
    value = na;
    state = state."HHLL";
}
#// Determine the 'band' value based on the relationship between 'close' and 'value'
def band  = if close > value then lowest else highest;
def band1 = if close > value then lowest1 else highest1;
#// Determine the color based on the relationship between 'close' and 'value'
def col = close > value;
def cross = (close Crosses band);

#-- plots
#// Plot a diamond shape at the 'band' value when there's a cross between 'close' and 'band'
plot diaCross = if cross[1] then band else na;
plot p1 = if cross then na else band;
def p2 = band1;
diaCross.SetPaintingStrategy(PaintingStrategy.SQUARES);
diaCross.AssignValueColor(if col then Color.GREEN else Color.RED);
p1.AssignValueColor(if col then Color.GREEN else Color.RED);

AddCloud(p1, p2, Color.DARK_RED, Color.DARK_GREEN);

#// Mean Reversion Conditions
def hCross = (high Crosses Below band1[1]);
def lCross = (low  Crosses Above band1[1]);
def mean_rev_dn = hCross and band1[1]==high(Period=tf)[1] and high(Period=tf)!= band1 and !cross and band[1]==band;
def mean_rev_up = lCross and band1[1]==low(Period=tf)[1]  and low(Period=tf)!= band1 and !cross and band[1]==band;

plot meanDn = if mean_rev_dn[-1] and showMeanReversionPoints then high else na;
plot meanUp = if mean_rev_up[-1] and showMeanReversionPoints then low else na;
meanDn.SetDefaultColor(Color.MAGENTA);
meanUp.SetDefaultColor(Color.CYAN);
meanDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
meanUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

# bar Color

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if col then Color.DARK_GREEN else Color.DARK_RED);

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