Horizontal Lines In ThinkOrSwim

@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;}
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

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:
@viswanarahari 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...
 
How can do I do the LOD line similar to this one?

Code:
# Plot High and Low of RTH for Any Day Through Week
# Mobius
# Chat Room Request 04.22.2020

input DayOfWeek = {default Monday, Tuesday, Wednesday, Thursday, Friday};

def DOW;
switch (DayOfWeek)
{
case Monday:
 DOW = 1;
case Tuesday:
 DOW = 2;
case Wednesday:
 DOW = 3;
case Thursday:
 DOW = 4;
case Friday:
 DOW = 5;
}
def RTH = getTime() >= RegularTradingStart(getYYYYMMDD()) and
          getTime() <= RegularTradingEnd(getYYYYMMDD());
def day = getDayOfWeek(getYYYYMMDD()) == DOW;
def hh = if day and RTH and !RTH[1]
         then high
         else if day and RTH and high > hh[1]
         then high
         else hh[1];
def xh = if high == hh
         then barNumber()
         else double.nan;
plot HighLine = if barNumber() >= highestAll(xh)
                then highestAll(if isNaN(close[-1])
                                then hh
                                else double.nan)
                else double.nan;
def ll = if day and RTH and !RTH[1]
         then low
         else if day and RTH and low < ll[1]
         then low
         else ll[1];
def xl = if low == ll
         then barNumber()
         else double.nan;
plot LowLine = if barNumber() >= highestAll(xl)
                then highestAll(if isNaN(close[-1])
                                then ll
                                else double.nan)
                else double.nan;
 
@blake007 By switching high and highestAll to low and lowestAll.

Code:
plot lowLine = lowestAll(if isNaN(close[-1])
then low(period = "Day")
else Double.NaN);
 
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:
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...
 
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?

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!

Code:
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;
}
 
@Drestat 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...
 
Hi everyone,

Is it possible to draw a horizontal line with the following conditions:

Only shows if regular session hours (I think this one is done using

Code:
def regularSessionHours = RegularTradingStart(GetYYYYMMDD()) <= GetTime();

and using regularSessionHours on the plot condition)

Price level is the price @specific time regardless of the chart timeframe?

For Ex: A horizontal line drawn in the 2 min or 15 min or any chart at the price @935am
 
Untested, but something like this maybe:

Code:
input time = 0930;

def price_at_time = if SecondsFromTime(time) = 0 then CLOSE
    else if secondsFromTime(time) > 0 then price_at_time
        else double.nan;

-mashume
 
I am trying to find out a way to display horizontal dashed lines at every 100 points for forex pairs. For example, GBP/USD, display a horizontal line at 1.20, 1.21, 1.22, 1.23, etc.

Can anybody point me in the right direction?
 
@Englewood85 That's the general idea... I'll leave it to you to research the SetPaintingStrategy() function...

Ruby:
plot price120 = 1.20;
plot price121 = 1.21;
plot price122 = 1.22;
 
@generic so sorry for the confusion, i am looking for horizontal lines drawn as I have shown in the image below, extended all the way to the right side of the screen.

Thank you,

Screen-Shot-2020-12-10-at-6-24-11-PM.png
 
Like this?

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2020
#
#wizard plots
#wizard text: Inputs: length:
#wizard input: length
#wizard text: trend setup:
#wizard input: trendSetup

input length = 20;
input trendSetup = 3;

def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];

plot Bearish = IsAscending(close, trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing;

plot Bullish = IsDescending(close, trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bearish.SetDefaultColor(GetColor(1));
Bearish.SetLineWeight(2);
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(2));
Bullish.SetLineWeight(2);

def condition = bullish or bearish;

def b_high = if condition then high[1] else b_high[1];
def b_low = if condition then close[1] else b_low[1];

plot hh = b_high[1];
plot ll = b_low[1];

hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh.SetDefaultColor(Color.YELLOW);
ll.SetDefaultColor(Color.YELLOW);
 
@BenTen Thats exactly what I am looking for, two tweaks if it's not too much to ask plz. I would like the lines to start at the candle (if possible), plz refer to the yellow arrows in the image below. and also for bear engulfing candle, the lines are not plotted at the right level. For bear flag lines should be at open of the candle and the highest wick as shown in the image below in red circle and red lines...Also is there a way to extend the lines all the way to the right so I can spot over laps between different areas?

I really appreciate it and thank you for your time

Screen-Shot-2020-12-10-at-7-16-14-PM.png
 
@Learnbot Partial fix below. Not sure how to make the start line starts at the candle before the engulfing pattern, so you would have to live it that for now.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2020
#
#wizard plots
#wizard text: Inputs: length:
#wizard input: length
#wizard text: trend setup:
#wizard input: trendSetup

input length = 20;
input trendSetup = 3;

def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];

plot Bearish = IsAscending(close, trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing;

plot Bullish = IsDescending(close, trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bearish.SetDefaultColor(GetColor(1));
Bearish.SetLineWeight(2);
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(2));
Bullish.SetLineWeight(2);

def bu_high = if bullish then high[1] else bu_high[1];
def bu_low = if bullish then close[1] else bu_low[1];
def be_high = if bearish then high[1] else be_high[1];
def be_low = if bearish then open[1] else be_low[1];

plot bu_hh = bu_high[1];
plot bu_ll = bu_low[1];
plot be_hh = be_high[1];
plot be_ll = be_low[1];

bu_hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bu_ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bu_hh.SetDefaultColor(Color.YELLOW);
bu_ll.SetDefaultColor(Color.YELLOW);
be_hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_hh.SetDefaultColor(Color.YELLOW);
be_ll.SetDefaultColor(Color.YELLOW);
 
@Learnbot Change the [1] from the 4 plots to [-1] and they'll draw from the candle you want. This will make the study repaint by 1 bar but I think in your case it shouldn't be a problem for what you're trying to do with it.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
366 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top