Current Price Line Indicator for ThinkorSwim

korygill

korygill

Active member
VIP
This indicator displays a horizontal line across your ThinkorSwim chart to show the current value of the price.

One some charts, it is hard to discern the last price among all the other indicators and bubbles on the axis. Sometimes one wants to see the last price relative to other meaningful values like prev lows, reversal points, etc. This indicator draws a horizontal line across the chart area for the last price. I find it useful on VolumeProfile and TPO charts and many more.

Image of LinePriceTracker
(Orange line at 2981.5 on the sample charts below)



Code for LinePriceTracker

Code:
# LastPriceTracker
#
# Author: Kory Gill, @korygill
#
# Shows the last price as horizontal line across entire chart area.
#
# VERSION HISTORY  - Sortable date and time (your local time is fine), and your initials.
# 20190910-2200-KG - Created.
# ...
# ...

def vClose = close;
def nan = double.NaN;

def highestClose = HighestAll(if IsNaN(vClose[-1]) then vClose else nan);
plot hc = highestClose;
hc.SetPaintingStrategy(PaintingStrategy.DASHES);
hc.SetDefaultColor(Color.Orange);
hc.HideBubble();
hc.HideTitle();

Link to LastPriceTracker study

https://tos.mx/SkUZpR


Happy trading,
Kory Gill, @korygill
 
Last edited by a moderator:
S

soary

Member
Hi Kory and community, this looks interesting but since I'm not a programmer and just a beginner learning thinkscript I didn't understand it at first but I think I do now, however I wonder why this code would be useful since the last price is on the platform. I do see visual benefit of having a line for the last price even though it will keep moving with every last price. Did I interpret your code correctly.?

I have been looking for something similar for a long time to put a horizontal line on my daily and intraday charts with the prior days market close that occurs at 1600 Eastern time. I found a code in TOS and tried to modify it twice. In my first attempt it was similar to your code here and the close horizontal line on the charts moved with every last close candle which is not what I wanted. This is my most recent attempt which shows no red mistakes in the code in TOS but it doesn't show the price graph on the charts. I have no idea how to fix it. I would greatly appreciate your help or the community to help me add the market close to my charts. Thanks in advance

Code:
def marketClose = 1600.00;

plot yesterday = marketClose;

input aggregationPeriod = AggregationPeriod.DAY;

input showOnlyLastPeriod = yes;

input Close = 1600.00;

#hint Close: End of Period, Market close 1600 EST.

input length = 1;

input displace = -1;

def closeByPeriod = close(period = “DAY”)[-1];

def prevPrice = close(period = aggregationPeriod)[-1];

def price = close(period = aggregationPeriod);

plot DailyClose = if showOnlyLastPeriod and !IsNaN(prevPrice) then Double.NaN else price;

DailyClose.SetDefaultColor(GetColor(3));

DailyClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Last edited:
S

SupaDupa

New member
Hi, I noticed E-trade and Tradingview have a static price line indicator in their charts but TOS did not. TOS help desk made such an indicator for me but they could not or did not have the time to make it work with extended hours, only works with extended hours set to 0. Thus it does not work with any study such as Ichimoku. Was wondering if such an indicator already exist or can someone code this one https://tos.mx/5OkZ8GE to work with extended hours. Thanks in adavance .
 
zeek

zeek

Active member
2019 Donor
Noticed that this indicator does not work in extended hours, is there any way to modify the code to make that work?
 
R

ryansau6

New member
If you are working with only the daily chart then no. In order to see if with extended hours you would have to be on an intraday chart.
 
zeek

zeek

Active member
2019 Donor
If you are working with only the daily chart then no. In order to see if with extended hours you would have to be on an intraday chart.

It’s the intraday chart i was trying it with. The line was showing in pre-market but it was not moving along as the price changed.
 
blakecmathis

blakecmathis

Well-known member
This is a basic chart from TradingView. I really like how there is a simple line that tracks with the market price across the chart. Is there anybody who can help me implement this into TOS?

 
C

chillc15

New member
This is a basic chart from TradingView. I really like how there is a simple line that tracks with the market price across the chart. Is there anybody who can help me implement this into TOS?

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

skynetgen

Well-known member
#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();

Brilliant code without using "highestall() (supposedely time consuming in timescript) ! Thanks man!
 
X

XeoNoX

Member
another simpple but very good code to draw the line across the chart for the current price... works with the current price across all time frames and you can change the color or style of the line

Code:
plot priceLine = highestAll(if isNan(close[-1]) and !isNAN(close) then close else double.nan);
 
P

Poc

New member
New to Thinkorswim. I asked their support about pricelines and chart order. Is there anyway to have priceline that draws behind the price bars? TOS support advised not.
Alternatively, is there a way to have the grid on TOS be in quarter increments. My observation is that crude trades from quarter to quarter very often and I use the pricelines to denote the quarter increments.
I spent some time on the OneNote cloud looking for a zone drawing tool also. I am not looking for an indicator to draw the zones for me automatically. I would like to be able to draw the zone and input the border color and the color, and preferably have it drawn behind the price bars.
I can accomplish most of that with the rectangle tool, which unlike the priceline draws behind the price bars. The rectangle tool will not draw forward in time on tick and renko charts, although it does keep stepping forward as the new bars print.
Thanks, Poc
 
markos

markos

Well-known member
VIP
This is a must for any /ES or SPX Day Trader although I use it on my daily chart.

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;
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 BarNumber0;
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
 
murkr

murkr

Member
VIP
@markos I get this error when trying to add your code posted above

 
scott69

scott69

New member
#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.
 

Similar threads

Top