5 month SMA on the 1min

Can you please help me calculate the 5 month SMA to observe it on the 1min and 5 min charts? I mean what numerical value (length) would I enter to plot that 5 month on the 1 min and on the 5 min?)
 
Last edited by a moderator:
Solution
this is very cool! VERY cool workaround. thank you.
1. Is there a way to remove all the extra labels and bubbles and display only the 5m calculated label?
2. Is there a way to scan for PA crossing or being equal to the calculated price?
3. Is is possible to plot the the label conclusion as a line? I could scroll the watchlist to visualize if theres a line...
4. If so- could the condition wizard scan for price interacting with that value?

Again thank you for your time. I love your work. And have and use several of your indicators @halcyonguy Thank you for sharing - I cannot code (yet) so I appreciate the brilliance of this forum.


i redid this study.

1. - removed the extra line and bubbles.
2. - pa ?? , i added a check...
Can you please help me calculate the 5 month SMA to observe it on the 1min and 5 min charts? I mean what numerical value (length) would I enter to plot that 5 month on the 1 min and on the 5 min?)

EDIT 12/2 this study is wrong
it does not find a 5 month average.
i think the different time frame is throwing it off.
maybe it was too late and i went off track and created this, instead of just using an average with a period specified...

making another version

i'll leave it for now. @MerryDay , can delete it if you want to

-------------------------------------

can't
studies need data to calculate. chart studies need bars to get data.
390 1 minute bars / day , 22days/month , 5 months
390 x 22 x 5 = 42,000.
a chart can't display that many bars. maybe 10k

10k / (5 x 22) = 90 round down to 78 ,... 390/78 = 5 min
might be able to do something...?


here is something to experiment with
a label displays the average
bubbles show the values each month
tested it on a day chart

Code:
#x_month_avg

#https://usethinkscript.com/threads/5-month-sma-on-the-1min.17232/

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

def agg = AggregationPeriod.month;
plot cls_m = close(period = agg);


def qty = 5;
def mttl = sum(cls_m,5);

def mo = getmonth();

# is bar within last 5 months on chart ?
def x1 = if (getlastmonth() - mo + 1) <= qty then 1 else 0;

def new_mo = (mo != mo[1]);

# if last bar is < 5 months oway, then add up the 5 months closes
def ttl = if bn == 1 or mo == 1 then 0
 else if x1 and new_mo then ttl[1] + cls_m
 else ttl[1];

def mo_avg = ttl / qty;

addlabel(1, "avg" + qty + " " + mo_avg, color.yellow);

addchartbubble(new_mo, high,
mo + "\n" +
cls_m + "\n" +
ttl + "\n" +
mo_avg
, color.yellow, yes);
#
 
Last edited:
this is very cool! VERY cool workaround. thank you.
1. Is there a way to remove all the extra labels and bubbles and display only the 5m calculated label?
2. Is there a way to scan for PA crossing or being equal to the calculated price?
3. Is is possible to plot the the label conclusion as a line? I could scroll the watchlist to visualize if theres a line...
4. If so- could the condition wizard scan for price interacting with that value?

Again thank you for your time. I love your work. And have and use several of your indicators @halcyonguy Thank you for sharing - I cannot code (yet) so I appreciate the brilliance of this forum.
 
this is very cool! VERY cool workaround. thank you.
1. Is there a way to remove all the extra labels and bubbles and display only the 5m calculated label?
2. Is there a way to scan for PA crossing or being equal to the calculated price?
3. Is is possible to plot the the label conclusion as a line? I could scroll the watchlist to visualize if theres a line...
4. If so- could the condition wizard scan for price interacting with that value?

Again thank you for your time. I love your work. And have and use several of your indicators @halcyonguy Thank you for sharing - I cannot code (yet) so I appreciate the brilliance of this forum.


i redid this study.

1. - removed the extra line and bubbles.
2. - pa ?? , i added a check when price crosses the average
3. - added a plot for the average line
4. - wizard , scan ?? you asked for a chart study. add a formula to be true on every crossing, x


Code:
#x_month_avg_02

#https://usethinkscript.com/threads/5-month-sma-on-the-1min.17232/

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

def agg = AggregationPeriod.month; 
def cls_m = close(period = agg);

input qty = 5;
input averageType = AverageType.SIMPLE;
def Avg = MovingAverage(averageType, cls_m, qty);

input show_average_line = yes;
plot zavg = if show_average_line then avg else na;
zavg.SetDefaultColor(Color.yellow);

addlabel(1, " ", color.black);
addlabel(1, "avg" + qty + " " + avg, color.yellow);

plot z3 = if (close crosses above avg) then low else na;
z3.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z3.SetDefaultColor(Color.green);
z3.setlineweight(2);
z3.hidebubble();

plot z4 = if (close crosses below avg) then high else na;
z4.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
z4.SetDefaultColor(Color.red);
z4.setlineweight(2);
z4.hidebubble();

def x = (close crosses avg);
#
 
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
470 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