Horizontal Lines In ThinkOrSwim

@generic and @BenTen One more question plz, I want the arrows to show only on 15min time frame how can I do that? The current script i came up with shows arrows on 15min, 5 min and on 1 min, but does show on higher than 15 min time frames so i am missing something but i don't know what... i tried to add IF..ELSE as u can see in my code but i don't know what veriabe would go after else lol

thank you both
Code:
def fifteen_min_bool;
# Set Chart for 15mm
if GetAggregationPeriod() == AggregationPeriod.FIFTEEN_MIN {
    fifteen_min_bool = 1;
} else {
    fifteen_min_bool = 0;
}
#def ltDay = if GetAggregationPeriod() == AggregationPeriod.fifteen_min then 1 else Double.NaN;

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];




#if GetAggregationPeriod() <= AggregationPeriod.fifteen_min {
    plot Bearish_15 = IsAscending(close(period = AggregationPeriod.FIFTEEN_MIN), trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing;

    plot Bullish_15 = IsDescending(close(period = AggregationPeriod.FIFTEEN_MIN), trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

    Bearish_15.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
    Bearish_15.SetDefaultColor(GetColor(1));
    Bearish_15.SetLineWeight(2);
    Bullish_15.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
    Bullish_15.SetDefaultColor(GetColor(2));
    Bullish_15.SetLineWeight(2);
#} else {#}
 

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

@Learnbot Change the current_agg to make it show up on different aggs.
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;
input current_agg = AggregationPeriod.FIFTEEN_MIN;

def nan = Double.NaN;
def fifteen = GetAggregationPeriod() == current_agg;
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 and
    fifteen;

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

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 and fifteen then high[1] else bu_high[1];
def bu_low = if bullish and fifteen then close[1] else bu_low[1];
def be_high = if bearish and fifteen then high[1] else be_high[1];
def be_low = if bearish and fifteen then open[1] else be_low[1];

def buhh = if IsNaN(close) then buhh[1] else bu_high; 
def bull = if IsNaN(close) then bull[1] else bu_low;
def behh = if IsNaN(close) then behh[1] else be_high;
def bell = if IsNaN(close) then bell[1] else be_low;

plot bu_hh = buhh;
plot bu_ll = bull;
plot be_hh = behh;
plot be_ll = bell;

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);
 
Thank you again @mashume , for some reason it prints on different price levels when changing the chart timeframe and both are wrong...

Hi @BenTen @tomsk or anybody else, is this that hard?, can this be done?

Ex. @9:45:00am today, ES was 3525.5, I would like to see a horizontal line at 3525.5 on the 5 min, 30 min, or any timeframe chart.
because its plotting the close the timeframe you choose has to BOTH have an aggregation divisible by the time you defined and have a lower time frame. this is a TOS limitation
 
Hello, im creating a study where I simply draw horizontal lines for each stock. So each stock I list has a different value.

So as you can see, I will have a list of prices for each stock to draw specific horizontal lines on many charts. I just included 3 stocks for simplicity sake.

But my main question is this. Right now the line is shown to be dotted Orange line for all stocks. Is there anyway to color code the line to show up as ORANGE when P1>current stock close, and GREEN when P1<current stock close?

So for AAON, P1 is 48.95. current price for AAON is 72.74. so the line should be Green. And if the current price was 40, then it would be orange. Not sure how to get this in the code.

Basically im trying to distinguish which is higher, P1, or current price. If I cant change the color of the line, then maybe a chart label? Something to make it more obvious.

thanks in advance!

Code:
AddLabel(No, GetSymbol());
plot p1;
p1.SetDefaultColor(Color.orange);
p1.SetLineWeight(5);
p1.SetStyle(Curve.LONG_DASH);
def nan = Double.NaN;
if (GetSymbol() == "AAON")then {p1 = 48.95;} else
if (GetSymbol() == "AAPL")then {p1 = 85;} else
if (GetSymbol() == "ZTS")then {p1 = 125;} else
{ p1 = nan; ;}
 
You can use the if-else statement. Here's an example:

Code:
plot Data = 350;
Data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Data.AssignValueColor(if close > Data then color.CYAN else color.MAGENTA);

O70cn1U.png
 
Wow, thanks, but how do I incorporate yours? When I try the below, thinkscript is giving me an error on the p1 that I bolded.

Code:
AddLabel(No, GetSymbol());
plot p1;
p1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
p1.AssignValueColor(if close > p1 then color.CYAN else color.MAGENTA);
p1.SetLineWeight(5);
p1.SetStyle(Curve.LONG_DASH);
def nan = Double.NaN;

if (GetSymbol() == "AAON")then {p1 = 48.95;} else
if (GetSymbol() == "AAPL")then {p1 = 85;} else
if (GetSymbol() == "ZTS")then {p1 = 125;} else
{    p1 = nan;    ;}
 
@eugchen Where are you trying to plot "p1" on your chart? You need to specify the level. Look at my example above.

Code:
plot Data = 350;

I'm plotting the line at $350 price level on my chart.
 
Sorry forgive me, I'm a total noobie...i got this code from researching a bit online.

What I believe the code I'm using is to plot p1.

for AAON, p1 = 48.95 (draw a horizontal line at 48.95)
for AAPL, p1 = 85 (draw a horizontal line at 85)

and so forth.

I do see you are plotting a horizontal line at 350, but my price level will change for different stocks.
 
@eugchen The code you provided was not in order. In other words, you were trying to plot "p1" before defining its location.

This should work:

Code:
plot p1 = if (GetSymbol() == "AAON") then 48.95 else if (GetSymbol() == "AAPL") then 85 else if (GetSymbol() == "ZTS") then 125 else double.nan;
p1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
p1.AssignValueColor(if close > p1 then color.CYAN else color.MAGENTA);
 
Benten---THANK YOU!!!!! so helpful!!!

one last thing....on my charts, i like to see some white space to the right. often 20-30 bars of blank space. well in that blank space area, the line is showing up always at cyan. is there anyway to have the entire line either show up as cyan or magenta based on the current price and P1?

so for instance, if P1 = 80 and Last price on stock is 90, then the entire line should show up as Cyan and vice versa if stock less than 80.
 
sorry I wasn't clear. I already have the expansion area.

here's a screenshot of what I'm looking at. since i have the expansion area, its assuming the price in that expansion area is 0 and will always show a cyan line. id like the entire line to be the same as the part of the line to the left, not different colors. hope this clarifies a bit.

Capture1.jpg
 
@eugchen The forums are filled with examples of how to have an indicator line change colors but I would refer you to the standard HullMovingAvg Study that comes with TOS for a working example...
 
Rad14733- will this hullmovingavg make my entire horizontal line one color? That's what I'm looking for.

Ok... Got it... If SetDefaultColor() won't do it then it probably can't be done... The only other thing that "might" work would be trying to use some type of loop to paint ahead... For that you would probably use something like the code below and then set the color as you would for a normal plot... Just spitballing... Perhaps some else knows a better way though...

Ruby:
<loop code>
plot data[-x] = <whatever>;
<color code>
<loop code>
 
Or I'll be ok if the line stops at the current price (where the maroon meets the blue). Is that easier?

Here's the current code btw...I'm sorta confused as to why the line in that blank area is blue?

Code:
plot p1 =

if (GetSymbol() == "AAON") then 48.95 else
if (GetSymbol() == "AAPL") then 85 else
if (GetSymbol() == "ABBV") then 97 else

double.nan;

p1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
p1.SetLineWeight(5);
p1.SetStyle(Curve.POINTS);
p1.AssignValueColor(if close > p1 then color.Dark_red else color.Dark_orange);
 
@eugchen The color of the expansion area is cyan because that is the TOS default chart line color... It shows up that way on every one of my charts expansion area...
 

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