Correlation Indicator For ThinkOrSwim

Roger1956

New member
I posted an indicator earlier that I was having problems with. I think I have that solved now. I have some notes for this indicator because it covers a lot of territory.
Here are the notes and I will post the code at the end of the notes:

Signal Color Guide
Color Symbol Meaning When to Pay Attention
Cyan (Light Blue) ↑ Up Arrow Basic Confluence - 2+ technical levels aligning (EMAs, pivots, Fibs, etc.) Potential support/resistance zones
Orange △ Triangle Strong Confluence - 3+ levels aligning + High Volume Strong momentum/breakout potential
Magenta (Pink) ↓ Down Arrow Ultimate Confluence - 3+ levels aligning + Pivot Point High-probability reversal/breakout signals
How to Use These Signals
Cyan Up Arrows (↑)

Example: EMA21 + Daily Pivot align at the same price.

Action: Watch for bounces (if near support) or breaks (if near resistance).

Orange Triangles (△)

Example: EMA8 + Weekly Pivot + Fib Level align with 1.5x average volume.

Action: High-volume breakouts often continue trending—consider following the momentum.

Magenta Down Arrows (↓)

Example: EMA50 + Monthly Pivot + Yesterday’s 50% Range align at a local high/low.

Here is the Think or swim Script:
Code:
# Multi-Level Confluence Indicator (Final Working Version)
# All errors fixed - using dots for StrongSignal

declare upper;

# Inputs
input tolerance = 0.005;
input showLabels = yes;
input volumePeriod = 20;
input volumeMultiplier = 1.5;
input lookback = 2;

# EMAs
def EMA8 = ExpAverage(close, 8);
def EMA21 = ExpAverage(close, 21);
def EMA50 = ExpAverage(close, 50);

# Pivots
def dailyPivot = (high(period = "DAY")[1] + low(period = "DAY")[1] + close(period = "DAY")[1]) / 3;
def weeklyPivot = (high(period = "WEEK")[1] + low(period = "WEEK")[1] + close(period = "WEEK")[1]) / 3;

# Yesterday's Range
def yesterdayHigh = high(period = "DAY")[1];
def yesterdayLow = low(period = "DAY")[1];
def rangeLevel50 = yesterdayLow + (yesterdayHigh - yesterdayLow) * 0.5;

# Volume
def avgVolume = Average(volume, volumePeriod);
def highVolume = volume > avgVolume * volumeMultiplier;

# Pivot Detection
def isPivotHigh = high > Highest(high[1], lookback) and high > Highest(high[-lookback], lookback);
def isPivotLow = low < Lowest(low[1], lookback) and low < Lowest(low[-lookback], lookback);

# Level Matching
script isNear {
input level = 0;
input price = 0;
input tol = 0.005;
plot result = AbsValue(level - price) <= (price * tol);
}

# Confluence Check
def confluenceCount =
(if isNear(EMA8, close, tolerance) then 1 else 0) +
(if isNear(EMA21, close, tolerance) then 1 else 0) +
(if isNear(dailyPivot, close, tolerance) then 1 else 0) +
(if isNear(rangeLevel50, close, tolerance) then 1 else 0);

# Signal Conditions
def hasConfluence = confluenceCount >= 2;
def strongConfluence = confluenceCount >= 3 and highVolume;
def ultimateConfluence = confluenceCount >= 3 and (isPivotHigh or isPivotLow);

# Plot Statements (with dots for StrongSignal)
plot ConfluenceSignal = if hasConfluence then low else Double.NaN;
ConfluenceSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP); # Cyan up arrow
ConfluenceSignal.SetDefaultColor(Color.CYAN);
ConfluenceSignal.SetLineWeight(3);

plot StrongSignal = if strongConfluence then low else Double.NaN;
StrongSignal.SetPaintingStrategy(PaintingStrategy.POINTS); # Changed to dots
StrongSignal.SetDefaultColor(Color.ORANGE);
StrongSignal.SetLineWeight(4);

plot UltimateSignal = if ultimateConfluence then low else Double.NaN;
UltimateSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); # Magenta down arrow
UltimateSignal.SetDefaultColor(Color.MAGENTA);
UltimateSignal.SetLineWeight(5);

# Alerts
Alert(hasConfluence, "2+ Level Confluence", Alert.BAR, Sound.DING);
Alert(strongConfluence, "Strong Confluence + High Volume", Alert.BAR, Sound.BELL);
Alert(ultimateConfluence, "Ultimate Confluence + Pivot", Alert.BAR, Sound.CHIMES);

# Labels
AddLabel(showLabels, "Confluences: " + confluenceCount,
if ultimateConfluence then Color.MAGENTA
else if strongConfluence then Color.ORANGE
else if hasConfluence then Color.CYAN
else Color.GRAY);

AddLabel(showLabels, "Volume: " + Round(volume/avgVolume, 1) + "x Avg",
if highVolume then Color.GREEN else Color.GRAY);

Action: High-probability reversal zones—look for candlestick confirmations (e.g., doji, engulfing).
 
Last edited by a moderator:

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
375 Online
Create Post

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