looking for traffic lights for when a specific moving average is above another moving average

FreefallJM03

Active member
VIP
Is there a way to do this for the 10 SMA being above the 50 SMA and for the 10 SMA being below the 50 SMA? I am looking for a script that can either do this in a watchlist or put this into stoplights at the top of a chart for the 2Min, 5min, 10min, 15min, 30min, and 60min time periods.
 
Last edited by a moderator:
Is there a way to do this for the 10 SMA being above the 50 SMA and for the 10 SMA being below the 50 SMA? I am looking for a script that can either do this in a watchlist or put this into stoplights at the top of a chart for the 2Min, 5min, 10min, 15min, 30min, and 60min time periods.

Perhaps one of the scripts in this thread, will help you with your quest.
Something like this?
https://usethinkscript.com/threads/mtf-moving-average-dashboard-for-thinkorswim.13911/#post-115774
 
Nope, nothing in there remotely close to what I was looking for. I'm not looking for traffic lights for candlesticks. I am looking for traffic lights for when a specific moving average is above another moving average. Thanks though!

'traffic lights' isn't a function
what do you really want to see?
a row of labels ?
rows of colored dots ?
----------------------

this draws labels , that are green or red.
green if the shorter length average is > longer length average. (for each agg time)
if chart time is > that an agg time, that label is gray. it doesn't cause an error.
can choose different agg times and the labels will display correctly.

Code:
#MTF_avgx_dots

#https://usethinkscript.com/threads/looking-for-traffic-lights-for-when-a-specific-moving-average-is-above-another-moving-average.20431/
#looking for traffic lights for when a specific moving average is above another moving average
#  the 2Min, 5min, 10min, 15min, 30min, and 60min time periods.

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

input agg1 = AggregationPeriod.TWO_MIN;
input agg2 = AggregationPeriod.FIVE_MIN;
input agg3 = AggregationPeriod.TEN_MIN;
input agg4 = AggregationPeriod.FIFTEEN_MIN;
input agg5 = AggregationPeriod.thirty_MIN;
input agg6 = AggregationPeriod.hour;

def chartagg = getaggregationperiod();
def chartmin = chartagg/60000;

# adjust aggs if too small
def agg1b;
if agg1 >= chartagg then {
 agg1b = agg1;
} else {
 agg1b = chartagg;
}
def agg1min = agg1/60000;

def agg2b;
if agg2 >= chartagg then {
 agg2b = agg2;
} else {
 agg2b = chartagg;
}
def agg2min = agg2/60000;

def agg3b;
if agg3 >= chartagg then {
 agg3b = agg3;
} else {
 agg3b = chartagg;
}
def agg3min = agg3/60000;

def agg4b;
if agg4 >= chartagg then {
 agg4b = agg4;
} else {
 agg4b = chartagg;
}
def agg4min = agg4/60000;

def agg5b;
if agg5 >= chartagg then {
 agg5b = agg5;
} else {
 agg5b = chartagg;
}
def agg5min = agg5/60000;

def agg6b;
if agg6 >= chartagg then {
 agg6b = agg6;
} else {
 agg6b = chartagg;
}
def agg6min = agg6/60000;


#Averages
input length1 = 10;
input length2 = 50;
#input avgtype = AverageType.EXPONENTIAL;
input avgtype1 = AverageType.simple;
input avgtype2 = AverageType.simple;
input price   = Fundamentaltype.close;
def ma1_1 = MovingAverage(avgtype1, Fundamental(price, period = agg1b), length1);
def ma1_2 = MovingAverage(avgtype1, Fundamental(price, period = agg2b), length1);
def ma1_3 = MovingAverage(avgtype1, Fundamental(price, period = agg3b), length1);
def ma1_4 = MovingAverage(avgtype1, Fundamental(price, period = agg4b), length1);
def ma1_5 = MovingAverage(avgtype1, Fundamental(price, period = agg5b), length1);
def ma1_6 = MovingAverage(avgtype1, Fundamental(price, period = agg6b), length1);

def ma2_1 = MovingAverage(avgtype2, Fundamental(price, period = agg1b), length2);
def ma2_2 = MovingAverage(avgtype2, Fundamental(price, period = agg2b), length2);
def ma2_3 = MovingAverage(avgtype2, Fundamental(price, period = agg3b), length2);
def ma2_4 = MovingAverage(avgtype2, Fundamental(price, period = agg4b), length2);
def ma2_5 = MovingAverage(avgtype2, Fundamental(price, period = agg5b), length2);
def ma2_6 = MovingAverage(avgtype2, Fundamental(price, period = agg6b), length2);

input show_agg1_average_lines = no;
plot z1_1 = if show_agg1_average_lines then ma1_1 else na;
plot z2_1 = if show_agg1_average_lines then ma2_1 else na;
z1_1.SetDefaultColor(getcolor(0));
#z1_1.setlineweight(1);
z1_1.hidebubble();
z1_1.SetHiding(agg1 < chartagg);
z2_1.SetDefaultColor(getcolor(0));
#z2_1.setlineweight(1);
z2_1.hidebubble();
z2_1.SetHiding(agg1 < chartagg);

input show_agg2_average_lines = no;
plot z1_2 = if show_agg2_average_lines then ma1_2 else na;
plot z2_2 = if show_agg2_average_lines then ma2_2 else na;
z1_2.SetDefaultColor(getcolor(1));
#z1_2.setlineweight(1);
z1_2.hidebubble();
z1_2.SetHiding(agg2 < chartagg);
z2_2.SetDefaultColor(getcolor(1));
#z2_2.setlineweight(1);
z2_2.hidebubble();
z2_2.SetHiding(agg2 < chartagg);

input show_agg3_average_lines = no;
plot z1_3 = if show_agg3_average_lines then ma1_3 else na;
plot z2_3 = if show_agg3_average_lines then ma2_3 else na;
z1_3.SetDefaultColor(getcolor(2));
#z1_3.setlineweight(1);
z1_3.hidebubble();
z1_3.SetHiding(agg3 < chartagg);
z2_3.SetDefaultColor(getcolor(2));
#z2_3.setlineweight(1);
z2_3.hidebubble();
z2_3.SetHiding(agg3 < chartagg);

input show_agg4_average_lines = no;
plot z1_4 = if show_agg4_average_lines then ma1_4 else na;
plot z2_4 = if show_agg4_average_lines then ma2_4 else na;
z1_4.SetDefaultColor(getcolor(3));
#z1_4.setlineweight(1);
z1_4.hidebubble();
z1_4.SetHiding(agg4 < chartagg);
z2_4.SetDefaultColor(getcolor(3));
#z2_4.setlineweight(1);
z2_4.hidebubble();
z2_4.SetHiding(agg4 < chartagg);

input show_agg5_average_lines = no;
plot z1_5 = if show_agg5_average_lines then ma1_5 else na;
plot z2_5 = if show_agg5_average_lines then ma2_5 else na;
z1_5.SetDefaultColor(getcolor(4));
#z1_5.setlineweight(1);
z1_5.hidebubble();
z1_5.SetHiding(agg5 < chartagg);
z2_5.SetDefaultColor(getcolor(4));
#z2_5.setlineweight(1);
z2_5.hidebubble();
z2_5.SetHiding(agg5 < chartagg);

input show_agg6_average_lines = no;
plot z1_6 = if show_agg6_average_lines then ma1_6 else na;
plot z2_6 = if show_agg6_average_lines then ma2_6 else na;
z1_6.SetDefaultColor(getcolor(5));
#z1_6.setlineweight(1);
z1_6.hidebubble();
z1_6.SetHiding(agg6 < chartagg);
z2_6.SetDefaultColor(getcolor(5));
#z2_6.setlineweight(1);
z2_6.hidebubble();
z2_6.SetHiding(agg6 < chartagg);


#==================================
# labels
# average id labels
input ShowLabels = yes;
addlabel(1, " ", color.black);
addlabel(showlabels, 
     (if avgtype1 == AverageType.Simple then "SMA"
 else if avgtype1 == AverageType.exponential then "EMA"
 else if avgtype1 == AverageType.hull then "HULL"
 else if avgtype1 == AverageType.weighted then "WT"
 else if avgtype1 == AverageType.wilders then "WILD"
 else "---") + length1
, color.cyan);

addlabel(showLabels, 
     (if avgtype2 == AverageType.Simple then "SMA"
 else if avgtype2 == AverageType.exponential then "EMA"
 else if avgtype2 == AverageType.hull then "HULL"
 else if avgtype2 == AverageType.weighted then "WT"
 else if avgtype2 == AverageType.wilders then "WILD"
 else "---") + length2
, color.cyan);
addlabel(1, " ", color.black);


# MTF color labels ,  compare 2 avgs
#https://usethinkscript.com/threads/the-multi-10x-mtf-labels-indicator-for-thinkorswim.1129/page-4#post-69106
AddLabel(showlabels,
(if agg1min < 60 then (agg1min + " m")
 else if agg1min < 1440 then ((agg1min / 60) + " H")
 else if agg1min < 10080 then (agg1min / (60 * 24) + " D")
 else "--"),
(if agg1 < chartagg then color.dark_gray else if ma1_1 > ma2_1 then Color.GREEN else Color.RED));

AddLabel(showlabels,
(if agg2min < 60 then (agg2min + " m")
 else if agg2min < 1440 then ((agg2min / 60) + " H")
 else if agg2min < 10080 then (agg2min / (60 * 24) + " D")
 else "--"),
(if agg2 < chartagg then color.dark_gray else if ma1_2 > ma2_2 then Color.GREEN else Color.RED));

AddLabel(showlabels,
(if agg3min < 60 then (agg3min + " m")
 else if agg3min < 1440 then ((agg3min / 60) + " H")
 else if agg3min < 10080 then (agg3min / (60 * 24) + " D")
 else "--"),
(if agg3 < chartagg then color.dark_gray else if ma1_3 > ma2_3 then Color.GREEN else Color.RED));

AddLabel(showlabels,
(if agg4min < 60 then (agg4min + " m")
 else if agg4min < 1440 then ((agg4min / 60) + " H")
 else if agg4min < 10080 then (agg4min / (60 * 24) + " D")
 else "--"),
(if agg4 < chartagg then color.dark_gray else if ma1_4 > ma2_4 then Color.GREEN else Color.RED));

AddLabel(showlabels,
(if agg5min < 60 then (agg5min + " m")
 else if agg5min < 1440 then ((agg5min / 60) + " H")
 else if agg5min < 10080 then (agg5min / (60 * 24) + " D")
 else "--"),
(if agg5 < chartagg then color.dark_gray else if ma1_5 > ma2_5 then Color.GREEN else Color.RED));

AddLabel(showlabels,
(if agg6min < 60 then (agg6min + " m")
 else if agg6min < 1440 then ((agg6min / 60) + " H")
 else if agg6min < 10080 then (agg6min / (60 * 24) + " D")
 else "--"),
(if agg6 < chartagg then color.dark_gray else if ma1_6 > ma2_6 then Color.GREEN else Color.RED));

addlabel(1, " ", color.black);
#
 

Attachments

  • img1.JPG
    img1.JPG
    105.9 KB · Views: 15
Last edited:
Thanks Halcyonguy. I am trying it out now. Looks like it will be very, very, very helpful for my trading strategy. This way I don't always have to be watching the other charts on the higher time frames.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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