Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
How to draw Horizontal Lines with price label at predefined Prices ?
How to draw Horizontal Lines with price label at predefined Prices ?
jsk123
Hyderabad,India
Posts: 88 since Oct 2013
Thanks Given: 44
Thanks Received: 21
Hi,
I have some price levels that I want to put in the code of thinkscript so that I can apply that study and immediately recognize the support and resistance levels .
I already have the price levels that I want to draw horizontal lines at. It is pretty basic thing I am trying to accomplish. But I am lost as I'm a noob to TOS.
Please give me an example of how to draw horizontal lines (with label) at predefined price levels so that I can make an indicator in TOS.
One example would suffice. Thank you very much.
Can you help answer these questions from other members on NexusFi?
Above your Chart you can Select Drawing Tools...Then the Forth selection "$ Price Levels"
This is the Manual Drawing Method....you can then Edit that line to set the Price to the Exact Tick if you could Not get it Perfectly where you wanted it.
I see you are wanting to Code this....
jsk123
Hyderabad,India
Posts: 88 since Oct 2013
Thanks Given: 44
Thanks Received: 21
Hi
Thanks for the reply. I have hundreds of levels that I need to put, everytime I close the software or uninstall/reinstall it, I will lose those levels if I draw using that PriceLevel tool.
So, i want to write code so that I can apply the indicator immediately if some of the levels are lost due to some reason.
You can save those levels by saving the drawing set. Right click and at the end, Drawings, then at the end again, Save Drawing Set. You can then load it into any other chart.
Also if you save the Chart Grid (box icon in the top right), Save Grid As, it will save the grid with all indicators and drawings so if you reload that grid it loads everything.
Everything is stored in the thinkorswim servers so it will be there available until you delete the sets.
I was just trying to find out how i had mine set...as all of my drawings are saved including Price Levels.
When i start back up the Platform they are all there.
It has to do with how you have your Platform set up to save your work space like @rmejia has mentioned.
I was curious were you trying to accomplish Price levels of Support/Resistance in this way on this Chart i attached ?
zoelithoi
Las Vegas Nevada
Posts: 2 since Oct 2017
Thanks Given: 0
Thanks Received: 0
I couldn't find any examples on the 'net' for drawing a horizontal line based on the price (high, low, open, etc. ) using Thinkscript.
Kinda wierd..... it seems like it should be so easy.
anyways, below is my script.
It seems like there should be an easier way to do it.
My script lets you define the length of the line in terms of 'bars' on the first input parameter.
It will draw a line from the leftmost bar all the way to the right.
The level of the bar is based on either the leftmost bar or the rightmost bar depending on the 3rd input parameter (leftmost_bar) which is a boolean, it defaults to yes.
The 2nd input parameter lets you chose 1 of the price fundamentals, ie. low, close, open, high, etc. this is where the horizontal line will be drawn
It will add a 'price' label in the form of a bubble.
declare once_per_bar; #recalculation done once per bar, not per tick
def current_bn = BarNumber();
def Total_bn = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then current_bn else Double.NaN);
#data_pointer, ie the bar number we use to point to historical or future data, = Total_bn (total bar numbers) - current_bn (current bar number).
def data_pointer = Total_bn - current_bn;
def x = lineLength - data_pointer -1;
plot Horizontal_line_leftmost =
if linelength - data_pointer == 15 and data_pointer < lineLength then price_type[14]
else if linelength - data_pointer == 14 and data_pointer < lineLength then price_type[13]
else if linelength - data_pointer == 13 and data_pointer < lineLength then price_type[12]
else if linelength - data_pointer == 12 and data_pointer < lineLength then price_type[11]
else if linelength - data_pointer == 11 and data_pointer < lineLength then price_type[10]
else if linelength - data_pointer == 10 and data_pointer < lineLength then price_type[9]
else if linelength - data_pointer == 9 and data_pointer < lineLength then price_type[8]
else if linelength - data_pointer == 8 and data_pointer < lineLength then price_type[7]
else if linelength - data_pointer == 7 and data_pointer < lineLength then price_type[6]
else if linelength - data_pointer == 6 and data_pointer < lineLength then price_type[5]
else if linelength - data_pointer == 5 and data_pointer < lineLength then price_type[4]
else if linelength - data_pointer == 4 and data_pointer < lineLength then price_type[3]
else if linelength - data_pointer == 3 and data_pointer < lineLength then price_type[2]
else if linelength - data_pointer == 2 and data_pointer < lineLength then price_type[1]
else if linelength - data_pointer == 1 and data_pointer < lineLength then price_type[0]
else double.nan;
#plot Horizontal_line_leftmost = yyy;
}
script Horizontal_line_rightmost
{
input lineLength = 8;
input price_type = close;
#This line starts from the 'right-most' bar
declare once_per_bar; #recalculation done once per bar, not per tick
def current_bn = BarNumber();
def Total_bn = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then current_bn else Double.NaN);
#data_pointer, ie the bar number we use to point to historical or future data, = Total_bn (total bar numbers) - current_bn (current bar number).
def data_pointer = Total_bn - current_bn;
plot Horizontal_line_rightmost =
if data_pointer == 15 and data_pointer < lineLength then price_type[-15]
else if data_pointer == 14 and data_pointer < lineLength then price_type[-14]
else if data_pointer == 13 and data_pointer < lineLength then price_type[-13]
else if data_pointer == 12 and data_pointer < lineLength then price_type[-12]
else if data_pointer == 11 and data_pointer < lineLength then price_type[-11]
else if data_pointer == 10 and data_pointer < lineLength then price_type[-10]
else if data_pointer == 9 and data_pointer < lineLength then price_type[-9]
else if data_pointer == 8 and data_pointer < lineLength then price_type[-8]
else if data_pointer == 7 and data_pointer < lineLength then price_type[-7]
else if data_pointer == 6 and data_pointer < lineLength then price_type[-6]
else if data_pointer == 5 and data_pointer < lineLength then price_type[-5]
else if data_pointer == 4 and data_pointer < lineLength then price_type[-4]
else if data_pointer == 3 and data_pointer < lineLength then price_type[-3]
else if data_pointer == 2 and data_pointer < lineLength then price_type[-2]
else if data_pointer == 1 and data_pointer < lineLength then price_type[-1]
else if data_pointer == 0 and data_pointer < lineLength then price_type[0]
else double.nan;
# parameters:
# param#1: number of bars
# param#2: choice of ; low, high, close, or open
# param#3: the line will be drawn from the leftmost bar at teh level of teh 'type_of_price', ie. low, high, close, open etc.; otherwise it will be drawn from the rightmost bar.
plot horiz =
if from_leftmost_bar then Horizontal_line_leftmost (Num_of_Bars, Type_of_Price)
else Horizontal_line_rightmost (Num_of_Bars, Type_of_Price);
AddChartBubble(horiz == horiz[Num_of_Bars-1] and from_leftmost_bar, horiz, Horizontal_line_leftmost(), horiz.TakeValueColor());
AddChartBubble(horiz == horiz[Num_of_Bars-1] and !from_leftmost_bar, horiz, Horizontal_line_rightmost(), horiz.TakeValueColor());
zoelithoi
Las Vegas Nevada
Posts: 2 since Oct 2017
Thanks Given: 0
Thanks Received: 0
I found a mistake in the chart bubbles, it should be:
AddChartBubble(horiz == horiz[Num_of_Bars-1] and from_leftmost_bar, horiz, Horiz[0], horiz.TakeValueColor());
AddChartBubble(horiz == horiz[Num_of_Bars-1] and !from_leftmost_bar, horiz, Horiz[0], horiz.TakeValueColor());
pjbelonger
WATKINSVILLE
Posts: 1 since Apr 2018
Thanks Given: 0
Thanks Received: 0
sandptrader, what you were "curious" about is exactly what I'm trying to do, add price labels inside the right axis for horizontal levels. Please help.