GHLA SuperTrend CCI HighLow Activator For ThinkOrSwim

cando13579

Active member
VIP
GHLA SuperTrend CCI High-Low Activator Oscillator
A multi-layered trend and momentum indicator that combines Gann-inspired high/low levels, a SuperTrend mechanism, and a custom CCI oscillator. It provides dynamic entry and exit signals, confirming bullish or bearish trends while filtering out market noise. The accompanying oscillator visually represents trend strength and direction, allowing traders to quickly identify opportunities and avoid indecision zones.
GHLA-SUPERTREND-OSCCILATOR.png

Code:
# GHLA_SuperTrend_CCI_High_Low_Activator_Oscillator
#By CANDO13579
 
declare lower;
declare real_size;
input ghlaPeriod = 10;
input stPeriod = 14;
input stShiftTicks = 20.0;
input useFilter = yes;

def minTick = TickSize();
def shift = stShiftTicks * minTick;

# -----------------------------
# GHLA Logic
# -----------------------------
def ghlaAvgH = Average(high, ghlaPeriod);
def ghlaAvgL = Average(low, ghlaPeriod);

def sw = if close > ghlaAvgH then 1
         else if close < ghlaAvgL then -1
         else 0;

def ghlaDir = CompoundValue(1, if sw != 0 then sw else ghlaDir[1], 0);
def ghlaLevel = if ghlaDir < 0 then ghlaAvgH else ghlaAvgL;

# -----------------------------
# Custom CCI using Typical Price
# -----------------------------
def tp = (high + low + close) / 3;
def tpSMA = Average(tp, stPeriod);
def meanDev = Average(AbsValue(tp - tpSMA), stPeriod);
def cciValue = if meanDev == 0 then 0 else (tp - tpSMA) / (0.015 * meanDev);

# -----------------------------
# SuperTrend State Machine
# -----------------------------

# stFlag: 1=long, -1=short
rec stFlag = if IsNaN(stFlag[1]) then if cciValue >= 0 then 1 else -1
             else if cciValue > 0 and stFlag[1] <= 0 then 1
             else if cciValue < 0 and stFlag[1] >= 0 then -1
             else stFlag[1];

rec st = if IsNaN(st[1]) then if cciValue >= 0 then low - shift else high + shift
         else
            if cciValue > 0 and stFlag[1] <= 0 then low - shift
            else if cciValue < 0 and stFlag[1] >= 0 then high + shift
            else
                if stFlag > 0 and (low - shift) > st[1] then low - shift
                else if stFlag < 0 and (high + shift) < st[1] then high + shift
                else
                    if useFilter and stFlag > 0 and st[1] < st[1] and (close < open or high < high[1]) then st[1]
                    else if useFilter and stFlag < 0 and st[1] > st[1] and (close > open or low > low[1]) then st[1]
                    else st[1];

# -----------------------------
# signals
# -----------------------------
def notNaST = !IsNaN(st);
def upSignal = notNaST and close > st and close > ghlaLevel;
def downSignal = notNaST and close < st and close < ghlaLevel;
def neutralSignal = notNaST and !upSignal and !downSignal;

# -----------------------------
# Output (centered)
# -----------------------------
def signalCenter = 0;
plot Sig = signalCenter;
Sig.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Sig.SetLineWeight(4);

Sig.AssignValueColor(
    if upSignal then Color.GREEN
    else if downSignal then Color.RED
    else Color.LIGHT_GRAY
);

# Boundary reference lines
# -----------------------------
plot UpperLine = 1;
UpperLine.SetDefaultColor(Color.DARK_GRAY);
UpperLine.SetStyle(Curve.SHORT_DASH);

plot LowerLine = -1;
LowerLine.SetDefaultColor(Color.DARK_GRAY);
LowerLine.SetStyle(Curve.SHORT_DASH);

# Gann High/Low Activator Oscillator

input activatorPeriod = 14;

# Calculate simple moving averages
def avgHigh = Average(high, activatorPeriod);
def avgLow = Average(low, activatorPeriod);

# Determine state
def bullState = close > avgHigh;
def bearState = close < avgLow;

# Track the last valid state
def lastState = CompoundValue(1,
    if bullState then 1
    else if bearState then -1
    else lastState[1],
0);

def avgRange = avgHigh - avgLow;
def oscillator =
    if avgRange != 0 then
        if lastState == 1 then (close - avgLow) / avgRange
        else if lastState == -1 then (close - avgHigh) / avgRange
        else 0.5
    else 0.5;

# Plot oscillator
plot GannOsc = oscillator;
GannOsc.SetLineWeight(2);
GannOsc.AssignValueColor(
    if lastState == 1 then CreateColor(0, 255, 0) # Green
    else if lastState == -1 then CreateColor(255, 165, 0) # Orange
    else Color.GRAY
);

# Plot midline
plot MidLine = 0.5;
MidLine.SetDefaultColor(Color.LIGHT_GRAY);
MidLine.SetStyle(Curve.SHORT_DASH);
 
Last edited by a moderator:

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

GHLA SuperTrend CCI High-Low Activator Oscillator
A multi-layered trend and momentum indicator that combines Gann-inspired high/low levels, a SuperTrend mechanism, and a custom CCI oscillator. It provides dynamic entry and exit signals, confirming bullish or bearish trends while filtering out market noise. The accompanying oscillator visually represents trend strength and direction, allowing traders to quickly identify opportunities and avoid indecision zones.
Wow. Great job on this one! I tried to duplicate the SR-type lines for the upper. It works, yours is better. Would you add the code for that as well. Thanks again.
 
Very Cool, I love it, could you make Vertical lines on crossing for the upper? and do you have the link to the upper with labels?
 
Last edited:
Very Cool, I love it, could you make Vertical lines on crossing for the upper? and do you have the link to the upper with labels?
Hi ,do not know if this is what you expected but ,try this.

GHLA-supertrend-oscc.png

Code:
declare upper;
declare real_size;
input ghlaPeriod = 10;
input stPeriod = 14;
input stShiftTicks = 20.0;
input useFilter = yes;
input activatorPeriod = 14;

def minTick = TickSize();
def shift = stShiftTicks * minTick;

# -----------------------------
# GHLA Logic
# -----------------------------
def ghlaAvgH = Average(high, ghlaPeriod);
def ghlaAvgL = Average(low, ghlaPeriod);

def sw = if close > ghlaAvgH then 1
else if close < ghlaAvgL then -1
else 0;

def ghlaDir = CompoundValue(1, if sw != 0 then sw else ghlaDir[1], 0);
def ghlaLevel = if ghlaDir < 0 then ghlaAvgH else ghlaAvgL;

# -----------------------------
# Custom CCI using Typical Price
# -----------------------------
def tp = (high + low + close) / 3;
def tpSMA = Average(tp, stPeriod);
def meanDev = Average(AbsValue(tp - tpSMA), stPeriod);
def cciValue = if meanDev == 0 then 0 else (tp - tpSMA) / (0.015 * meanDev);

# -----------------------------
# SuperTrend State Machine
# -----------------------------
rec stFlag = if IsNaN(stFlag[1]) then if cciValue >= 0 then 1 else -1
else if cciValue > 0 and stFlag[1] <= 0 then 1
else if cciValue < 0 and stFlag[1] >= 0 then -1
else stFlag[1];

rec st = if IsNaN(st[1]) then if cciValue >= 0 then low - shift else high + shift
else
if cciValue > 0 and stFlag[1] <= 0 then low - shift
else if cciValue < 0 and stFlag[1] >= 0 then high + shift
else
if stFlag > 0 and (low - shift) > st[1] then low - shift
else if stFlag < 0 and (high + shift) < st[1] then high + shift
else
if useFilter and stFlag > 0 and st[1] < st[1] and (close < open or high < high[1]) then st[1]
else if useFilter and stFlag < 0 and st[1] > st[1] and (close > open or low > low[1]) then st[1]
else st[1];

# -----------------------------
# signals
# -----------------------------
def notNaST = !IsNaN(st);
def upSignal = notNaST and close > st and close > ghlaLevel;
def downSignal = notNaST and close < st and close < ghlaLevel;
def neutralSignal = notNaST and !upSignal and !downSignal;

# -----------------------------
# Output (centered)
# -----------------------------
def signalCenter = 0;
plot Sig = signalCenter;
Sig.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Sig.SetLineWeight(4);

Sig.AssignValueColor(
if upSignal then Color.GREEN
else if downSignal then Color.RED
else Color.LIGHT_GRAY
);

# Boundary reference lines
# -----------------------------
plot UpperLine = 1;
UpperLine.SetDefaultColor(Color.DARK_GRAY);
UpperLine.SetStyle(Curve.SHORT_DASH);

plot LowerLine = -1;
LowerLine.SetDefaultColor(Color.DARK_GRAY);
LowerLine.SetStyle(Curve.SHORT_DASH);

# Gann High/Low Activator Oscillator

# Calculate simple moving averages
def avgHigh = Average(high, activatorPeriod);
def avgLow = Average(low, activatorPeriod);

# Determine state
def bullState = close > avgHigh;
def bearState = close < avgLow;

# Track the last valid state
def lastState = CompoundValue(1,
if bullState then 1
else if bearState then -1
else lastState[1],
0);

def avgRange = avgHigh - avgLow;
def oscillator =
if avgRange != 0 then
if lastState == 1 then (close - avgLow) / avgRange
else if lastState == -1 then (close - avgHigh) / avgRange
else 0.5
else 0.5;

# Plot oscillator
plot GannOsc = oscillator;
GannOsc.SetLineWeight(2);
GannOsc.AssignValueColor(
if lastState == 1 then CreateColor(0, 255, 0) # Green
else if lastState == -1 then CreateColor(255, 165, 0) # Orange
else Color.GRAY
);

# Plot midline
plot MidLine = 0.5;
MidLine.SetDefaultColor(Color.LIGHT_GRAY);
MidLine.SetStyle(Curve.SHORT_DASH);

# -----------------------------
# Vertical lines on oscillator crosses
# -----------------------------

# Detect midline crosses
def crossAbove = oscillator crosses above MidLine;
def crossBelow = oscillator crosses below MidLine;

# Add vertical lines on crosses
AddVerticalLine(crossAbove, "", Color.CYAN, Curve.SHORT_DASH);
AddVerticalLine(crossBelow, "", Color.MAGENTA, Curve.SHORT_DASH);

# Optional: Add labels at top of chart for better visibility
#AddChartBubble(crossAbove, high, "Cross Above", Color.CYAN, yes);
#AddChartBubble(crossBelow, high, "Cross Below", Color.MAGENTA, yes);

Here
 
Last edited by a moderator:
@cando13579 , amazing setup you have created. thanks
trying to digest and found there's a typo in both codes above => "st[1] < st[1]" as it is a condition it won't ever work
 
@cando13579 , amazing setup you have created. thanks
trying to digest and found there's a typo in both codes above => "st[1] < st[1]" as it is a condition it won't ever work
First of all thanks, now let me try to explain that error was done intentionally just for reference , I mostly First create my indicators on pine and convert them to TOS and while doing so, I like the signals to match across platforms and on this case canceling that one part made it so.
TOS and TradingView handle bar indexing differently

TradingView’s [1], [2], historical referencing is very strict.
TOS sometimes shifts indexing slightly depending on aggregation or extended hours.
This can cause the “trend flips” to fire one bar earlier or later.
Hope this helps I can always fix that but it would stop matching the one on pine .and mostly trade using both platforms.
Thank you.
 
GHLA SuperTrend CCI High-Low Activator Oscillator
A multi-layered trend and momentum indicator that combines Gann-inspired high/low levels, a SuperTrend mechanism, and a custom CCI oscillator. It provides dynamic entry and exit signals, confirming bullish or bearish trends while filtering out market noise. The accompanying oscillator visually represents trend strength and direction, allowing traders to quickly identify opportunities and avoid indecision zones.
View attachment 26314
Code:
# GHLA_SuperTrend_CCI_High_Low_Activator_Oscillator
#By CANDO13579
 
declare lower;
declare real_size;
input ghlaPeriod = 10;
input stPeriod = 14;
input stShiftTicks = 20.0;
input useFilter = yes;

def minTick = TickSize();
def shift = stShiftTicks * minTick;

# -----------------------------
# GHLA Logic
# -----------------------------
def ghlaAvgH = Average(high, ghlaPeriod);
def ghlaAvgL = Average(low, ghlaPeriod);

def sw = if close > ghlaAvgH then 1
         else if close < ghlaAvgL then -1
         else 0;

def ghlaDir = CompoundValue(1, if sw != 0 then sw else ghlaDir[1], 0);
def ghlaLevel = if ghlaDir < 0 then ghlaAvgH else ghlaAvgL;

# -----------------------------
# Custom CCI using Typical Price
# -----------------------------
def tp = (high + low + close) / 3;
def tpSMA = Average(tp, stPeriod);
def meanDev = Average(AbsValue(tp - tpSMA), stPeriod);
def cciValue = if meanDev == 0 then 0 else (tp - tpSMA) / (0.015 * meanDev);

# -----------------------------
# SuperTrend State Machine
# -----------------------------

# stFlag: 1=long, -1=short
rec stFlag = if IsNaN(stFlag[1]) then if cciValue >= 0 then 1 else -1
             else if cciValue > 0 and stFlag[1] <= 0 then 1
             else if cciValue < 0 and stFlag[1] >= 0 then -1
             else stFlag[1];

rec st = if IsNaN(st[1]) then if cciValue >= 0 then low - shift else high + shift
         else
            if cciValue > 0 and stFlag[1] <= 0 then low - shift
            else if cciValue < 0 and stFlag[1] >= 0 then high + shift
            else
                if stFlag > 0 and (low - shift) > st[1] then low - shift
                else if stFlag < 0 and (high + shift) < st[1] then high + shift
                else
                    if useFilter and stFlag > 0 and st[1] < st[1] and (close < open or high < high[1]) then st[1]
                    else if useFilter and stFlag < 0 and st[1] > st[1] and (close > open or low > low[1]) then st[1]
                    else st[1];

# -----------------------------
# signals
# -----------------------------
def notNaST = !IsNaN(st);
def upSignal = notNaST and close > st and close > ghlaLevel;
def downSignal = notNaST and close < st and close < ghlaLevel;
def neutralSignal = notNaST and !upSignal and !downSignal;

# -----------------------------
# Output (centered)
# -----------------------------
def signalCenter = 0;
plot Sig = signalCenter;
Sig.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Sig.SetLineWeight(4);

Sig.AssignValueColor(
    if upSignal then Color.GREEN
    else if downSignal then Color.RED
    else Color.LIGHT_GRAY
);

# Boundary reference lines
# -----------------------------
plot UpperLine = 1;
UpperLine.SetDefaultColor(Color.DARK_GRAY);
UpperLine.SetStyle(Curve.SHORT_DASH);

plot LowerLine = -1;
LowerLine.SetDefaultColor(Color.DARK_GRAY);
LowerLine.SetStyle(Curve.SHORT_DASH);

# Gann High/Low Activator Oscillator

input activatorPeriod = 14;

# Calculate simple moving averages
def avgHigh = Average(high, activatorPeriod);
def avgLow = Average(low, activatorPeriod);

# Determine state
def bullState = close > avgHigh;
def bearState = close < avgLow;

# Track the last valid state
def lastState = CompoundValue(1,
    if bullState then 1
    else if bearState then -1
    else lastState[1],
0);

def avgRange = avgHigh - avgLow;
def oscillator =
    if avgRange != 0 then
        if lastState == 1 then (close - avgLow) / avgRange
        else if lastState == -1 then (close - avgHigh) / avgRange
        else 0.5
    else 0.5;

# Plot oscillator
plot GannOsc = oscillator;
GannOsc.SetLineWeight(2);
GannOsc.AssignValueColor(
    if lastState == 1 then CreateColor(0, 255, 0) # Green
    else if lastState == -1 then CreateColor(255, 165, 0) # Orange
    else Color.GRAY
);

# Plot midline
plot MidLine = 0.5;
MidLine.SetDefaultColor(Color.LIGHT_GRAY);
MidLine.SetStyle(Curve.SHORT_DASH);
Thanks for this indicator. Wondering what's the upper indicator in the screenshot?
 
Thanks for this indicator. Wondering what's the upper indicator in the screenshot?

Question: Why bother displaying this without the labels' data, as shown in the display photo. Please share the full labelled indicator for the traders who desire it ... Please
 
Last edited by a moderator:
First of all thanks, now let me try to explain that error was done intentionally just for reference , I mostly First create my indicators on pine and convert them to TOS and while doing so, I like the signals to match across platforms and on this case canceling that one part made it so.
TOS and TradingView handle bar indexing differently

TradingView’s [1], [2], historical referencing is very strict.
TOS sometimes shifts indexing slightly depending on aggregation or extended hours.
This can cause the “trend flips” to fire one bar earlier or later.
Hope this helps I can always fix that but it would stop matching the one on pine .and mostly trade using both platforms.
Thank you.
got that. thanks for the explanation. actually I was trying to convert it to tradingview, merging all 3 sections of your setup into one indicator as in tv it is possible to plot in lower pane simultaneously as in the price chart. tried to ask my AI assistance buddys for help but they made a few mistakes so I will try at a later future.
 
got that. thanks for the explanation. actually I was trying to convert it to tradingview, merging all 3 sections of your setup into one indicator as in tv it is possible to plot in lower pane simultaneously as in the price chart. tried to ask my AI assistance buddys for help but they made a few mistakes so I will try at a later future.
Hi ,care to explain what 3 sections, Are you referring to?.
 
Hi ,care to explain what 3 sections, Are you referring to?.
I intend to merge into a single indicator, in the lower pane GHLA and in the upper chart the vertical lines as well as the Perfect SuperTrend. that would provide a complete setup into a single indicator so it can be used even on the tv free version. As a reference I constructed a single indicator in tv merging 2 very interesting strategies from Dr Barbara Star that appeared in S&C magazine (check in tv for "Dr. Barbara Star: Dual Strategies Combined [Merged] - gemini")
 
I intend to merge into a single indicator, in the lower pane GHLA and in the upper chart the vertical lines as well as the Perfect SuperTrend. that would provide a complete setup into a single indicator so it can be used even on the tv free version. As a reference I constructed a single indicator in tv merging 2 very interesting strategies from Dr Barbara Star that appeared in S&C magazine (check in tv for "Dr. Barbara Star: Dual Strategies Combined [Merged] - gemini")
When I get some time , I will g8ve it i try ,not sure administration's would allow that to be shared here.?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
740 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