How to script to plot horizontal price lines with price ?

A

achillez16

New member
VIP
Hi All

I would like to create multiple drawings of price line with price shown as the name, currently I am doing this manually and would like to know if there is a way to this via a script. Something like below for e.g TSLA

1] Input the list of price levels I would like to plot. (eg. 1600, 1650, 1700) I can edit the script itself and add these price levels.
2] Based on the number of prices I enter in the list it should iterate over the list and plot the price levels for all these price points.
3] It should also display the price name

Image - (the price lines here were done manually, but looking for something similar which can be plotted all at once if given multiple levels )

 
BenTen

BenTen

Administrative
Staff
VIP
Start with this script:

Code:
# Auto Horizontal Lines

input price1 = 130;
input price2 = 131;
input price3 = 132;

plot l1 = price1;
plot l2 = price2;
plot l3 = price3;

Adjust the inputs to the price levels you want to plot.
 
A

achillez16

New member
VIP
Thanks Ben that helps . . . Just curious is there a way to define an array / list in thinkscript ? so that i can define an array with all the price levels and loop over it ?
 
Piper792

Piper792

New member
VIP
Anyone have the code to add a "name" to the price level/line. Say I am plotting out 4-hour levels and want to identify it with a name to the right on the price line.
 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@Piper792 You can use the Price level drawing tool for that.
 
Piper792

Piper792

New member
VIP
Yeah - I want to plot a series of levels and just input the price in the study. Of course with different prices. But exactly want to replicate price level

# 1hr UT
# 2hr UT
# 4hr UT
# Swing Pivot High

#Resistance
plot data1 = 1995.6; data1.SetDefaultColor(Color.Red);
plot data2 = 1995.6; data1.SetDefaultColor(Color.Red);
plot data3 = 1995.6; data1.SetDefaultColor(Color.Red);
plot data4 = 1995.6; data1.SetDefaultColor(Color.Red);

#Support
plot data5 = 1995.6; data1.SetDefaultColor(Color.Green);
plot data6 = 1995.6; data1.SetDefaultColor(Color.Green);
plot data7 = 1995.6; data1.SetDefaultColor(Color.Green);
plot data8 = 1995.6; data1.SetDefaultColor(Color.Green);
 
V

viswanarahari

New member
Hello new friends!. This is a nice forum and am exited to be part of it. Kindly pardon me if I am posting in wrong place. But I will learn with your guidance. I am familiar with python and other languages now just facing some road blocks to learn thinkscript.

Can you please help me how I can make a think script which will plot price lines based on underlying symbol.

1. I want to draw price lines based on the stock.
2. The script should switch based on the stock that is in the display. I did below and it is some how not working.

AddLabel(yes, GetSymbol());

switch((GetSymbol()){

case "ZM" :
{ plot p_100 = 100;
plot P_207 = 207;
plot P_319 = 319;
plot P_429 = 429; }

case "AAPL":

{ Plot P_100 = 100;
Plot P_250 = 250;
Plot P_275 =275; }
}
 
Last edited:
korygill

korygill

Active member
VIP
@viswanarahari Try something like this

Code:
AddLabel(yes, GetSymbol());

plot p1;
plot p2;
plot p3;
plot p4;

def nan = double.NaN;


if (GetSymbol() == "ZM") then {
p1 = 100;
P2 = 207;
P3 = 319;
P4 = 429;
} else if (GetSymbol() == "AAPL") then {
p1 = 100;
p2 = 250;
p3 = 275;
p4 = nan;
} else {
p1 = nan;
p2 = nan;
p3 = nan;
p4 = nan;}
 
V

viswanarahari

New member
Sincere thanks @korygill. It does work functionally.

One small additional help. Is there a way I can store p1,p2,p3,.... pn in an array and access them ? Number of elements in array are constant and it becomes easy to maintain the code as p1,p2, p3 changes based on criteria. For example..

def arrayAMZN = (p1, p2,p3, pn, nan,..nan);
def arrayAAPL = (p1, p2,p3, pn, nan,..nan);

Looks like similar question is asked above and when I checked the link, I did not get required information. Sincere apologies since I am just a beginer on this thinkscript.

Sincere thanks again!
 
Last edited:
korygill

korygill

Active member
VIP
No, not that I know of. Best pattern I have found is the one I posted.
 
V

viswanarahari

New member
No, not that I know of. Best pattern I have found is the one I posted.
Sincere thanks for the reply Korygill. I searched a lot and could not find something nearest to what I am looking additinally.

But your original answer is greatly appreciated again!
 
rad14733

rad14733

Well-known member
VIP
Sincere thanks @korygill. It does work functionally.

One small additional help. Is there a way I can store p1,p2,p3,.... pn in an array and access them ? Number of elements in array are constant and it becomes easy to maintain the code as p1,p2, p3 changes based on criteria. For example..

def arrayAMZN = (p1, p2,p3, pn, nan,..nan);
def arrayAAPL = (p1, p2,p3, pn, nan,..nan);

Looks like similar question is asked above and when I checked the link, I did not get required information. Sincere apologies since I am just a beginer on this thinkscript.

Sincere thanks again!
Just to clarify, Thinkorswim/Thinkscript does not support arrays at this time...

If you feel that it is something worthy of adding you can contact support and make a request... If they get enough requests they might consider the addition for a future release but it would be off in the future as it would need to be fully implemented and tested...
 
Drestat

Drestat

New member
Hello all! Im new here! Thanks for having me!
Im looking to write something that will help my father and I save time when we do our daily homework:

Lets say I have a Excel document with these columns:

Symbol | Name of line | Green Line | Red Line
-----------------------------------------------------------------------------------------------------
SPY | Line in 60 mins | 100 | 90
-----------------------------------------------------------------------------------------------------
SPY | Line in Day | 105 | 92
-----------------------------------------------------------------------------------------------------
QQQ | Line in Day | 50 | 45
-----------------------------------------------------------------------------------------------------
QQQ | Line in Day | 52 | 46
-----------------------------------------------------------------------------------------------------
FB | Line in Day | 150 | 145


My goal is to then take that table and import it into TOS and create "Price Level" lines from it. As in the example, it would go into the "SPY" symbol and create two "Price Level" lines with the name "Line in 60 mins". The first line in price "100" would be green, and the second line with price "90" would be red. Both with the same name, only difference would be the color. Then it would go to the rest of the symbols :)

I have a bit of programing experience but Im completely new to thinkScrip, I hope some of you are able to push me in the right direction.

Your time is extremely appreciated, so thanks in advance!

Andres Munoz
 
Last edited:
rad14733

rad14733

Well-known member
VIP
Greetings @Drestat and welcome to the forums... Unfortunately, we cannot import into TOS in the manner you have described... The only thing we can import is symbols into a Watchlist...
 
Drestat

Drestat

New member
Thanks for the prompt response @rad14733 ! Then, instead I would like to write a study instead of importing it, and i would just edit the code directly every day to reflect the new values I would like my Price Lines to have. Would you be able to push me in the right direction?
 
Drestat

Drestat

New member
I tried this and this is a beautiful start! (Thank you @korygill ).

Ive Added the colors I need for my lines, now I need to give the variable "p1" a Name and also show the Price. How could I go about it with this example?

It tells me that I cant add a Label, but perhaps im doing it wrong. Instead of a plot, could I draw a "PriceLine" and have it show a name on the left, as well as the price on the right?

Thank you very much in advance!

--------------------------------------------------
AddLabel(yes, GetSymbol());

plot p1;
plot p2;
plot p3;
plot p4;

p1.SetDefaultColor(Color.GREEN);
p2.SetDefaultColor(Color.RED);
p3.SetDefaultColor(Color.GREEN);
p4.SetDefaultColor(Color.RED);

def nan = Double.NaN;

if (GetSymbol() == "SPY")
then {
p1 = 346;
p2 = 345.8;
p3 = 345.6;
p4 = 345.4;
} else if (GetSymbol() == "QQQ")
then {
p1 = 100;
p2 = 102;
p3 = 103;
p4 = nan;
} else {
p1 = nan;
p2 = nan;
p3 = nan;
p4 = nan;
}
--------------------------------------------------------
 
Last edited:
rad14733

rad14733

Well-known member
VIP
I tried this and this is a beautiful start! (Thank you @korygill ).

Ive Added the colors I need for my lines, now I need to give the variable "p1" a Name and also show the Price. How could I go about it with this example?

It tells me that I cant add a Label, but perhaps im doing it wrong. Instead of a plot, could I draw a "PriceLine" and have it show a name on the left, as well as the price on the right?
I'm not sure you can do this automatically... You might be expecting too much out of the TOS platform... Unfortunately, we have to live within the constraints of the program... There are many things we might want to do if the program would allow us... I think we need to reconcile with the fact that TOS should be considered more of an entry-level trading platform in comparison to other offerings in the software market... It surpasses others in some areas but lags woefully behind in others...
 

Similar threads

Top