I modified a copy of Mobius's Line At Price study, so it is not limited to just the last close price.
a modified version of
Line At Price
Mobius
Alternative to using the HighestAll() function
https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
this is the basic study , V00
it finds the lowest low on the chart.
Code:
# alt_horzpriceline_lowest_00
# halcyonguy
# 21-11-21
# a modified version of
# Line At Price
# Mobius
# Alternative to using the HighestAll() function
# https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
# draw a line at the lowest low, without using lowestall()
input barsBack = 1000;
# if a small number is used, then only the last 'barsBack' quantity of bars on the chart will have a line.
# the preceding bars will have na and no line drawn
#input barsBack = 50;
# rule to find a price value
def low1 = if barnumber() == 1 then low
else if low < low1[1] then low
else low1[1];
# set the desired value on last bar and the bars after it
def low2 = if !IsNaN(close) and IsNaN(close[-1])
then low1
else low2[1];
# look at bars after the last bar and read the desired value
def lowline = if isNaN(close[-barsBack])
then low2[-barsBack]
else Double.NaN;
plot z = lowline;
z.SetLineWeight(2);
z.SetDefaultColor(Color.LIME);
z.SetStyle(Curve.MEDIUM_DASH);
addlabel( 1, "low line " + lowline, color.yellow);
#
this one, V01 , has more features and comments
..work with a price function/formula (this example uses low, and finds the lowest low).
..add a condition to define when to process data, when it is true. (it stops at the last bar)
....a vertical line is drawn at the start of the condition being true.
....a stop could be added by changing the condition to 0 before the lastbar, so it could find values within a range of bars.
..choose to disable the start condition and use all the bars on the chart.
Just like the original, it doesn't use lowestall() or highestall(). it uses a big negative offset number.
to change this for another purpose, change this formula,
def pricedata = low;
to change the condition enable time, change this formula,
def cond1 = (bn > 540);
to use all of the bars on the chart and ignore the condition, set this to yes
disable_start_condition_use_all_bars = yes
there are 2 test inputs.
..test1 all data
....draws a label that explains the bubble colors.
....draws bubbles with barnumber, low, and the lowest price.
......gray bubbles are before the condition and ignored.
......cyan bubbles are during the condition being true.
......1 green bubble is at the lowest level.
..test2 single bubble
....1 green bubble is at the lowest level.
i added comments to describe what each section is doing.
I like to explain things, sorry if this is a little wordy.
Code:
# alt_horzpriceline_lowest_01
# halcyonguy
# 21-11-21
# a modified version of
# Line At Price
# Mobius
# Alternative to using the HighestAll() function
# https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
# this example code: find the lowest low on the chart, and draw a horizontal line, without using lowestall().
# it uses a large negative offset, to look at values after the lastbar.
def bn = barnumber();
def na = double.nan;
# a price level or a formula
def pricedata = low;
# some number that is greater than the number of bars on the chart
input barsBack = 1000;
# if a small number is used, then only the last 'barsBack' quantity of bars on the chart will have a line.
# the preceding bars will have na and no line drawn
# disable the start condition and use all the chart bars to find a value
input disable_start_condition_use_all_bars = yes;
addlabel( !disable_start_condition_use_all_bars, "NOT USING ALL BARS", color.cyan);
# add a start condition, that stays true, to define when to read data
# this example looks at data after barnumber 540
def cond1 = (bn > 540);
def enable1 = (cond1 or disable_start_condition_use_all_bars);
# draw a vertical line when the condition changes to true
addverticalline(( !enable1[1] and enable1), "START", color.light_gray);
# if looking for a lowest value, initialize with a big number.
# if looking for a highest value, initialize with a small number.
def initnum = 99999;
# rule to find a price value.
# in this case , pricedata < low1[1]
# this is processed on the desired bars, so that the desired value is on the last bar on the chart.
def low1 = if !enable1 then initnum
else if barnumber() == 1 then pricedata
else if pricedata < low1[1] then pricedata
else low1[1];
# set the desired value, lowest low, on the last bar and the bars after it
def low2 = if !IsNaN(close) and IsNaN(close[-1])
then low1
else low2[1];
# look at bars after the last bar and read the desired value
def lowline = if isNaN(close[-barsBack])
then low2[-barsBack]
else Double.NaN;
plot z = lowline;
z.SetLineWeight(2);
z.SetDefaultColor(Color.LIME);
z.SetStyle(Curve.MEDIUM_DASH);
z.hidebubble();
addlabel((lowline == initnum), " <<< No data found with condition >>> ", color.cyan);
input test1_all_data = no;
addlabel(test1_all_data, "low line " + lowline, color.yellow);
addlabel(test1_all_data, "The gray bubbles are before the condition." , color.gray);
addlabel(test1_all_data, "The cyan bubbles are during the condition." , color.cyan);
addlabel(test1_all_data, "The green bubble is at the Lowest" , color.green);
addchartbubble(test1_all_data, high*( if (enable1 and lowline == pricedata) then 1.04 else 1.02), bn + "\n" + round(pricedata, 2) + "\n" + round(lowline, 2), (if (enable1 and lowline == pricedata) then color.green else if enable1 then color.cyan else color.gray), yes);
input test2_single_bubble = no;
addchartbubble(((test2_single_bubble or test1_all_data) and enable1 and lowline == pricedata), low*0.994, "BN: " + bn + "\n" + round(pricedata, 2) + "\n$" + round(lowline,2), color.green, no);
addlabel(!test1_all_data and !test2_single_bubble , "Lowest: " + lowline, color.green);
# -------------------------
# orig
#input barsBack = 1000;
#
#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.SetLineWeight(2);
#line.SetDefaultColor(Color.LIME);
#line.SetStyle(Curve.MEDIUM_DASH);
#
hal_horz