Multiple Time Frame (MTF) Squeeze Indicator for ThinkorSwim

hello - I found this script on the thread and was wondering if someone can help to add UP or DOWN Arrow based on the direction where SQUEEZE is fired
+ after adding ARROWs Is it possible to convert the script to Scan for BUY/SELL signal.
appreciate any help
thanks.. RG


Code:
#===== CODE FOR SQUEEZE ===

declare lower;

input price = close;
input Length = 20.0;
input nBB = 2.0;
input nK_High = 1.0;
input nK_Mid = 1.5;
input nK_Low = 2.0;


def momentum = TTM_Squeeze(price = price, length = length, nk = nk_Mid, nbb = nbb).”Histogram”;
plot oscillator = momentum;
def BolKelDelta_Mid = reference BollingerBands(“num_dev_up” = nBB, “length” = Length ).”upperband” – KeltnerChannels(“factor” = nK_Mid, “length” = Length).”Upper_Band”;
def BolKelDelta_Low = reference BollingerBands(“num_dev_up” = nBB, “length” = Length ).”upperband” – KeltnerChannels(“factor” = nK_Low, “length” = Length).”Upper_Band”;
def BolKelDelta_High = reference BollingerBands(“num_dev_up” = nBB, “length” = Length ).”upperband” – KeltnerChannels(“factor” = nK_High, “length” = Length).”Upper_Band”;
oscillator.DefineColor(“Up”, CreateColor(0, 255, 255));
oscillator.DefineColor(“UpDecreasing”, CreateColor(0, 0, 255));
oscillator.DefineColor(“Down”, CreateColor(255, 0, 0));
oscillator.DefineColor(“DownDecreasing”, CreateColor(255, 255, 0));
oscillator.AssignValueColor(
if oscillator[1] < oscillator then if oscillator[0] >= 0
then oscillator.Color(“Up”)
else oscillator.Color(“DownDecreasing”)
else if oscillator >= 0
then oscillator.Color(“UpDecreasing”)
else oscillator.Color(“Down”) );
oscillator.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
oscillator.SetLineWeight(5);

plot squeeze = If(IsNaN(close), Double.NaN, 0);

squeeze.DefineColor(“NoSqueeze”, Color.GREEN);
squeeze.DefineColor(“SqueezeLow”, Color.black);
squeeze.DefineColor(“SqueezeMid”, Color.RED);
squeeze.DefineColor(“SqueezeHigh”, Color.orange);
squeeze.AssignValueColor(if BolKelDelta_High <= 0 then squeeze.Color(“SqueezeHigh”) else if BolKelDelta_Mid <= 0 then squeeze.Color(“SqueezeMid”) else if BolKelDelta_Low <= 0 then squeeze.Color(“SqueezeLow”) else squeeze.color(“noSqueeze”));
squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
squeeze.SetLineWeight(3);
 
Works great.

@laketrader @noobstocktrader101 Hello. Is there a way where the script can be written so that the script automatically changes timeframes with the chart timeframes? Therefore I don't have to change the chart timeframe then go into the script and match the script timeframe with the chart timeframe?

Thanks!!

@rgstock2 I love this and I am struggling to add the vertical fire portion from Mobius which would be helpful (or the missing piece IMO). Could someone assist with what might be incorrect?

Code:
#===== CODE FOR SQUEEZE ===

declare lower;

input price = close;
input Length = 20.0;
input nBB = 2.0;
input nK_High = 1.0;
input nK_Mid = 1.5;
input nK_Low = 2.0;


def momentum = TTM_Squeeze(price = price, length = length, nk = nk_Mid, nbb = nbb).”Histogram”;
plot oscillator = momentum;
def BolKelDelta_Mid = reference BollingerBands(“num_dev_up” = nBB, “length” = Length ).”upperband” – KeltnerChannels(“factor” = nK_Mid, “length” = Length).”Upper_Band”;
def BolKelDelta_Low = reference BollingerBands(“num_dev_up” = nBB, “length” = Length ).”upperband” – KeltnerChannels(“factor” = nK_Low, “length” = Length).”Upper_Band”;
def BolKelDelta_High = reference BollingerBands(“num_dev_up” = nBB, “length” = Length ).”upperband” – KeltnerChannels(“factor” = nK_High, “length” = Length).”Upper_Band”;
oscillator.DefineColor(“Up”, CreateColor(0, 255, 255));
oscillator.DefineColor(“UpDecreasing”, CreateColor(0, 0, 255));
oscillator.DefineColor(“Down”, CreateColor(255, 0, 0));
oscillator.DefineColor(“DownDecreasing”, CreateColor(255, 255, 0));
oscillator.AssignValueColor(
if oscillator[1] < oscillator then if oscillator[0] >= 0
then oscillator.Color(“Up”)
else oscillator.Color(“DownDecreasing”)
else if oscillator >= 0
then oscillator.Color(“UpDecreasing”)
else oscillator.Color(“Down”) );
oscillator.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
oscillator.SetLineWeight(5);

plot squeeze = If(IsNaN(close), Double.NaN, 0);

squeeze.DefineColor(“NoSqueeze”, Color.GREEN);
squeeze.DefineColor(“SqueezeLow”, Color.black);
squeeze.DefineColor(“SqueezeMid”, Color.RED);
squeeze.DefineColor(“SqueezeHigh”, Color.orange);
squeeze.AssignValueColor(if BolKelDelta_High <= 0 then squeeze.Color(“SqueezeHigh”) else if BolKelDelta_Mid <= 0 then squeeze.Color(“SqueezeMid”) else if BolKelDelta_Low <= 0 then squeeze.Color(“SqueezeLow”) else squeeze.color(“noSqueeze”));
squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
squeeze.SetLineWeight(3);


##NEW CODE ADDED
plot zero = if IsNaN(close) or !IsNaN(squeeze) then Double.NaN else 0;
zero.SetPaintingStrategy(PaintingStrategy.POINTS);
zero.SetLineWeight(3);
zero.SetDefaultColor(Color.GREEN);

def K = (Highest(high, Length)+ Lowest(low, Length))/2+ExpAverage(close,Length);
plot Momo = Inertia(price - K/2,Length);

AddLabel(!IsNaN(squeeze), "Squeeze", if IsAscending(Momo)
then Color.GREEN
else Color.RED);
# 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 = 100;

def CN = Average(close, n);
def VN = Average(volume, n);
def G = close > CN and volume > VN ;
def B = close > CN and volume == VN;
def O = close < CN and volume == VN;
def R = close < CN and volume >= 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.ORANGE); #Strong Bear

#How to use:
#Buy on Green or Blue
#Sell on Yellow or Orange

#End
 
Last edited:
Not sure if this is what you're looking for.

Code:
# 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
else if Momo < 0 and Momo < Momo[1]
then Color.Red
else Color.ORANGE);
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);
AddLabel(!IsNaN(Squeeze), "Squeeze", if IsAscending(Momo)
then Color.GREEN
else Color.RED);
# 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.ORANGE); #Strong Bear

#How to use:
#Buy on Green or Blue
#Sell on Yellow or Orange

#End
 
Or maybe this

Code:
# 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 length = 20;
def price = close(period = AGG);
input SDmult = 2.0;
input ATRmult = 1.5;

def K = (Highest(high("Period" = AGG), length) + Lowest(low("Period" = AGG), length) + ExpAverage(price, length)) / 3;
plot Momo = Inertia(close - K, length);
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.ORANGE
else if Momo < 0 and Momo < Momo[1]
then Color.Red
else Color.Yellow);
def SD = StDev(close(period = AGG), length);
def Avg = Average(close(period = AGG), length);
def ATR = Average(TrueRange(high(period = AGG), close(period = AGG), low(period = AGG)), length);
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);
AddLabel(!IsNaN(Squeeze), "Squeeze", if IsAscending(Momo)
then Color.GREEN
else Color.RED);
# 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.ORANGE); #Strong Bear

#How to use:
#Buy on Green or Blue
#Sell on Yellow or Orange

#End
 
Well I wanted to modify the squeeze code I had to include vertical lines that fire but I can't figure why it's not firing correctly. I had bolded the area that adds the vertical line but it's not firing. In the codes you've shared, the vertical Fire lines display, I was trying to replicate it for the code I pasted.

@Pelonsax - is there any way to make this dynamic to change in overall timeframe (e.g. vs manual input of changing time frame by modifying study).

All I was able to figure it out.. we can ignore this. If anyone was interested, happy to share.
 
Last edited by a moderator:
Well I wanted to modify the squeeze code I had to include vertical lines that fire but I can't figure why it's not firing correctly. I had bolded the area that adds the vertical line but it's not firing. In the codes you've shared, the vertical Fire lines display, I was trying to replicate it for the code I pasted.

@Pelonsax - is there any way to make this dynamic to change in overall timeframe (e.g. vs manual input of changing time frame by modifying study).

All I was able to figure it out.. we can ignore this. If anyone was interested, happy to share.
@ampersand do you mind sharing the code?
 
Sure. I just added the variable to call the addvertical line into the Squeeze code along with some of the labels into this.

Code:
#===== CODE FOR SQUEEZE ===

declare lower;

input price = close;
input Length = 20.0;
input nBB = 2.0;
input nK_High = 1.0;
input nK_Mid = 1.5;
input nK_Low = 2.0;


def momentum = TTM_Squeeze(price = price, length = length, nk = nk_Mid, nbb = nbb).”Histogram”;
plot oscillator = momentum;
def BolKelDelta_Mid = reference BollingerBands(“num_dev_up” = nBB, “length” = Length ).”upperband” – KeltnerChannels(“factor” = nK_Mid, “length” = Length).”Upper_Band”;
def BolKelDelta_Low = reference BollingerBands(“num_dev_up” = nBB, “length” = Length ).”upperband” – KeltnerChannels(“factor” = nK_Low, “length” = Length).”Upper_Band”;
def BolKelDelta_High = reference BollingerBands(“num_dev_up” = nBB, “length” = Length ).”upperband” – KeltnerChannels(“factor” = nK_High, “length” = Length).”Upper_Band”;
oscillator.DefineColor(“Up”, CreateColor(0, 255, 255));
oscillator.DefineColor(“UpDecreasing”, CreateColor(0, 0, 255));
oscillator.DefineColor(“Down”, CreateColor(255, 0, 0));
oscillator.DefineColor(“DownDecreasing”, CreateColor(255, 255, 0));
oscillator.AssignValueColor(
if oscillator[1] < oscillator then if oscillator[0] >= 0
then oscillator.Color(“Up”)
else oscillator.Color(“DownDecreasing”)
else if oscillator >= 0
then oscillator.Color(“UpDecreasing”)
else oscillator.Color(“Down”) );
oscillator.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
oscillator.SetLineWeight(5);

plot squeeze = If(IsNaN(close), Double.NaN, 0);

squeeze.DefineColor(“NoSqueeze”, Color.GREEN);
squeeze.DefineColor(“SqueezeLow”, Color.black);
squeeze.DefineColor(“SqueezeMid”, Color.RED);
squeeze.DefineColor(“SqueezeHigh”, Color.orange);
squeeze.AssignValueColor(if BolKelDelta_High <= 0 then squeeze.Color(“SqueezeHigh”) else if BolKelDelta_Mid <= 0 then squeeze.Color(“SqueezeMid”) else if BolKelDelta_Low <= 0 then squeeze.Color(“SqueezeLow”) else squeeze.color(“noSqueeze”));
squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
squeeze.SetLineWeight(3);


##NEW CODE ADDED
plot zero = if IsNaN(close) or !IsNaN(squeeze) then Double.NaN else 0;
zero.SetPaintingStrategy(PaintingStrategy.POINTS);
zero.SetLineWeight(3);
zero.SetDefaultColor(Color.GREEN);

AddLabel(!IsNaN(squeeze), "Squeeze", if IsAscending(oscillator)
then Color.GREEN
else Color.RED);
# End Code - Momentum Squeeze
#Adding lines for fire - custom
def SD = STDev(price, length);
def Avg = Average(price, length);
def ATR = Average(TrueRange(high,close,low), length);
def sDup = Avg + (nBB * SD);
def ATrup = Avg + (nk_mid * ATR);

plot testfire = if sDup < ATRup then 0 else Double.NaN;

AddVerticalLine(!IsNaN(testfire[1]) and IsNaN(testfire), "Fired", Color.RED, Curve.FIRM);
#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, n);
def VN = Average(volume, n);
def G = close > CN and volume > VN ;
def B = close > CN and volume == VN;
def O = close < CN and volume == VN;
def R = close < CN and volume >= 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.ORANGE); #Strong Bear

#How to use:
#Buy on Green or Blue
#Sell on Yellow or Orange

#End
 
Here's a version of it I just cooked up for the price window. It colors candles according to the scheme in the histogram and displays a label for when there is a squeeze as well as the vertical line and an alert for when it fires. Enjoy!

https://tos.mx/gwkWMDV

Code:
# MTF and candle paint mod: PELONSAX
# 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
#12/10/20 MOD by PELONSAX CANDLE PAINT
declare upper;

input AGG = AggregationPeriod.FIVE_MIN;
input ALERT = yes;
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);

def Momo = Inertia(close - K/2, Klength);

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);


def Squeeze = if SDup < ATRup
then 0
else Double.NaN;

addlabel(!IsNan(Squeeze), "SQUEEZE", color.red);



# End Code - Momentum Squeeze

AddVerticalLine(!IsNaN(squeeze[1]) and IsNaN(squeeze), "Fired", Color.RED, Curve.FIRM);


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);

Alert((ALERT) and (!IsNaN(squeeze[1]) and IsNaN(squeeze)), "Fired", Alert.BAR, Sound.Bell);

9v5RQcE.png
 
@Pelonsax This is great - is there anyway to modify it so that it follows the selected time frame vs having to manually update it? I notice this is set for FIVE MIN - which means unless the chart timeframe is not set to 5 min, it would not display correctly. Can this be dynamic?
 
This is something I have been playing with @Pelonsax has some code in here somewhere and I need help Identifying it. I only tinker and try to remix stuff. I have no intention of taking credit for anything.

I am having a problem with this script. The histogram only shows up on large volume futures etc and not smaller stocks, could one of you guys have a look and see if you can fix this. It would be a good indicator if that was fixed. This is just something I am trying to do to learn coding....making small steps. I need to get better at documenting, I have forgotten where some of the snippets come from as they have all gotten mixed up lol!!

Code:
# 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));
 
@dmillz If your current chart's timeframe is higher than one of the timeframes in your indicator, it will not work.
 

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
500 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