Weekly SMA to only show up on weekly time-frame chart

samerjb

New member
Hay. I am using DailySMA to view SMA on the daily charts only. I would like to use weekly SMA only on the weekly time-frames but could not find WeeklySMA. Using SimpelMovingAvg with weekly aggregation period will plot an indicator on all (D, W & M) charts.


Can you share a code for that & for monthly time frames as well. Thanks in advance.

Sam
 
Solution
Hay. I am using DailySMA to view SMA on the daily charts only. I would like to use weekly SMA only on the weekly time-frames but could not find WeeklySMA. Using SimpelMovingAvg with weekly aggregation period will plot an indicator on all (D, W & M) charts.

Can you share a code for that & for monthly time frames as well. Thanks in advance.


can pick any 2nd aggregation time for use in an average.
show the line when the average time matches the chart time.

can choose to always show the average line.
labels display agg times and change colors. colors based on matching times and always show.

average time has to be greater than the chart time.

Code:
# mtf_avg_only_on_same_mtf_00

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

#...
Hay. I am using DailySMA to view SMA on the daily charts only. I would like to use weekly SMA only on the weekly time-frames but could not find WeeklySMA. Using SimpelMovingAvg with weekly aggregation period will plot an indicator on all (D, W & M) charts.

Can you share a code for that & for monthly time frames as well. Thanks in advance.


can pick any 2nd aggregation time for use in an average.
show the line when the average time matches the chart time.

can choose to always show the average line.
labels display agg times and change colors. colors based on matching times and always show.

average time has to be greater than the chart time.

Code:
# mtf_avg_only_on_same_mtf_00

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

# choose when to show avg
input show_2nd_agg_average_only_when_chart_time_matches = yes;
def show_2 = show_2nd_agg_average_only_when_chart_time_matches;

# choose 2nd agg for average
#input average_agg = AggregationPeriod.HOUR;
input average_agg = AggregationPeriod.week;
def avgaggmin = (average_agg / 60000);

# get agg of the chart
def chartagg = GetAggregationPeriod();
def chartmin = (chartagg / 1000) / 60;

# compare chart agg to avg agg
def issameagg = (chartmin == avgaggmin);

def show_avg = if !show_2 then 1 else issameagg;

def cls1 = close(period = average_agg);
#def cls1 = close;
input ma1_len = 10;
input ma1_type =  AverageType.simple;
def ma1 = MovingAverage(ma1_type, cls1, ma1_len);

plot z1 = if show_avg then ma1 else na;
z1.SetDefaultColor(color.yellow);
#z1.setlineweight(1);
z1.HideBubble();


input agg_labels = yes;
AddLabel(agg_labels, "  ", Color.black);

AddLabel(agg_labels, "Average 2nd agg time " +
  (if avgaggmin < 60 then (avgaggmin + " m")
  else if avgaggmin < 1440 then ((avgaggmin/60) + " H")
  else if avgaggmin < 10080 then (avgaggmin/(60*24) + " Day")
  else if average_agg == aggregationPeriod.MONTH then "Month"
  else if average_agg == aggregationPeriod.WEEK then "Week"
  else "")
, Color.cyan);

AddLabel(agg_labels, "Chart time " +
 (if chartmin < 60 then (chartmin + " m")
  else if chartmin < 1440 then ((chartmin/60) + " H")
  else if chartmin < 10080 then (chartmin/(60*24) + " Day")
  else if chartagg == aggregationPeriod.MONTH then "Month"
  else if chartagg == aggregationPeriod.WEEK then "Week"
  else ""),
(if issameagg then color.green else if !show_2 then Color.YELLOW else color.cyan));

AddLabel(agg_labels and !show_2, "always show avarage", (if !show_2 then Color.YELLOW else color.cyan));


# ----------  ref stuff -------------------------
#https://usethinkscript.com/threads/the-multi-10x-mtf-labels-indicator-for-thinkorswim.1129/page-4#post-69106

# https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AverageType
# ..AverageTypes..
# EXPONENTIAL
# HULL
# SIMPLE
# WEIGHTED
# WILDERS
#

average time = week
chart time = day
show average only when times match = no
IbDBmWX.jpg
 
Solution

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