Plot Current Live Price Horizontal Line - not at close of current bar regardless of timeframe

DJones

New member
I cannot find a horizontal current price line that actually updates with live data. Everything seems to use a closing price for a bar. I want a live price bar regardless of timeframe on the chart.

Please help!
 
Solution
@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 -...
@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

1757372471029.png

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

1757372528369.png



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

1757372602207.png
 
Solution

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