HLC Trend Identifier + Mom Squeeze V02 + Volatility Ocs

sam4cok

Member
Platform
  1. Thinkorswim
Wait for the squeeze, then HLC cross and increase in hist... or skip the squeeze, wait for the cross, Hist Up or Dn and add base line :)


ARkanlY.png


# Momentum Squeeze V02 by Mobius + "HLC Trend" + Volatility Osc
#https://www.tradingview.com/script/Zjk4UJF5-HLC-Trend-Identifier/
#https://www.tradingview.com/script/XL9nXxyY-Volatility-Oscillator/
# New faster Momentum Oscillator with outer band markers. New more accurate Squeeze indication.
# Mod & converted by Sam4COK @ 07/2022

declare lower;
def na = Double.NaN;
input n = 20;

def c = close;
def mean = Inertia(c, n);
def SD = Sqrt((fold i = 0 to n
with s
do s + Sqr(mean - GetValue(c, i))) / n);
plot Momo = Inertia((c - mean) / SD, Floor(n ));
Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0
then Color.CYAN
else if Momo > 0 and Momo < Momo[1]
then Color.BLUE
else if Momo < 0 and Momo < Momo[1]
then CreateColor(255, 0, 98)
else Color.ORANGE);
def upper = mean + (2 * SD);
def lower = mean - (2 * SD);
def W = (upper - lower) / mean;
def B = Highest(W, n * 2);
def Sq = Lowest(W, n * 2);
plot Squeeze = if ((W - Sq) / (B - Sq)) <= .01
then 0
else na;
Squeeze.SetStyle(Curve.POINTS);
Squeeze.SetLineWeight(3);
Squeeze.SetDefaultColor(Color.WHITE);
AddLabel(Squeeze, "Squeeze", Color.YELLOW);


#study("HLC Trend")

#// Inputs
input ShowHLC = yes;
input length_Close = 5; # "Close MA Period Length", type = integer)
input length_High = 30; # "High MA Period Length", type = integer)
input length_Low = 13; # "Low MA Period Length", type = integer)
input type_MA = {default SMA, EMA, WMA};
input fill_Cloud = yes; #"Use cloud coloring for Bull/Bear identification?", type = bool)
input fill_BG = no; # "Color Indicator background based on Bull/Bear/Neautral?", type = bool)
input TrendLebel = yes;

#// Pull traditional HLC
def sOpen = open;
def sHigh = high;
def sLow = low;
def sClose = close;

#// Calculations
def ma_High;
def ma_Low;
def ma_Close;
def ma_Open;
switch (type_MA) {
case SMA:
ma_High = SimpleMovingAvg(sHigh, length_High);
ma_Low = SimpleMovingAvg(sLow, length_Low);
ma_Close = SimpleMovingAvg(sClose, length_Close);
ma_Open = SimpleMovingAvg(sOpen, length_Close);
case EMA:
ma_High = ExpAverage(sHigh, length_High);
ma_Low = ExpAverage(sLow, length_Low);
ma_Close = ExpAverage(sClose, length_Close);
ma_Open = ExpAverage(sOpen, length_Close);
case WMA:
ma_High = WMA(sHigh, length_High);
ma_Low = WMA(sLow, length_Low);
ma_Close = WMA(sClose, length_Close);
ma_Open = WMA(sOpen, length_Close);
}
def ma_CH = ma_Close - ma_High;
def ma_LC = ma_Low - ma_Close;

#// Draw Colors
def fill_Color = if ma_CH > ma_LC then 1 else 0;
def bg_Color = if ma_CH >= ma_LC then if (ma_CH < 0 and ma_CH < ma_CH[1]) then 0 else 1
else if (ma_LC < 0 and ma_LC < ma_LC[1]) then 0 else -1;
## Volatility Osc

def spike = ma_Close - ma_Open; #"Spike Linel"

def x = StDev(spike, length_Close);
def y = StDev(spike, length_Close) * -1;

plot VolaLine = 0;
VolaLine.AssignValueColor(if spike > x then Color.GREEN else
if spike < y then Color.RED else Color.GRAY);
VolaLine.SetLineWeight(2);
#// Draw Out

plot plot_CH = if ShowHLC then ma_CH else na; # "MA Close - MA High"
plot_CH.SetDefaultColor(Color.GREEN);

plot plot_LC = if ShowHLC then ma_LC else na; # "MA Low - MA Close"
plot_LC.SetDefaultColor(Color.RED);

def Trend = if bg_Color > 0 and Momo > 0 and spike > x then 1 else
if bg_Color < 0 and Momo < 0 and spike < y then -1 else na;

AddLabel (if TrendLebel and Trend then yes else na , "Trend", if Trend > 0 then Color.GREEN else
if Trend < 0 then Color.RED else Color.GRAY);

AddCloud (if ShowHLC and fill_BG and bg_Color > 0 then Double.POSITIVE_INFINITY else na, Double.NEGATIVE_INFINITY, Color.GREEN);
AddCloud (if ShowHLC and fill_BG and bg_Color == 0 then Double.POSITIVE_INFINITY else na, Double.NEGATIVE_INFINITY, CreateColor(255, 255, 0));
AddCloud (if ShowHLC and fill_BG and bg_Color < 0 then Double.POSITIVE_INFINITY else na, Double.NEGATIVE_INFINITY, Color.RED);

AddCloud (if ShowHLC and fill_Cloud then ma_CH else na, ma_LC , Color.DARK_GREEN, Color.DARK_RED, no);
AddCloud (if ShowHLC and fill_Cloud then ma_CH else na, ma_LC , Color.DARK_GREEN, Color.DARK_RED, no);

#// END Cloud fill selector
 
Top