Current Price Line Indicator for ThinkorSwim

#Plots a Horizontal Line that follows the price value selected
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.green);
priceline.hideBubble();
@chillc15 this is the one that I have been using for a while. Works well and seems "clean." Thanks for sharing.
 
This is all I use for current priceline... I don't recall if I found this somewhere or wrote it myself... I usually set the color to WHITE from the Study settings panel and sometime set it to display as dots instead of a solid line... Works for my need of looking back for support/resistance...

Ruby:
input price = close;
plot price_across_chart = HighestAll(if !IsNaN(price) and IsNaN(price[-1]) then price else Double.NaN);
 
I'm not a coder, but I've been browsing through Google and on here and couldn't find a solution, so I tried playing around with this and came up with this code:

Code:
plot CloseLine = Close(period = AggregationPeriod.DAY);

CloseLine.SetStyle(Curve.SHORT_DASH);
CloseLine.SetLineWeight(1);
CloseLine.SetDefaultColor(Color.WHITE);
CloseLine.HideBubble();
CloseLine.HideTitle();

So the purpose of this indicator is to draw a line wherever the close price is at. When I was trying this code on OnDemand, it wasn't showing the line on Premarket.

Question: How do I add the line for premarket? Do I need to change the AggregationPeriod?

Another feature I want to add is to have the "CloseLine" to change to GREEN if it goes above previous close and RED if it goes below previous close. Anyone have the expertise to do that?

I tried:

Code:
plot CloseLine = if Close(period = AggregationPeriod.DAY) > close[-1] then color.GREEN else
                                       if Close(period = AggregationPeriod.DAY) < close[-1] then color.RED else
                                       color.CURRENT;

CloseLine.SetStyle(Curve.SHORT_DASH);
CloseLine.SetLineWeight(1);
CloseLine.SetDefaultColor(Color.WHITE);
CloseLine.HideBubble();
CloseLine.HideTitle();

That code gave me an error.

So, any help would be greatly appreciated.
 
There are limitations to OnDemand and you may have encountered one of them... I hold very little trust in OnDemand simply because everything I try to do in OnDemand seems to be too complex or isn't supported... My advice would be to try the same thing in Paper Money which performs better than OnDemand... Just my two cents...
 
There are limitations to OnDemand and you may have encountered one of them... I hold very little trust in OnDemand simply because everything I try to do in OnDemand seems to be too complex or isn't supported... My advice would be to try the same thing in Paper Money which performs better than OnDemand... Just my two cents...
I guess I'll wait until market opens again.
 
I tried to modified this code so that the line would turn green when the current price goes above previous high bar and turn red when it goes below previous low bar. However, I'm getting the "Expected double" error. Any idea where I did wrong??

Here's the code:
Code:
def vClose = close;
def vHigh = high[-1];
def vLow = low[-1];
def nan = double.NaN;

def highestClose = HighestAll(if IsNaN(vClose[-1]) then vClose else nan);
def PreviousHigh = HighestAll(if IsNaN(vHigh[-1]) then vHigh else nan);
def PreviousLow = HighestAll(if IsNaN(vLow[-1]) then vLow else nan);

plot hc = if highestClose > PreviousHigh then color.GREEN else
          if highestClose < PreviousLow then color.RED else
          color.WHITE;

hc.SetPaintingStrategy(PaintingStrategy.DASHES);
hc.SetDefaultColor(Color.CURRENT);
hc.HideBubble();
hc.HideTitle();
 
Does anyone have study for this? My goal is to look at the pre-market price movement while charting on the daily chart and on charts that I don't have after hours trading turned on. Being able to see the live priceline on these charts would be VERY useful. Please let me know!
 
@hydroflask No, without extended hours enabled, you won't be able to pull any data from pre-market.

Also, there is no pre-market for the Daily timeframe.
 
@BenTen I understand there's no pre-market on the daily timeframe, what I'd like to do is grab the current pre-market price data and superimpose it on the daily chart. There must be a way to do this in the script of the priceline indicator and where it gets its data, right?
 
Last edited:
I've inserted a bubble mover to the following Horizontal Line S/R code. However it's not working. Can you please assist. Thanks.

Code:
#  Posted from Mobius 1/15/18 - This puts a Horizontal Line at Price to see price level at potential Support / Resistance
#  Here is a code Snippet that gives you all you need to limit a line both forward and backward
# Dynamic_Line
# Mobius
# V01.09.2012
input LineLimit = 100;
input OnExpansion = yes;
input OnExpansionLimit = 30;
input bubble_mover    = 5; #Moves bubbles left/right then number of bars input here
def   n               = bubble_mover;
def   n1              = n +1;
def c = close; # Replace close with any conditional value that meets your requirement
def barNumber = barNumber();
def bar = if IsNaN(c) then Double.NaN else BarNumber();
def ThisBar = HighestAll(bar);
def cline = if bar == ThisBar then c else Double.NaN;
def condi = CompoundValue(1, if IsNaN(c) then condi [1] else c, c);
plot P = if ThisBar - LineLimit <= bar then HighestAll (cLine) else Double.NaN;
P.SetStyle(Curve.Short_Dash);
P.SetLineWeight(1);
P.SetDefaultColor(CreateColor(75,250,150));
plot ExpLine = if OnExpansion and barNumber < HighestAll (bar + OnExpansionLimit) and IsNaN(c) then condi else Double.NaN;
ExpLine.SetStyle(Curve.Short_Dash);
ExpLine.SetLineWeight(1);
ExpLine.SetDefaultColor(CreateColor(150,150,150));
# End Code Dynamic Line Mobius • 8:23 PM

input show_bubbles = yes;
def current = !isnan(close[n1])and isnan(close[-1]);
AddChartBubble(show_bubbles and current, c, Round(c), color.cyan,yes
);
 
Was wondering if anyone can help me create a study that does one thing only, plot a horizontial midline to the right of the current bar. And i want the line to always be plotted half the range of the current candle.
 
Was wondering if anyone can help me create a study that does one thing only, plot a horizontial midline to the right of the current bar. And i want the line to always be plotted half the range of the current candle.

Use one of the PriceLine studies posted here and set the price to hl2...
 
Is it possible to modify the priceline studie to instead of showing the current price, show line when price is 10c below current price?
 
Is it possible to modify the priceline studie to instead of showing the current price, show line when price is 10c below current price?

I'm sure it can... In fact, just the other day I added code to my PriceLine Study so it paints a line 1 ATR above and 1 ATR below the current price... It just requires two additional plots, one with the value added and the other with the value subtracted... Just two lines of code unless you want added formatting...
 
Original code appears to have stopped working. The horizontal line is now static and not moving with the latest price. Was working fine on Friday, but this morning, not moving. Anyone else?
 

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