Daily SMA Indicator for ThinkorSwim (with Alerts)

This isn't any kind of groundbreaking code, but I thought it might save somebody a little time.

This study posts up to four Hourly SMAs, and five Daily SMAs, as well as the previous day's High, Low, and Close on one chart. It gives alerts when price crosses the moving averages. User can choose the length of the Moving Averages.

The main benefit is that you can see the hourly / daily moving averages on any smaller time frame charts, without making adjustments.

I usually combine this study with daily and weekly pivot point studies, and before each session I take notice of areas where multiple "levels" intersect, and also which moving averages seem to be most relevant to my timeframe. I turn off alerts for any SMAs that don't seem to be relevant.

Hope this is helpful.

cs6sbFv.png


Code:
#DS_Levels
#Combines many important daily and hourly levels in one study
#Copyright Confluence Capital Group
#2018-04-19

#Saving CPU
declare once_per_bar;


#User Inputs
input HourlySMAPeriod1 = 20;
input HourlySMAPeriod2 = 50;
input HourlySMAPeriod3 = 100;
input HourlySMAPeriod4 = 200;
input DailySMAPeriod1 = 10;
input DailySMAPeriod2 = 20;
input DailySMAPeriod3 = 50;
input DailySMAPeriod4 = 100;
input DailySMAPeriod5 = 200;
input ShowOnlyToday = yes;

#Definitions
def HourlyClose = close(period = AggregationPeriod.HOUR);
def DailyClose = close(period = AggregationPeriod.DAY);


#Plots
plot HourlySMA1 = Average(HourlyClose, HourlySMAPeriod1);
plot HourlySMA2 = Average(HourlyClose, HourlySMAPeriod2);
plot HourlySMA3 = Average(HourlyClose, HourlySMAPeriod3);
plot HourlySMA4 = Average(HourlyClose, HourlySMAPeriod4);

plot DailySMA1 = Average(DailyClose, DailySMAPeriod1);
plot DailySMA2 = Average(DailyClose, DailySMAPeriod2);
plot DailySMA3 = Average(DailyClose, DailySMAPeriod3);
plot DailySMA4 = Average(DailyClose, DailySMAPeriod4);
plot DailySMA5 = Average(DailyClose, DailySMAPeriod5);

plot YesterdayHigh = high(period = AggregationPeriod.DAY)[1];
plot YesterdayLow = low(period = AggregationPeriod.DAY)[1];
plot YesterdayClose = close(period = AggregationPeriod.DAY)[1];


#Format Plots
HourlySMA1.SetDefaultColor(Color.CYAN);
HourlySMA1.SetLineWeight(1);

HourlySMA2.SetDefaultColor(Color.ORANGE);
HourlySMA2.SetLineWeight(1);

HourlySMA3.SetDefaultColor(Color.PINK);
HourlySMA3.SetLineWeight(1);

HourlySMA4.SetDefaultColor(Color.GRAY);
HourlySMA4.SetLineWeight(1);

DailySMA1.SetDefaultColor(Color.PLUM);
DailySMA1.SetLineWeight(2);
DailySMA1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DailySMA2.SetDefaultColor(Color.CYAN);
DailySMA2.SetLineWeight(2);
DailySMA2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DailySMA3.SetDefaultColor(Color.ORANGE);
DailySMA3.SetLineWeight(2);
DailySMA3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DailySMA4.SetDefaultColor(Color.PINK);
DailySMA4.SetLineWeight(2);
DailySMA4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DailySMA5.SetDefaultColor(Color.GRAY);
DailySMA5.SetLineWeight(2);
DailySMA5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

YesterdayHigh.SetDefaultColor(Color.GREEN);
YesterdayLow.SetDefaultColor(Color.RED);
YesterdayClose.SetDefaultColor(Color.DARK_GRAY);

#Chart Bubbles
def LastBar = !IsNaN(open) and IsNaN(open [-1] ) ;
def BubbleLocation = LastBar[10];

AddChartBubble(BubbleLocation, DailySMA1, DailySMAPeriod1 + "d", Color.PINK, yes);
AddChartBubble(BubbleLocation, DailySMA2, DailySMAPeriod2 + "d", Color.GREEN, yes);
AddChartBubble(BubbleLocation, DailySMA3, DailySMAPeriod3 + "d", Color.BLUE, yes);
AddChartBubble(BubbleLocation, DailySMA4, DailySMAPeriod4 + "d", Color.PLUM, yes);
AddChartBubble(BubbleLocation, DailySMA5, DailySMAPeriod5 + "d", Color.GRAY, yes);

#Defining support / Resistance

def Daily1Action = close crosses DailySMA1;
def Daily2Action = close crosses DailySMA2;
def Daily3Action = close crosses DailySMA3;
def Daily4Action = close crosses DailySMA4;
def Daily5Action = close crosses DailySMA5;

def Hourly1Action = close crosses HourlySMA1;
def Hourly2Action = close crosses HourlySMA2;
def Hourly3Action = close crosses HourlySMA3;
def Hourly4Action = close crosses HourlySMA4;


#Alerts
Alert(Daily1Action, "Daily " + DailySMAPeriod1 + "SMA", Alert.bar, Sound.Ding);
Alert(Daily2Action, "Daily " + DailySMAPeriod2 + "SMA", Alert.BAR, Sound.Ding);
Alert(Daily3Action, "Daily " + DailySMAPeriod3 + "SMA", Alert.BAR, Sound.Ding);
Alert(Daily4Action, "Daily " + DailySMAPeriod4 + "SMA", Alert.BAR, Sound.Ding);
Alert(Daily5Action, "Daily " + DailySMAPeriod5 + "SMA", Alert.BAR, Sound.Ding);

Alert(Hourly1Action, "Hourly " + HourlySMAPeriod1 + "SMA", Alert.BAR, Sound.Ding);
Alert(Hourly2Action, "Hourly " + HourlySMAPeriod2 + "SMA", Alert.BAR, Sound.Ding);
Alert(Hourly3Action, "Hourly " + HourlySMAPeriod3 + "SMA", Alert.BAR, Sound.Ding);
Alert(Hourly4Action, "Hourly " + HourlySMAPeriod4 + "SMA", Alert.BAR, Sound.Ding);
 
Last edited:
This is a great combination of multi timeframe moving average indicator. Thank you for sharing. If anyone is looking for a simpler version, with less features, here is the link.
 

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