MTF Moving Average Labels

tgiasson

New member
Looking for a label to show the percent the price is from its moving average and to do so on a specific time frame. For example, would like to have a label to show % price is from 21 ema on a 30 min chart on its own label. And to be able to take that label on different time frame charts without it being affected by the different time frame chart or ema's on that chart. The label would only show the ema and time frame it's calculating against. Would like to be able to change the time frame and ema in the label's parameters, ex. instead of 21 on 30min have another label for 8ema on daily. Hope I explained this well.
 
Looking for a label to show the percent the price is from its moving average and to do so on a specific time frame. For example, would like to have a label to show % price is from 21 ema on a 30 min chart on its own label. And to be able to take that label on different time frame charts without it being affected by the different time frame chart or ema's on that chart. The label would only show the ema and time frame it's calculating against. Would like to be able to change the time frame and ema in the label's parameters, ex. instead of 21 on 30min have another label for 8ema on daily. Hope I explained this well.
Was anyone able to help?
 
I got the study for you. I was in the process of adding a feature to it. I'm trying to add alert if there's a 10 percent drop from a peak on the 9 & 50 moving day averages.

https://tos.mx/TSjuHLE

Code:
# avgs_per_diff_00

declare lower;

input avg1Type = Averagetype.simple;
input avg2type = Averagetype.simple;
input Avg1Length = 10;
input Avg2Length = 20;

def avg1 = MovingAverage(avg1Type, close, avg1Length);
def avg2 = MovingAverage(avg2Type, close, avg2Length);
def avgup = (avg1 > avg2);

#def AvgPercent = MovingAverage(avg1Type, close, avg1Length)-MovingAverage(avg2Type, close, avg2Length);
# plot percentDiff = (absValue(avgPercent)/movingaverage(avg1type,close,avg1length)) *100;

def Avg12diff = avg1 - avg2;

plot percentDiff = (absValue(avg12diff)/avg1) *100;
percentDiff.DefineColor("Up", color.green);
percentDiff.DefineColor("Down", color.red);
percentDiff.AssignValueColor(if avgup then percentDiff.color("up") else percentDiff.color("down"));

plot ZeroLine = 0;


0sT1oLo.png
 
I would like to add below label in ToS on daily timeframe:

Code:
1 Hour: Bullish

This would show up as Bullish if below condition is met

CSS:
close > ema200

Is this even possible on ToS because I noticed ToS allows only higher time frame calculations from current timeframe?

I noticed Tradingview displays it nicely on Daily timeframe but would love to know if its possible on ToS daily timeframe.

If its not possible, how do I even show it on higher up timeframes only because it keeps giving that error saying I need higher time frame even when I'm comparing timeframes by taking aggreegation and matching it with current period?

Thanks
 
The ToS platform allows us to plot higher timeframe data on a lower time frame.
For example 1hr data on a 15min chart.

It is not possible to plot lower timeframe data on a higher chart such as 1hr on a Daily chart.
FYI, the standard for moving average cross is to use two averages. Choosing the close of a single bar is arbitrary. A short average provides better results.
1pM3Kyi.png

Ruby:
# ########################################
# MTF Moving Average Label @MerryDay 1/2023
input LongLength = 200;
input ShortLength = 9;
input LongType = Averagetype.simple;
input ShortType = Averagetype.eXPONENTIAL;
input agg     = AggregationPeriod.hour;
def aggPrice = Close(Period =agg);
def LongAvg =  MovingAverage(Averagetype.simple, aggPrice, LongLength);  # higher timeframe
def ShortAvg = MovingAverage(Averagetype.eXPONENTIAL, close, ShortLength);  # current chart timeframe

# #########################################
# Charting & Formatting
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;

plot pLongAvg = LongAvg ;
       pLongAvg.SetDefaultColor(color.blue);

plot pShortAvg = ShortAvg ;
       pShortAvg.SetDefaultColor(color.pink);

AddCloud(ShortAvg, LongAvg, color.green, color.pink);
AddLabel(ShortAvg>=LongAvg, "Bullish", GlobalColor("LabelGreen"));

FYI, using an MTF indicator limits the usefulness of your script.

Studies that have secondary aggregations cannot be used in Scans, Watchlists, Chart Alerts, Conditional Orders.
They can only be used to make plots on a chart.

As an alternate to using MTF indicators in your scripts is to vary the lengths to approximate the results of your MTF indicators.
You can try:
On a daily chart a 50 SMA would equal a 10 SMA on a weekly chart
On a 1 Min Chart a 50 SMA would equal a 10 SMA on a 5 Min Chart
On a 1 Min Chart a 300 SMA would equal a 10 SMA on a Hourly Chart
On a 1 Min Chart a 1950 SMA would equal a 10 SMA on a Daily Chart
 
Last edited:

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