How to add a moving average into a study from different time frames?

dsohi11

New member
Anyone know how this please let me know? If the question is confusing also let me know thanks in advance.
 
Solution
You can use the aggregation period. Here's an example from the docs to plot the 15m close on your chart.
https://tlc.thinkorswim.com/center/...gregationPeriod/AggregationPeriod-FIFTEEN-MIN
There are limits to what you can do. You can't plot the 1m on a 5m chart, nor the 30m on a 2h chart. But you can go the other direction and plot the 30m on a 5m chart if you want.

Code:
plot 15m_EMA = MovAvgExponential(price = close(period = AggregationPeriod.FIFTEEN_MIN));

In this example, I've plotted the 15m ema by calling the price for the function using a secondary aggregation period. This one is simple, but illustrates the point I hope.

Ask more if you need,

-mashume
You can use the aggregation period. Here's an example from the docs to plot the 15m close on your chart.
https://tlc.thinkorswim.com/center/...gregationPeriod/AggregationPeriod-FIFTEEN-MIN
There are limits to what you can do. You can't plot the 1m on a 5m chart, nor the 30m on a 2h chart. But you can go the other direction and plot the 30m on a 5m chart if you want.

Code:
plot 15m_EMA = MovAvgExponential(price = close(period = AggregationPeriod.FIFTEEN_MIN));

In this example, I've plotted the 15m ema by calling the price for the function using a secondary aggregation period. This one is simple, but illustrates the point I hope.

Ask more if you need,

-mashume
 
Solution

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

I created a label for this based on Ripsters EMA clouds. I’ll jump on the computer later and post it here. It’s mostly complete but any input from anyone else on the forum would be greatly appreciated.

If it’s not posted in the next hour or two send me a DM because I probably forgot haha
 
Last edited:
What I promised. See if that is helpful for you. I just add one for each time frame needed.

#MACD Histogram Cross
#Justin Turner

Declare Upper;

input time_frame = AggregationPeriod.DAY;

def lookback = 1;
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
def averageType = AverageType.EXPONENTIAL;
def showBreakoutSignals = no;
def time_select = (close(period = time_frame));

def value = MovingAverage(averageType, time_select, fastLength) - MovingAverage(averageType,time_select, slowLength);
def avg = MovingAverage(averageType, Value, MACDLength);

def bull_cross = value crosses above avg;
def bear_cross = value crosses below avg;

def bull_lookback = highest(bull_cross, lookback);
def bear_lookback = highest(bear_cross, lookback);

AddLabel (yes,
if Time_Frame == aggregationPeriod.YEAR then "Yr-"
else if
Time_Frame == aggregationPeriod.QUARTER then "Qtr-"
else if
Time_Frame == aggregationPeriod.MONTH then "Mo-"
else if
Time_Frame == aggregationPeriod.WEEK then "Wk-"
else if
Time_Frame == aggregationPeriod.FOUR_DAYS then "4D-"
else if
Time_Frame == aggregationPeriod.THREE_DAYS then "3D-"
else if
Time_Frame == aggregationPeriod.TWO_DAYS then "2D-"
else if
Time_Frame == aggregationPeriod.DAY then "D-"
else if
Time_Frame == aggregationPeriod.FOUR_HOURS then "4H-"
else if
Time_Frame == aggregationPeriod.TWO_HOURS then "2H-"
else if
Time_Frame == aggregationPeriod.HOUR then "1H-"
else if
Time_Frame == aggregationPeriod.THIRTY_MIN then "30m-"
else if
Time_Frame == aggregationPeriod.TWENTY_MIN then "20m-"
else if
Time_Frame == aggregationPeriod.FIFTEEN_MIN then "15m-"
else if
Time_Frame == aggregationPeriod.TEN_MIN then "10m-"
else if
Time_Frame == aggregationPeriod.FIVE_MIN then "5m-"
else if
Time_Frame == aggregationPeriod.FOUR_MIN then "4m-"
else if
Time_Frame == aggregationPeriod.THREE_MIN then "3m-"
else if
Time_Frame == aggregationPeriod.TWO_MIN then "2m-"
else if
Time_Frame == aggregationPeriod.MIN then "1m-"
else "-",
if bull_lookback then createcolor (0,204, 0)
else if
bear_lookback then createcolor (204, 0, 0)
else if
bull_lookback within 2 bars then createcolor (0, 153, 0)
else if
bear_lookback within 2 bars then createcolor (153, 0, 0)
else
color.white);
AddLabel (yes,
if
bull_lookback then "MACD Bull X"
else if
bear_lookback then "MACD Bear X"
else if
bull_lookback within 2 bars then "MACD Bull XX"
else if bear_lookback within 2 bars then "MACD Bear XX"
else "MACD",
if bull_lookback then createcolor (0,204, 0)
else if
bear_lookback then createcolor (204, 0, 0)
else if
bull_lookback within 2 bars then createcolor (0, 153, 0)
else if
bear_lookback within 2 bars then createcolor (153, 0, 0)
else
color.white);
 
What I promised. See if that is helpful for you. I just add one for each time frame needed.

#MACD Histogram Cross
#Justin Turner

Declare Upper;

input time_frame = AggregationPeriod.DAY;

def lookback = 1;
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
def averageType = AverageType.EXPONENTIAL;
def showBreakoutSignals = no;
def time_select = (close(period = time_frame));

def value = MovingAverage(averageType, time_select, fastLength) - MovingAverage(averageType,time_select, slowLength);
def avg = MovingAverage(averageType, Value, MACDLength);

def bull_cross = value crosses above avg;
def bear_cross = value crosses below avg;

def bull_lookback = highest(bull_cross, lookback);
def bear_lookback = highest(bear_cross, lookback);

AddLabel (yes,
if Time_Frame == aggregationPeriod.YEAR then "Yr-"
else if
Time_Frame == aggregationPeriod.QUARTER then "Qtr-"
else if
Time_Frame == aggregationPeriod.MONTH then "Mo-"
else if
Time_Frame == aggregationPeriod.WEEK then "Wk-"
else if
Time_Frame == aggregationPeriod.FOUR_DAYS then "4D-"
else if
Time_Frame == aggregationPeriod.THREE_DAYS then "3D-"
else if
Time_Frame == aggregationPeriod.TWO_DAYS then "2D-"
else if
Time_Frame == aggregationPeriod.DAY then "D-"
else if
Time_Frame == aggregationPeriod.FOUR_HOURS then "4H-"
else if
Time_Frame == aggregationPeriod.TWO_HOURS then "2H-"
else if
Time_Frame == aggregationPeriod.HOUR then "1H-"
else if
Time_Frame == aggregationPeriod.THIRTY_MIN then "30m-"
else if
Time_Frame == aggregationPeriod.TWENTY_MIN then "20m-"
else if
Time_Frame == aggregationPeriod.FIFTEEN_MIN then "15m-"
else if
Time_Frame == aggregationPeriod.TEN_MIN then "10m-"
else if
Time_Frame == aggregationPeriod.FIVE_MIN then "5m-"
else if
Time_Frame == aggregationPeriod.FOUR_MIN then "4m-"
else if
Time_Frame == aggregationPeriod.THREE_MIN then "3m-"
else if
Time_Frame == aggregationPeriod.TWO_MIN then "2m-"
else if
Time_Frame == aggregationPeriod.MIN then "1m-"
else "-",
if bull_lookback then createcolor (0,204, 0)
else if
bear_lookback then createcolor (204, 0, 0)
else if
bull_lookback within 2 bars then createcolor (0, 153, 0)
else if
bear_lookback within 2 bars then createcolor (153, 0, 0)
else
color.white);
AddLabel (yes,
if
bull_lookback then "MACD Bull X"
else if
bear_lookback then "MACD Bear X"
else if
bull_lookback within 2 bars then "MACD Bull XX"
else if bear_lookback within 2 bars then "MACD Bear XX"
else "MACD",
if bull_lookback then createcolor (0,204, 0)
else if
bear_lookback then createcolor (204, 0, 0)
else if
bull_lookback within 2 bars then createcolor (0, 153, 0)
else if
bear_lookback within 2 bars then createcolor (153, 0, 0)
else
color.white);
could you please provide shareable link
 

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