Plot indicator on SPY chart if Bars on other tickers are in agreement

jrock8903

New member
Currently watch 4-5 other tickers when trading SPY in another window. If all are green and there is a good entry on SPY I go long, if they are Red and SPY is week, I go short on appropriate price action.
Looking for some sort of indicator that I can use to plot an arrow when all of the watched tickers are in agreement on the SPY chart. For instance watching TSLA 3 minute, QQQ one minute, AMZN 3 min, and MSFT 5 minute, if all are showing green and there is a pullback on SPY to support, I look to enter calls. Be nice if I could just have an arrow or something plot on the SPY chart when all the Tickers are in agreement instead of having to watch two different windows. Is this even possible?
 
Last edited:
Solution
Currently watch 4-5 other tickers when trading SPY in another window. If all are green and there is a good entry on SPY I go long, if they are Red and SPY is week, I go short on appropriate price action.
Looking for some sort of indicator that I can use to plot an arrow when all of the watched tickers are in agreement on the SPY chart. For instance watching TSLA 3 minute, QQQ one minute, AMZN 3 min, and MSFT 5 minute, if all are showing green and there is a pullback on SPY to support, I look to enter calls. Be nice if I could just have an arrow or something plot on the SPY chart when all the Tickers are in agreement instead of having to watch two different windows. Is this even possible?


this will allow user to pick up to...
Currently watch 4-5 other tickers when trading SPY in another window. If all are green and there is a good entry on SPY I go long, if they are Red and SPY is week, I go short on appropriate price action.
Looking for some sort of indicator that I can use to plot an arrow when all of the watched tickers are in agreement on the SPY chart. For instance watching TSLA 3 minute, QQQ one minute, AMZN 3 min, and MSFT 5 minute, if all are showing green and there is a pullback on SPY to support, I look to enter calls. Be nice if I could just have an arrow or something plot on the SPY chart when all the Tickers are in agreement instead of having to watch two different windows. Is this even possible?


this will allow user to pick up to 5 stocks and a 2nd aggregation time for each.
it determines if those bars are up (close > open) or down.
a dot is drawn for each stock, under each bar, green red, or gray.
if all are up , then a green triangle is drawn above the bar. if all are down, then red.

there is a stock to pick to exclude. since you want to compare to SPY, i used SPY as the ignore symbol.
so if an input symbol is SPY, that stock data will be ignored.


Code:
# monitor_x_symbols_compare_spy

#new
#https://usethinkscript.com/threads/plot-indicator-on-spy-chart-if-bars-on-other-tickers-are-in-agreement.15780/

#--------------------------

def na = double.nan;
def bn = barnumber();

input Symbol1 = "TSLA";
def agg1 = AggregationPeriod.five_min;
def s1o = open(Symbol1, period = agg1);
def s1c = close(Symbol1, period = agg1);

input Symbol2 = "QQQ";
def agg2 = AggregationPeriod.five_min;
def s2o = open(Symbol2, period = agg2);
def s2c = close(Symbol2, period = agg2);

input Symbol3 = "SPY";
def agg3 = AggregationPeriod.five_min;
def s3o = open(Symbol3, period = agg3);
def s3c = close(Symbol3, period = agg3);

input Symbol4 = "SPY";
def agg4 = AggregationPeriod.five_min;
def s4o = open(Symbol4, period = agg4);
def s4c = close(Symbol4, period = agg4);

input Symbol5 = "SPY";
def agg5 = AggregationPeriod.five_min;
def s5o = open(Symbol5, period = agg5);
def s5c = close(Symbol5, period = agg5);


input exclude_symbol = "SPY";
def s1ok = if  Symbol1 == exclude_symbol then 0 else 1;
def s2ok = if  Symbol2 == exclude_symbol then 0 else 1;
def s3ok = if  Symbol3 == exclude_symbol then 0 else 1;
def s4ok = if  Symbol4 == exclude_symbol then 0 else 1;
def s5ok = if  Symbol5 == exclude_symbol then 0 else 1;

def cntok = s1ok + s2ok + s3ok + s4ok + s5ok;

def s1up = s1ok and s1c > s1o;
def s2up = s2ok and s2c > s2o;
def s3up = s3ok and s3c > s3o;
def s4up = s4ok and s4c > s4o;
def s5up = s5ok and s5c > s5o;

def s1dwn = s1ok and s1c < s1o;
def s2dwn = s2ok and s2c < s2o;
def s3dwn = s3ok and s3c < s3o;
def s4dwn = s4ok and s4c < s4o;
def s5dwn = s5ok and s5c < s5o;


#-------------
# inputs - below bars

input show_input_dots = yes;
def vert = 0.0004;

plot z1 = if show_input_dots and s1ok then low * (1 - (1*vert)) else na;
z1.SetPaintingStrategy(PaintingStrategy.POINTS);
z1.SetLineWeight(3);
z1.AssignValueColor(if s1up then Color.GREEN else if s1dwn then Color.RED else Color.GRAY);
z1.hidebubble();

plot z2 = if show_input_dots and s2ok then low * (1 - (2*vert)) else na;
z2.SetPaintingStrategy(PaintingStrategy.POINTS);
z2.SetLineWeight(3);
z2.AssignValueColor(if s2up then Color.GREEN else if s2dwn then Color.RED else Color.GRAY);
z2.hidebubble();

plot z3 = if show_input_dots and s3ok then low * (1 - (3*vert)) else na;
z3.SetPaintingStrategy(PaintingStrategy.POINTS);
z3.SetLineWeight(3);
z3.AssignValueColor(if s3up then Color.GREEN else if s3dwn then Color.RED else Color.GRAY);
z3.hidebubble();

plot z4 = if show_input_dots and s4ok then low * (1 - (4*vert)) else na;
z4.SetPaintingStrategy(PaintingStrategy.POINTS);
z4.SetLineWeight(3);
z4.AssignValueColor(if s4up then Color.GREEN else if s4dwn then Color.RED else Color.GRAY);
z4.hidebubble();

plot z5 = if show_input_dots and s5ok then low * (1 - (5*vert)) else na;
z5.SetPaintingStrategy(PaintingStrategy.POINTS);
z5.SetLineWeight(3);
z5.AssignValueColor(if s5up then Color.GREEN else if s5dwn then Color.RED else Color.GRAY);
z5.hidebubble();


#-------------------------
# output - above bars

def outup = (s1ok and s1up) + (s2ok and s2up) + (s3ok and s3up) + (s4ok and s4up) + (s5ok and s5up);
def outdwn = (s1ok and s1dwn) + (s2ok and s2dwn) + (s3ok and s3dwn) + (s4ok and s4dwn) + (s5ok and s5dwn);

input show_output_dot = yes;

plot zz1 = if show_output_dot and ((outup == cntok) or (outdwn == cntok)) then high * (1 + (1*vert)) else na;
zz1.SetPaintingStrategy(PaintingStrategy.triangles);
zz1.SetLineWeight(3);
zz1.AssignValueColor(if (outup == cntok) then Color.GREEN else if (outdwn == cntok) then Color.RED else Color.GRAY);
zz1.hidebubble();

#------------------

addlabel(1, "  ", color.black);
input show_labels = yes;
addlabel(show_labels and s1ok, Symbol1, color.yellow);
addlabel(show_labels and s2ok, Symbol2, color.yellow);
addlabel(show_labels and s3ok, Symbol3, color.yellow);
addlabel(show_labels and s4ok, Symbol4, color.yellow);
addlabel(show_labels and s5ok, Symbol5, color.yellow);
#

xcc118W.jpg
 
Solution

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

this will allow user to pick up to 5 stocks and a 2nd aggregation time for each.
it determines if those bars are up (close > open) or down.
a dot is drawn for each stock, under each bar, green red, or gray.
if all are up , then a green triangle is drawn above the bar. if all are down, then red.

there is a stock to pick to exclude. since you want to compare to SPY, i used SPY as the ignore symbol.
so if an input symbol is SPY, that stock data will be ignored.


Code:
# monitor_x_symbols_compare_spy

#new
#https://usethinkscript.com/threads/plot-indicator-on-spy-chart-if-bars-on-other-tickers-are-in-agreement.15780/

#--------------------------

def na = double.nan;
def bn = barnumber();

input Symbol1 = "TSLA";
def agg1 = AggregationPeriod.five_min;
def s1o = open(Symbol1, period = agg1);
def s1c = close(Symbol1, period = agg1);

input Symbol2 = "QQQ";
def agg2 = AggregationPeriod.five_min;
def s2o = open(Symbol2, period = agg2);
def s2c = close(Symbol2, period = agg2);

input Symbol3 = "SPY";
def agg3 = AggregationPeriod.five_min;
def s3o = open(Symbol3, period = agg3);
def s3c = close(Symbol3, period = agg3);

input Symbol4 = "SPY";
def agg4 = AggregationPeriod.five_min;
def s4o = open(Symbol4, period = agg4);
def s4c = close(Symbol4, period = agg4);

input Symbol5 = "SPY";
def agg5 = AggregationPeriod.five_min;
def s5o = open(Symbol5, period = agg5);
def s5c = close(Symbol5, period = agg5);


input exclude_symbol = "SPY";
def s1ok = if  Symbol1 == exclude_symbol then 0 else 1;
def s2ok = if  Symbol2 == exclude_symbol then 0 else 1;
def s3ok = if  Symbol3 == exclude_symbol then 0 else 1;
def s4ok = if  Symbol4 == exclude_symbol then 0 else 1;
def s5ok = if  Symbol5 == exclude_symbol then 0 else 1;

def cntok = s1ok + s2ok + s3ok + s4ok + s5ok;

def s1up = s1ok and s1c > s1o;
def s2up = s2ok and s2c > s2o;
def s3up = s3ok and s3c > s3o;
def s4up = s4ok and s4c > s4o;
def s5up = s5ok and s5c > s5o;

def s1dwn = s1ok and s1c < s1o;
def s2dwn = s2ok and s2c < s2o;
def s3dwn = s3ok and s3c < s3o;
def s4dwn = s4ok and s4c < s4o;
def s5dwn = s5ok and s5c < s5o;


#-------------
# inputs - below bars

input show_input_dots = yes;
def vert = 0.0004;

plot z1 = if show_input_dots and s1ok then low * (1 - (1*vert)) else na;
z1.SetPaintingStrategy(PaintingStrategy.POINTS);
z1.SetLineWeight(3);
z1.AssignValueColor(if s1up then Color.GREEN else if s1dwn then Color.RED else Color.GRAY);
z1.hidebubble();

plot z2 = if show_input_dots and s2ok then low * (1 - (2*vert)) else na;
z2.SetPaintingStrategy(PaintingStrategy.POINTS);
z2.SetLineWeight(3);
z2.AssignValueColor(if s2up then Color.GREEN else if s2dwn then Color.RED else Color.GRAY);
z2.hidebubble();

plot z3 = if show_input_dots and s3ok then low * (1 - (3*vert)) else na;
z3.SetPaintingStrategy(PaintingStrategy.POINTS);
z3.SetLineWeight(3);
z3.AssignValueColor(if s3up then Color.GREEN else if s3dwn then Color.RED else Color.GRAY);
z3.hidebubble();

plot z4 = if show_input_dots and s4ok then low * (1 - (4*vert)) else na;
z4.SetPaintingStrategy(PaintingStrategy.POINTS);
z4.SetLineWeight(3);
z4.AssignValueColor(if s4up then Color.GREEN else if s4dwn then Color.RED else Color.GRAY);
z4.hidebubble();

plot z5 = if show_input_dots and s5ok then low * (1 - (5*vert)) else na;
z5.SetPaintingStrategy(PaintingStrategy.POINTS);
z5.SetLineWeight(3);
z5.AssignValueColor(if s5up then Color.GREEN else if s5dwn then Color.RED else Color.GRAY);
z5.hidebubble();


#-------------------------
# output - above bars

def outup = (s1ok and s1up) + (s2ok and s2up) + (s3ok and s3up) + (s4ok and s4up) + (s5ok and s5up);
def outdwn = (s1ok and s1dwn) + (s2ok and s2dwn) + (s3ok and s3dwn) + (s4ok and s4dwn) + (s5ok and s5dwn);

input show_output_dot = yes;

plot zz1 = if show_output_dot and ((outup == cntok) or (outdwn == cntok)) then high * (1 + (1*vert)) else na;
zz1.SetPaintingStrategy(PaintingStrategy.triangles);
zz1.SetLineWeight(3);
zz1.AssignValueColor(if (outup == cntok) then Color.GREEN else if (outdwn == cntok) then Color.RED else Color.GRAY);
zz1.hidebubble();

#------------------

addlabel(1, "  ", color.black);
input show_labels = yes;
addlabel(show_labels and s1ok, Symbol1, color.yellow);
addlabel(show_labels and s2ok, Symbol2, color.yellow);
addlabel(show_labels and s3ok, Symbol3, color.yellow);
addlabel(show_labels and s4ok, Symbol4, color.yellow);
addlabel(show_labels and s5ok, Symbol5, color.yellow);
#

xcc118W.jpg
IS IT POSSIBLE TO CHANGE THE TIME FRAM FOR EACH STOCK
 
@DAB721 I have not found any other scripts that will do what I want. You can change the time frames of the stocks you are watching by modifying the code, but this study seems to only work on the 1 minute chart.
Not sure how to make it so that it can be used on other timeframe charts.

Example for changing from Five to three minutes
old
input Symbol1 = "TSLA";
def agg1 = AggregationPeriod.five_min;
def s1o = open(Symbol1, period = agg1);
def s1c = close(Symbol1, period = agg1);
new
input Symbol1 = "TSLA";
def agg1 = AggregationPeriod.three_min;
def s1o = open(Symbol1, period = agg1);
def s1c = close(Symbol1, period = agg1);

Ideally I'd like it to only print one arrow at the time everything aligns, then the next arrow when it aligns in the opposite direction. This study can make the chart very busy, but I've put it in a lower study and that seems to work for me.

Much appreciated halcyonguy!
 
@MerryDay is there a way to get this to work on charts besides the one minute?
The ToS platform will ONLY allow HIGHER timeframes to be plotted on LOWER aggregation charts.

Therefore, if you set your secondary aggregations to 5min. It can ONLY be plotted on charts of 5 minutes and LOWER.

In answer to your question, No.
The ToS has no provision, no capability, no workarounds for plotting lower timeframes on higher aggregation charts.
 
The ToS platform will ONLY allow HIGHER timeframes to be plotted on LOWER aggregation charts.

Therefore, if you set your secondary aggregations to 5min. It can ONLY be plotted on charts of 5 minutes and LOWER.

In answer to your question, No.
The ToS has no provision, no capability, no workarounds for plotting lower timeframes on higher aggregation charts.
That would mean though I could set the MIN aggregation to TWO_MIN and use on a Two Minute chart? I'll have to change it and do some Back Testing... thank you!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
449 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