Repaints MTF Moving Average Labels For ThinkOrSwim

Repaints
Has anyone created or can anyone create script that I can add a few daily moving averages lables to a smaller timeframe screen?
I would like to have the choice between sma/ema
 
Has anyone created or can anyone create script that I can add a few daily moving averages lables to a smaller timeframe screen?
I would like to have the choice between sma/ema


you didn't say what you want to see in the label, so i guessed on a couple layouts

pick 4 averages,
type, length, 2nd aggregation time
can choose to show the lines

2 sets of labels

set 1 of labels show,
. avg#
. the average price on last bar
. green or red, depending on the price change since previous bar


set 2 of labels show , EMA9(2H),
. type of average
. length of average
. 2nd agg time
. green or red, depending on the price change since previous bar


Code:
# average_labels_00

# several labels of average stats

def na = Double.NaN;
def bn = BarNumber();

input average1_len = 9;
input average1_type =  AverageType.EXPONENTIAL;
input average1_agg_time = AggregationPeriod.DAY;
def agg1min = average1_agg_time/60000;
def avg1 = Round(MovingAverage(average1_type, close(period = average1_agg_time), average1_len), 2);

input average2_len = 21;
input average2_type =  AverageType.EXPONENTIAL;
input average2_agg_time = AggregationPeriod.DAY;
def agg2min = average2_agg_time/60000;
def avg2 = Round(MovingAverage(average2_type, close(period = average2_agg_time), average2_len), 2);

input average3_len = 50;
input average3_type =  AverageType.EXPONENTIAL;
input average3_agg_time = AggregationPeriod.DAY;
def agg3min = average3_agg_time/60000;
def avg3 = Round(MovingAverage(average3_type, close(period = average3_agg_time), average3_len), 2);

input average4_len = 100;
input average4_type =  AverageType.EXPONENTIAL;
input average4_agg_time = AggregationPeriod.DAY;
def agg4min = average4_agg_time/60000;
def avg4 = Round(MovingAverage(average4_type, close(period = average2_agg_time), average4_len), 2);


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

def avg1up = (avg1 > avg1[1]);
def avg2up = (avg2 > avg2[1]);
def avg3up = (avg3 > avg3[1]);
def avg4up = (avg4 > avg4[1]);

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

input show_labels_1 = yes;
AddLabel(show_labels_1, " " , Color.BLACK);
AddLabel(show_labels_1, "Avg1 " + avg1, (if avg1up then Color.GREEN else Color.RED));
AddLabel(show_labels_1, "Avg2 " + avg2, (if avg2up then Color.GREEN else Color.RED));
AddLabel(show_labels_1, "Avg3 " + avg3, (if avg3up then Color.GREEN else Color.RED));
AddLabel(show_labels_1, "Avg4 " + avg4, (if avg4up then Color.GREEN else Color.RED));
AddLabel(show_labels_1, " " , Color.BLACK);

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

input show_labels_2 = yes;
AddLabel(show_labels_2, " " , Color.BLACK);

AddLabel(show_labels_2,
 (if average1_type == AverageType.SIMPLE then "SMA"
  else if average1_type == AverageType.EXPONENTIAL then "EMA"
  else if average1_type == AverageType.WEIGHTED then "WT"
  else if average1_type == AverageType.WILDERS then "WLD"
  else if average1_type == AverageType.HULL then "HUL"
  else "-")
    + average1_len + "(" +
  (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 average1_type == aggregationPeriod.MONTH then "M"
  else if average1_type == aggregationPeriod.WEEK then "W"
  else "" ) + ")"
,(if avg1up then Color.GREEN else Color.RED));

AddLabel(show_labels_2,
 (if average2_type == AverageType.SIMPLE then "SMA"
  else if average2_type == AverageType.EXPONENTIAL then "EMA"
  else if average2_type == AverageType.WEIGHTED then "WT"
  else if average2_type == AverageType.WILDERS then "WLD"
  else if average2_type == AverageType.HULL then "HUL"
  else "-")
  + average2_len + "(" +
  (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 average2_type == aggregationPeriod.MONTH then "M"
  else if average2_type == aggregationPeriod.WEEK then "W"
  else "" ) + ")"
,(if avg2up then Color.GREEN else Color.RED));

AddLabel(show_labels_2,
 (if average3_type == AverageType.SIMPLE then "SMA"
  else if average3_type == AverageType.EXPONENTIAL then "EMA"
  else if average3_type == AverageType.WEIGHTED then "WT"
  else if average3_type == AverageType.WILDERS then "WLD"
  else if average3_type == AverageType.HULL then "HUL"
  else "-")
  + average3_len + "(" +
  (if agg3min < 60 then (agg1min + "m")
  else if agg3min < 1440 then ((agg3min/60) + "H")
  else if agg3min < 10080 then (agg3min/(60*24) + "D")
  else if average3_type == aggregationPeriod.MONTH then "M"
  else if average3_type == aggregationPeriod.WEEK then "W"
  else "" ) + ")"
, (if avg3up then Color.GREEN else Color.RED));

AddLabel(show_labels_2,
 (if average4_type == AverageType.SIMPLE then "SMA"
  else if average4_type == AverageType.EXPONENTIAL then "EMA"
  else if average4_type == AverageType.WEIGHTED then "WT"
  else if average4_type == AverageType.WILDERS then "WLD"
  else if average4_type == AverageType.HULL then "HUL"
  else "-")
  + average4_len + "(" +
  (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 average4_type == aggregationPeriod.MONTH then "M"
  else if average4_type == aggregationPeriod.WEEK then "W"
  else "" ) + ")"
, (if avg4up then Color.GREEN else Color.RED));


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

input show_lines = yes;
plot z1 = if show_lines then avg1 else na;
z1.SetDefaultColor(GetColor(1));
#z1.setlineweight(1);
z1.HideBubble();

plot z2 = if show_lines then avg2 else na;
z2.SetDefaultColor(GetColor(2));
#z2.setlineweight(1);
z2.HideBubble();

plot z3 = if show_lines then avg3 else na;
z3.SetDefaultColor(GetColor(3));
#z3.setlineweight(1);
z3.HideBubble();

plot z4 = if show_lines then avg4 else na;
z4.SetDefaultColor(GetColor(4));
#z4.setlineweight(1);
z4.HideBubble();

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

def stackup = (avg1 > avg2 and avg2 > avg3 and avg3 > avg4);
def stackdwn = (avg1 < avg2 and avg2 < avg3 and avg3 < avg4);

input show_stacked_averages_cloud = no;
AddCloud((if show_stacked_averages_cloud and stackup then avg1 else na), avg4,  Color.LIGHT_GREEN,  Color.MAGENTA);
AddCloud((if show_stacked_averages_cloud and stackdwn then avg4 else na), avg1,  Color.LIGHT_RED,  Color.MAGENTA);
#

vvMkHC8.jpg
 
you didn't say what you want to see in the label, so i guessed on a couple layouts

pick 4 averages,
type, length, 2nd aggregation time
can choose to show the lines

2 sets of labels

set 1 of labels show,
. avg#
. the average price on last bar
. green or red, depending on the price change since previous bar


set 2 of labels show , EMA9(2H),
. type of average
. length of average
. 2nd agg time
. green or red, depending on the price change since previous bar


Code:
# average_labels_00

# several labels of average stats

def na = Double.NaN;
def bn = BarNumber();

input average1_len = 9;
input average1_type =  AverageType.EXPONENTIAL;
input average1_agg_time = AggregationPeriod.DAY;
def agg1min = average1_agg_time/60000;
def avg1 = Round(MovingAverage(average1_type, close(period = average1_agg_time), average1_len), 2);

input average2_len = 21;
input average2_type =  AverageType.EXPONENTIAL;
input average2_agg_time = AggregationPeriod.DAY;
def agg2min = average2_agg_time/60000;
def avg2 = Round(MovingAverage(average2_type, close(period = average2_agg_time), average2_len), 2);

input average3_len = 50;
input average3_type =  AverageType.EXPONENTIAL;
input average3_agg_time = AggregationPeriod.DAY;
def agg3min = average3_agg_time/60000;
def avg3 = Round(MovingAverage(average3_type, close(period = average3_agg_time), average3_len), 2);

input average4_len = 100;
input average4_type =  AverageType.EXPONENTIAL;
input average4_agg_time = AggregationPeriod.DAY;
def agg4min = average4_agg_time/60000;
def avg4 = Round(MovingAverage(average4_type, close(period = average2_agg_time), average4_len), 2);


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

def avg1up = (avg1 > avg1[1]);
def avg2up = (avg2 > avg2[1]);
def avg3up = (avg3 > avg3[1]);
def avg4up = (avg4 > avg4[1]);

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

input show_labels_1 = yes;
AddLabel(show_labels_1, " " , Color.BLACK);
AddLabel(show_labels_1, "Avg1 " + avg1, (if avg1up then Color.GREEN else Color.RED));
AddLabel(show_labels_1, "Avg2 " + avg2, (if avg2up then Color.GREEN else Color.RED));
AddLabel(show_labels_1, "Avg3 " + avg3, (if avg3up then Color.GREEN else Color.RED));
AddLabel(show_labels_1, "Avg4 " + avg4, (if avg4up then Color.GREEN else Color.RED));
AddLabel(show_labels_1, " " , Color.BLACK);

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

input show_labels_2 = yes;
AddLabel(show_labels_2, " " , Color.BLACK);

AddLabel(show_labels_2,
 (if average1_type == AverageType.SIMPLE then "SMA"
  else if average1_type == AverageType.EXPONENTIAL then "EMA"
  else if average1_type == AverageType.WEIGHTED then "WT"
  else if average1_type == AverageType.WILDERS then "WLD"
  else if average1_type == AverageType.HULL then "HUL"
  else "-")
    + average1_len + "(" +
  (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 average1_type == aggregationPeriod.MONTH then "M"
  else if average1_type == aggregationPeriod.WEEK then "W"
  else "" ) + ")"
,(if avg1up then Color.GREEN else Color.RED));

AddLabel(show_labels_2,
 (if average2_type == AverageType.SIMPLE then "SMA"
  else if average2_type == AverageType.EXPONENTIAL then "EMA"
  else if average2_type == AverageType.WEIGHTED then "WT"
  else if average2_type == AverageType.WILDERS then "WLD"
  else if average2_type == AverageType.HULL then "HUL"
  else "-")
  + average2_len + "(" +
  (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 average2_type == aggregationPeriod.MONTH then "M"
  else if average2_type == aggregationPeriod.WEEK then "W"
  else "" ) + ")"
,(if avg2up then Color.GREEN else Color.RED));

AddLabel(show_labels_2,
 (if average3_type == AverageType.SIMPLE then "SMA"
  else if average3_type == AverageType.EXPONENTIAL then "EMA"
  else if average3_type == AverageType.WEIGHTED then "WT"
  else if average3_type == AverageType.WILDERS then "WLD"
  else if average3_type == AverageType.HULL then "HUL"
  else "-")
  + average3_len + "(" +
  (if agg3min < 60 then (agg1min + "m")
  else if agg3min < 1440 then ((agg3min/60) + "H")
  else if agg3min < 10080 then (agg3min/(60*24) + "D")
  else if average3_type == aggregationPeriod.MONTH then "M"
  else if average3_type == aggregationPeriod.WEEK then "W"
  else "" ) + ")"
, (if avg3up then Color.GREEN else Color.RED));

AddLabel(show_labels_2,
 (if average4_type == AverageType.SIMPLE then "SMA"
  else if average4_type == AverageType.EXPONENTIAL then "EMA"
  else if average4_type == AverageType.WEIGHTED then "WT"
  else if average4_type == AverageType.WILDERS then "WLD"
  else if average4_type == AverageType.HULL then "HUL"
  else "-")
  + average4_len + "(" +
  (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 average4_type == aggregationPeriod.MONTH then "M"
  else if average4_type == aggregationPeriod.WEEK then "W"
  else "" ) + ")"
, (if avg4up then Color.GREEN else Color.RED));


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

input show_lines = yes;
plot z1 = if show_lines then avg1 else na;
z1.SetDefaultColor(GetColor(1));
#z1.setlineweight(1);
z1.HideBubble();

plot z2 = if show_lines then avg2 else na;
z2.SetDefaultColor(GetColor(2));
#z2.setlineweight(1);
z2.HideBubble();

plot z3 = if show_lines then avg3 else na;
z3.SetDefaultColor(GetColor(3));
#z3.setlineweight(1);
z3.HideBubble();

plot z4 = if show_lines then avg4 else na;
z4.SetDefaultColor(GetColor(4));
#z4.setlineweight(1);
z4.HideBubble();

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

def stackup = (avg1 > avg2 and avg2 > avg3 and avg3 > avg4);
def stackdwn = (avg1 < avg2 and avg2 < avg3 and avg3 < avg4);

input show_stacked_averages_cloud = no;
AddCloud((if show_stacked_averages_cloud and stackup then avg1 else na), avg4,  Color.LIGHT_GREEN,  Color.MAGENTA);
AddCloud((if show_stacked_averages_cloud and stackdwn then avg4 else na), avg1,  Color.LIGHT_RED,  Color.MAGENTA);
#

vvMkHC8.jpg
THANK YOU!
 

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
389 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