# Line At Price
# Mobius
# Alternative to using the HighestAll() function
# Modified by rad14733 for personal use
input barsBack = 300;
def c = if !IsNaN(close) and IsNaN(close[-1]) then close else c[1];
plot line = if isNaN(close[-barsBack]) then c[-barsBack] else Double.NaN;
line.DefineColor("Up", Color.WHITE);
line.DefineColor("Dn", Color.GRAY);
line.DefineColor("Default", Color.CYAN);
line.SetLineWeight(3);
line.SetDefaultColor(line.Color("Default"));
line.AssignValueColor(if close > open then line.Color("Up") else line.Color("Dn"));
line.SetPaintingStrategy(PaintingStrategy.DASHES);
line.SetStyle(Curve.MEDIUM_DASH);
# END -...
# Line At Price
# Mobius
# Alternative to using the HighestAll() function
# Modified by rad14733 for personal use
input barsBack = 300;
def c = if !IsNaN(close) and IsNaN(close[-1]) then close else c[1];
plot line = if isNaN(close[-barsBack]) then c[-barsBack] else Double.NaN;
line.DefineColor("Up", Color.WHITE);
line.DefineColor("Dn", Color.GRAY);
line.DefineColor("Default", Color.CYAN);
line.SetLineWeight(3);
line.SetDefaultColor(line.Color("Default"));
line.AssignValueColor(if close > open then line.Color("Up") else line.Color("Dn"));
line.SetPaintingStrategy(PaintingStrategy.DASHES);
line.SetStyle(Curve.MEDIUM_DASH);
# END - Line_At_Price
# Current_PriceLine
# Plots a Horizontal Line that follows the price value selected
# https://futures.io/thinkorswim/25517-horisontal-price-line-tos-thinkorswim-trading-platform.html#post296001
input price=close;
input offset=0;
input length = 300;
def sma = SimpleMovingAvg(price, 1, length);
rec line = if IsNaN(sma) then line[1] else sma[offset];
plot priceline=if isnan(sma) then line else double.nan;
priceline.setpaintingStrategy(paintingStrategy.LINE);
priceline.setlineWeight(3);
priceline.setdefaultColor(color.LIME);
priceline.hideBubble();
# TTM_Squeeze_PriceLine
# Paints a horizontal price line with TTM_Squeeze indication
# Coded by rad14733 for usethinkscript.com
# v1.0 : 2021-01-10 : Original Code
# v1.1 : 2021-01-14 : Made user configurable by adding inputs
# v1.2 : 2021-01-19 : Modified code so when BB & KC bands are equal it is considered a squeeze
# Use reference calls to TOS BB's and plot midline and bands
input bbprice = close;
input displace = 0;
input length = 20;
input numdevdn = -2.0;
input numdevup = 2.0;
input averagetype = AverageType.SIMPLE;
input showVerticalLines = yes;
def bb_midline = BollingerBands(bbprice, displace, length, numdevdn, numdevup, averagetype).MidLine;
def bb_upperband = BollingerBands(bbprice, displace, length, numdevdn, numdevup, averagetype).UpperBand;
def bb_lowerband = BollingerBands(bbprice, displace, length, numdevdn, numdevup, averagetype).LowerBand;
# Use reference calls to TOS KC's and plot midline and bands
input kcdisplace = 0;
input kcfactor = 1.5;
input kclength = 20;
input kcprice = close;
input kcaverageType = AverageType.SIMPLE;
input kctrueRangeAverageType = AverageType.SIMPLE;
def kc_midline = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaveragetype, kctruerangeaveragetype).Avg;
def kc_upperband = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaveragetype, kctruerangeaveragetype).Upper_Band;
def kc_lowerband = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaveragetype, kctruerangeaveragetype).Lower_Band;
# When the BB upper and lower bands cross inside the KC's we are in a Squeeze
def squeezed = if bb_upperband <= kc_upperband and bb_lowerband >= kc_lowerband then 1 else if bb_upperband >= kc_upperband and bb_lowerband <= kc_lowerband then -1 else 0;
#def squeezed = if bb_upperband crosses below kc_upperband and bb_lowerband crosses above kc_lowerband then 1 else if bb_upperband crosses above kc_upperband and bb_lowerband crosses below kc_lowerband then -1 else 0;
AddVerticalLine(showVerticalLines and bb_upperband crosses below kc_upperband and bb_lowerband crosses above kc_lowerband, "Squeeze On", Color.RED);
AddVerticalLine(showVerticalLines and bb_upperband crosses above kc_upperband and bb_lowerband crosses below kc_lowerband, "Squeeze Off", Color.GREEN);
#Plot the current price across an entire chart
#Also helps determine when price is approaching support and resistance
#Color coded to indicate TTM_Squeeze zones
input price = close;
input barsBack = 300;
def c = if !IsNaN(close) and IsNaN(close[-1]) then close else c[1];
plot priceline = if isNaN(close[-barsBack]) then c[-barsBack] else Double.NaN;
#plot priceLine = HighestAll(if !IsNaN(price) and IsNaN(price[-1]) then price else Double.NaN);
priceLine.DefineColor("squeezed", Color.RED);
priceLine.DefineColor("unsqueezed", Color.GREEN);
#priceLine.AssignValueColor(if squeezed == 1 then priceLine.Color("squeezed") else if squeezed == -1 then priceLine.Color("unsqueezed") else if squeezed == 0 then priceLine.Color("squeezed") else Color.CURRENT);
priceLine.AssignValueColor(if squeezed == 1 then priceLine.Color("squeezed") else priceLine.Color("unsqueezed"));
priceLine.SetPaintingStrategy(PaintingStrategy.DASHES);
priceline.SetStyle(Curve.FIRM);
priceLine.SetLineWeight(2);
#plot sq = squeezed;
# END - TTM_Squeeze_PriceLine
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thank you so very much! The first one appears to be working. I look forward to watching it react during regular trading hours. This was my first question on the site and I really appreciate the reply and help.@DJones There are several price line scripts out there... Here are a couple that I use...
Ruby:# Line At Price # Mobius # Alternative to using the HighestAll() function # Modified by rad14733 for personal use input barsBack = 300; def c = if !IsNaN(close) and IsNaN(close[-1]) then close else c[1]; plot line = if isNaN(close[-barsBack]) then c[-barsBack] else Double.NaN; line.DefineColor("Up", Color.WHITE); line.DefineColor("Dn", Color.GRAY); line.DefineColor("Default", Color.CYAN); line.SetLineWeight(3); line.SetDefaultColor(line.Color("Default")); line.AssignValueColor(if close > open then line.Color("Up") else line.Color("Dn")); line.SetPaintingStrategy(PaintingStrategy.DASHES); line.SetStyle(Curve.MEDIUM_DASH); # END - Line_At_Price
View attachment 25684
Ruby:# Current_PriceLine # Plots a Horizontal Line that follows the price value selected # https://futures.io/thinkorswim/25517-horisontal-price-line-tos-thinkorswim-trading-platform.html#post296001 input price=close; input offset=0; input length = 300; def sma = SimpleMovingAvg(price, 1, length); rec line = if IsNaN(sma) then line[1] else sma[offset]; plot priceline=if isnan(sma) then line else double.nan; priceline.setpaintingStrategy(paintingStrategy.LINE); priceline.setlineWeight(3); priceline.setdefaultColor(color.LIME); priceline.hideBubble();
View attachment 25685
Ruby:# TTM_Squeeze_PriceLine # Paints a horizontal price line with TTM_Squeeze indication # Coded by rad14733 for usethinkscript.com # v1.0 : 2021-01-10 : Original Code # v1.1 : 2021-01-14 : Made user configurable by adding inputs # v1.2 : 2021-01-19 : Modified code so when BB & KC bands are equal it is considered a squeeze # Use reference calls to TOS BB's and plot midline and bands input bbprice = close; input displace = 0; input length = 20; input numdevdn = -2.0; input numdevup = 2.0; input averagetype = AverageType.SIMPLE; input showVerticalLines = yes; def bb_midline = BollingerBands(bbprice, displace, length, numdevdn, numdevup, averagetype).MidLine; def bb_upperband = BollingerBands(bbprice, displace, length, numdevdn, numdevup, averagetype).UpperBand; def bb_lowerband = BollingerBands(bbprice, displace, length, numdevdn, numdevup, averagetype).LowerBand; # Use reference calls to TOS KC's and plot midline and bands input kcdisplace = 0; input kcfactor = 1.5; input kclength = 20; input kcprice = close; input kcaverageType = AverageType.SIMPLE; input kctrueRangeAverageType = AverageType.SIMPLE; def kc_midline = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaveragetype, kctruerangeaveragetype).Avg; def kc_upperband = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaveragetype, kctruerangeaveragetype).Upper_Band; def kc_lowerband = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaveragetype, kctruerangeaveragetype).Lower_Band; # When the BB upper and lower bands cross inside the KC's we are in a Squeeze def squeezed = if bb_upperband <= kc_upperband and bb_lowerband >= kc_lowerband then 1 else if bb_upperband >= kc_upperband and bb_lowerband <= kc_lowerband then -1 else 0; #def squeezed = if bb_upperband crosses below kc_upperband and bb_lowerband crosses above kc_lowerband then 1 else if bb_upperband crosses above kc_upperband and bb_lowerband crosses below kc_lowerband then -1 else 0; AddVerticalLine(showVerticalLines and bb_upperband crosses below kc_upperband and bb_lowerband crosses above kc_lowerband, "Squeeze On", Color.RED); AddVerticalLine(showVerticalLines and bb_upperband crosses above kc_upperband and bb_lowerband crosses below kc_lowerband, "Squeeze Off", Color.GREEN); #Plot the current price across an entire chart #Also helps determine when price is approaching support and resistance #Color coded to indicate TTM_Squeeze zones input price = close; input barsBack = 300; def c = if !IsNaN(close) and IsNaN(close[-1]) then close else c[1]; plot priceline = if isNaN(close[-barsBack]) then c[-barsBack] else Double.NaN; #plot priceLine = HighestAll(if !IsNaN(price) and IsNaN(price[-1]) then price else Double.NaN); priceLine.DefineColor("squeezed", Color.RED); priceLine.DefineColor("unsqueezed", Color.GREEN); #priceLine.AssignValueColor(if squeezed == 1 then priceLine.Color("squeezed") else if squeezed == -1 then priceLine.Color("unsqueezed") else if squeezed == 0 then priceLine.Color("squeezed") else Color.CURRENT); priceLine.AssignValueColor(if squeezed == 1 then priceLine.Color("squeezed") else priceLine.Color("unsqueezed")); priceLine.SetPaintingStrategy(PaintingStrategy.DASHES); priceline.SetStyle(Curve.FIRM); priceLine.SetLineWeight(2); #plot sq = squeezed; # END - TTM_Squeeze_PriceLine
View attachment 25686
Start a new thread and receive assistance from our community.
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.
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.