# Momentum Squeeze and Volume Mod 08.17.18
# Mobius
# Added Squeeze Label with directional color
# Label is green when momentum is ascending, red when descending
# Added UI for separate Squeeze and Oscillator lenghts
# This code precisely replicates TTM_Squeeze. At default settings
# the output is the same as TTM_Squeeze. Top is Momentum squeeze
# study and bottom is TTM_Squeeze. The Oscillator can be adjusted
# separately with this version. I prefer the oscillator at 13, as
# it makes it more timely
#
# Squeeze was originated by John Bollinger and the Momentum Oscillator
# has been around long before Carter's version. He just painted it
# those colors.
#
# Some years ago we ran some statistics on squeeze breakouts and
# it was right around 50/50 with some variance with price near high
# volume pivots being a bit more easily read.
#
# If there was a high volume pivot within 3 or 4 bars of a low and
# then a squeeze, the probability of an expansion in price upward was
# nearer 1 st dev. If there was a low volume high pivot near a squeeze
# the probability was for a downward expansion of price.
#
# Squeeze in those cases denotes the indecision (price compression)
# before a trend change. The same price compression is what the
# SuperTrend code picks up on
# Modified by blt, 7.26.2016
# Bars painted GRAY if we are in a squeeze, BLUE if we are long and
# ORANGE if we are short. Also added addverticalline when squeeze fires
declare lower;
input AGG = AggregationPeriod.FIVE_MIN;
input Slength = 20; #hint Slength: Length for Squeeze
input Klength = 20; #hint Klength: Length for Oscillator
def price = close(period = AGG);
input SDmult = 2.0;
input ATRmult = 1.5;
def K = (Highest(high(period = AGG), Klength) + Lowest(low(period = AGG), Klength)) /
2 + ExpAverage(close(period = AGG), Klength);
plot Momo = Inertia(close - K/2, Klength);
Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Momo.SetLineWeight(3);
Momo.assignValueColor(if Momo > Momo[1] and Momo > 0
then Color.CYAN
else if Momo > 0 and Momo < Momo[1]
then Color.BLUE #ORANGE
else if Momo < 0 and Momo < Momo[1]
then Color.RED
else Color.YELLOW);
def SD = StDev(close(period = AGG), Slength);
def Avg = Average(close(period = AGG), Slength);
def ATR = Average(TrueRange(high(period = AGG), close(period = AGG), low(period = AGG)), Slength);
def SDup = Avg + (SDmult * SD);
def ATRup = Avg + (ATRmult * ATR);
plot Squeeze = if SDup < ATRup
then 0
else Double.NaN;
Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
Squeeze.SetLineWeight(3);
Squeeze.SetDefaultColor(Color.RED);
plot zero = if IsNaN(close(period = AGG)) or !IsNaN(Squeeze) then Double.NaN else 0;
zero.SetPaintingStrategy(PaintingStrategy.POINTS);
zero.SetLineWeight(3);
zero.SetDefaultColor(Color.GREEN);
# End Code - Momentum Squeeze
AddVerticalLine(!IsNaN(squeeze[1]) and IsNaN(squeeze), "Fired", Color.RED, Curve.FIRM);
#ADDED Volume###################################################################
#Colored Volume By Ethans080901
#Mod TroyX-8-17-18
#If today's closing price and volume is greater than 'n' days ago, color green
#If today's closing price is greater than 'n' days ago but volume is not, color blue
#If today's closing price is less than 'n' days ago, color orange
#If today's closing price is less than 'n' days ago but volume is not, color red
input n = 10;
def CN = Average(close(period = AGG), n);
def VN = Average(volume(period = AGG), n);
def G = close(period = AGG) > CN and volume(period = AGG) > VN ;
def B = close(period = AGG) > CN and volume(period = AGG) == VN;
def O = close(period = AGG) < CN and volume(period = AGG) == VN;
def R = close(period = AGG) < CN and volume(period = AGG) >= VN;
#Added volume Label
AddLabel( G, "BULLISH VOLUME" , Color.CYAN); #Strong Bull
AddLabel( B, "BULLISH VOLUME" , Color.BLUE); #Weak Bull
AddLabel( O, "BEARISH VOLUME" , Color.YELLOW); #Weak Bear
AddLabel( R, "BEARISH VOLUME" , Color.RED); #Strong Bear
#How to use:
#Buy on Green or Blue
#Sell on Yellow or Red
#End
#KIP_ADDED TMO###################################################################
#TMO SORCE UNKNOWN, CUSTOM TWEEKED TO MY PREFERANCE
#Mod KIP-12-13-20
input length = 14;
input calcLength = 10;
input smoothLength = 9;
def c = close;
def data = fold i = 1 to length
with s
do s + (if c > getValue(c, i)
then 1
else if c < getValue(c, i)
then - 1
else 0);
def normData = data * 400 / length;
def EMA5 = ExpAverage(normData, calcLength);
plot Main = ExpAverage(EMA5, smoothLength);
plot Signal = ExpAverage(Main, smoothLength);
Main.AssignValueColor(if Main > Signal
then color.green
else color.red);
Signal.AssignValueColor(if Main > Signal
then color.green
else color.red);
Signal.HideBubble();
Signal.HideTitle();
# End Code TMO
# Modified by blt, 7.26.2016
# Bars painted GRAY if we are in a squeeze, BLUE if we are long and
# ORANGE if we are short. Also added addverticalline when squeeze fires
#12/10/20 MOD by PELONSAX CANDLE PAINT
addlabel(!IsNan(Squeeze), "SQUEEZE", color.red);
# End Code - Momentum Squeeze
AssignPriceColor(
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 Color.Red
else Color.ORANGE);
input averageType = AverageType.WILDERS;
input ADX_line = 25; #HINT ADX_line: This creates a horizontal line on the study. \n\nEdit as desired: \n 0-20 ADX indicates chop or no trend\n 20-25 watch for signs new trend might be starting\n over 25 = trending\n 25-50 strong trend\n over 50 watch for signs trend might be at risk of ending
input Show_Signal_lines_for_DMI_Cross = yes; #HINT Show_Signal_lines_for_DMI_Cross: if yes, will plot vertical lines at points where DI+ and DI- cross if ADX is also > 20 at time of cross
input Sound_AudibleAlert_for_DMI_Cross = yes; #HINT Sound_AudibleAlert_for_DMI_Cross: if yes, will sound an audible alert and post to Messages center when DI+ and DI- cross if ADX is also > 20 at time of cross
# def allows you to create or define new "words" for ThinkScript to save time and typing by using the new "words" later in the code
# plot tells ThinkScript what information you want visible, and the following lines for each plot tell ThinkScript how you want that information displayed (color, line weight, etc.). Plot also creates ability in the Edit Studies box to check or un-check "show plot"
def hiDiff = high - high[1];
def loDiff = low[1] - low;
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
plot "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, length);
plot ADXline = ADX_line;
"DI+".SetDefaultColor(color.GREEN);
"DI+".SetLineWeight(2);
"DI-".SetDefaultColor(color.RED);
"DI-".SetLineWeight(2);
ADX.SetDefaultColor(color.LIGHT_GRAY);
ADX.SetLineWeight(1);
ADXline.SetDefaultColor(color.ORANGE);
ADXline.SetLineWeight(2);
# AddLabel can be used with plot or instead of plot by telling ThinkScript what information you want displayed on the chart and how you want that information displayed.
# AddLabel requires 3 components: (condition for label to appear or YES if always want label visible, what words and/or information you want visible in the label, and what color or color coding you want for the label)
# NOTE: ThinkScript can use if-then statements, but must always end with an "else". For example, if___ then___ else if___ then___ else if___ then else ____ .
AddLabel(ADX > 25, if "DI+" > "DI-" then "ADX > 25 OR TRENDING / UP TREND" else "ADX > 25 OR TRENDING / DOWN TREND", if "DI+" > "DI-" then color.GREEN else color.RED);
AddLabel(ADX < 20, "ADX < 20 OR NO TREND", color.GRAY);
AddLabel(ADX >= 20 and ADX <=25, if "DI+" > "DI-" then "ADX = " + round(ADX, 2) + " " + "... NEW UP TREND FORMING?" else "ADX = " + round(ADX, 2) + " " + "... NEW DOWN TREND FORMING?", if "DI+" > "DI-" then color.GREEN else if "DI+" < "DI-" then color.RED else color.LIGHT_GRAY);
# below this line is the code for audible alert with arrows when DMI crosses occurs when ADX is greater than 20
def BullishAlertLines = if Show_Signal_lines_for_DMI_Cross == yes then "DI+" crosses above "DI-" and ADX > 20 else no;
AddVerticalLine(BullishAlertLines, "Bullish DMI cross ADX > 20", Color.DARK_GREEN, curve.SHORT_DASH);def BullishAlertSound = if Sound_AudibleAlert_for_DMI_Cross == yes then "DI+" crosses above "DI-" and ADX > 20 else no;
Alert(BullishAlertSound, "Bullish DMI cross ADX > 20", Alert.BAR, Sound.Chimes);
def BearishAlertLines = if Show_Signal_lines_for_DMI_Cross == yes then "DI+" crosses below "DI-" and ADX > 20 else no;
AddVerticalLine(BearishAlertLines, "Bearish DMI cross ADX > 20", Color.DARK_RED, curve.SHORT_DASH);
def BearishAlertSound = if Sound_AudibleAlert_for_DMI_Cross == yes then "DI+" crosses below "DI-" and ADX > 20 else no;
Alert(BearishAlertSound, "Bearish DMI cross ADX > 20", Alert.BAR, Sound.Bell);
# KIP_ADDED VOLUME###################################################################
# %VOLUME STUDY, SOURCE UNKNOWN
#Mod KIP-12-13-20
#Inputs
input ShowSellVolumePercent = yes;
def H = high;
def L = low;
def V = volume;
def buying = V * (C - L) / (H - L);
def selling = V * (H - C) / (H - L);
#Volume Data
def today = volume(period = "DAY");
def curVolume = volume;
def SellVolPercent = Round((selling / volume) * 100, 0);
# Labels
AddLabel(ShowSellVolumePercent, "CURRENT BAR SELL %: " + SellVolPercent, (if SellVolPercent > 51 then Color.RED else if SellVolPercent < 49 then Color.GREEN else Color.WHITE));