NexusFi: Find Your Edge


Home Menu

 





How to draw Horizontal Lines with price label at predefined Prices ?


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one zoelithoi with 2 posts (0 thanks)
    2. looks_two sandptrader with 2 posts (0 thanks)
    3. looks_3 jsk123 with 2 posts (0 thanks)
    4. looks_4 rmejia with 1 posts (1 thanks)
    1. trending_up 22,731 views
    2. thumb_up 1 thanks given
    3. group 4 followers
    1. forum 7 posts
    2. attach_file 1 attachments




 
Search this Thread

How to draw Horizontal Lines with price label at predefined Prices ?

  #1 (permalink)
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.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Build trailing stop for micro index(s)
Psychology and Money Management
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Exit Strategy
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
22 thanks
The Program
20 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #2 (permalink)
 sandptrader 
Valdosta, GA. U.S.A
 
Experience: Advanced
Platform: Sierra , TOS
Trading: 6E, ES, CL, GC
Posts: 498 since Sep 2010
Thanks Given: 1,881
Thanks Received: 472


jsk123 View Post
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.

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

Reply With Quote
  #3 (permalink)
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.

Reply With Quote
  #4 (permalink)
 
rmejia's Avatar
 rmejia 
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 441

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.

Reply With Quote
Thanked by:
  #5 (permalink)
 sandptrader 
Valdosta, GA. U.S.A
 
Experience: Advanced
Platform: Sierra , TOS
Trading: 6E, ES, CL, GC
Posts: 498 since Sep 2010
Thanks Given: 1,881
Thanks Received: 472


rmejia View Post
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 ?

Attached Thumbnails
Click image for larger version

Name:	CL 11-15 (30 Min)  10_2_2015.jpg
Views:	1498
Size:	165.6 KB
ID:	194450  
Reply With Quote
  #6 (permalink)
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.

See below:

Regards,
Toby

script Horizontal_line_leftmost
{
input lineLength = 8;
input price_type = low;

#This line starts from the leftmost 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;
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;

#plot Horizontal_line_rightmost = price_type[lineLength];
}

input Num_of_Bars = 8;
input Type_of_Price = low;
input from_leftmost_bar = yes;

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

#AddLabel(yes, Concat("test: ", Horizontal_line_leftmost()));

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

Reply With Quote
  #7 (permalink)
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());

Reply With Quote
  #8 (permalink)
pjbelonger
WATKINSVILLE
 
Posts: 1 since Apr 2018
Thanks Given: 0
Thanks Received: 0


sandptrader View Post
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 ?

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.

Reply With Quote




Last Updated on May 13, 2018


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts