Multi-timeframe (MTF) Moving Average Indicator for ThinkorSwim

Boom! Thank you so much @MerryDay

mtf_max2.png
 

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

Hi, my apologies if this is a stupid question.... What is the practical difference between multi-time frame moving averages, and moving averages of varying lengths? What I mean is, If you're on the 1-minute chart and want to see the average of the last 30 minutes, wouldn't a 30ma be the same thing as an MTF with a 30-minute time frame applied? I'm trying to understand the use here, because I have a hunch that MTF is in fact very useful but am having a hard time grasping the concept. Thanks to all for this awesome community.
 
Hi, my apologies if this is a stupid question.... What is the practical difference between multi-time frame moving averages, and moving averages of varying lengths? What I mean is, If you're on the 1-minute chart and want to see the average of the last 30 minutes, wouldn't a 30ma be the same thing as an MTF with a 30-minute time frame applied? I'm trying to understand the use here, because I have a hunch that MTF is in fact very useful but am having a hard time grasping the concept. Thanks to all for this awesome community.
@krahsloop I don't use moving averages but I have seen discussions that have stated the same thing.
I am hoping that someone makes a tutorial thread comparing the MTF MA with the longer length MA, it would be a great contribution to the community.
I have issues w/ MTF indicators. Novice traders don't understand why they can't make entry/exit on an MTF:
aMTF.png

It would be awesome to give them other options...
 
@wcsharron @tradegeek After a bit of thought process, I think you are better off with labels than Plot.

check out labels study code below. This seems to work our regardless of Time or Tick charts.

Code:
#
# SM_MovingAverageLabels
#
# version 1.2
#
declare on_volume;

#Default moving average values:
#SIMP 3 Close.DAY
#SIMP 8 Close.DAY
#SIMP 20 Close.DAY
#SIMP 50 Close.DAY
#SIMP 200 Close.DAY


input aP = AggregationPeriod.DAY;

input MA_1_length = 3; #simple
input MA_2_length = 8; #simple
input MA_3_length = 20; #simple
input MA_4_length = 50; #simple
input MA_5_length = 200; #simple

def MA_1_closeType = close(period = aP);
def MA_2_closeType = close(period = aP);
def MA_3_closeType = close(period = aP);
def MA_4_closeType = close(period = aP);
def MA_5_closeType = close(period = aP);

def MA_1_avg = round(Average(MA_1_closeType, MA_1_length),2);
def MA_2_avg = round(Average(MA_2_closeType, MA_2_length),2);
def MA_3_avg = round(Average(MA_3_closeType, MA_3_length),2);
def MA_4_avg = round(Average(MA_4_closeType, MA_4_length),2);
def MA_5_avg = round(Average(MA_5_closeType, MA_5_length),2);

def currentPrice = close;

AddLabel(1, "SMA" + " ", Color.YELLOW);

def MA_1_above = if currentPrice > MA_1_avg then 1 else 0;
def MA_1_below = if currentPrice <= MA_1_avg then 1 else 0;
AddLabel(MA_1_above, MA_1_length + ": " + MA_1_avg + " ", Color.GREEN);
AddLabel(MA_1_below, MA_1_length + ": " + MA_1_avg + " ", Color.RED);

def MA_2_above = if currentPrice > MA_2_avg then 1 else 0;
def MA_2_below = if currentPrice <= MA_2_avg then 1 else 0;
AddLabel(MA_2_above, MA_2_length + ": " + MA_2_avg + " ", Color.GREEN);
AddLabel(MA_2_below, MA_2_length + ": " + MA_2_avg + " ", Color.RED);

def MA_3_above = if currentPrice > MA_3_avg then 1 else 0;
def MA_3_below = if currentPrice <= MA_3_avg then 1 else 0;
AddLabel(MA_3_above, MA_3_length + ": " + MA_3_avg + " ", Color.GREEN);
AddLabel(MA_3_below, MA_3_length + ": " + MA_3_avg + " ", Color.RED);

def MA_4_above = if currentPrice > MA_4_avg then 1 else 0;
def MA_4_below = if currentPrice <= MA_4_avg then 1 else 0;
AddLabel(MA_4_above, MA_4_length + ": " + MA_4_avg + " ", Color.GREEN);
AddLabel(MA_4_below, MA_4_length + ": " + MA_4_avg + " ", Color.RED);

def MA_5_above = if currentPrice > MA_5_avg then 1 else 0;
def MA_5_below = if currentPrice <= MA_5_avg then 1 else 0;
AddLabel(MA_4_above, MA_5_length + ": " + MA_5_avg + " ", Color.GREEN);
AddLabel(MA_4_below, MA_5_length + ": " + MA_5_avg + " ", Color.RED);

#EXPO 3 Close
#EXPO 8 Close
#EXPO 20 Close
#EXPO 50 Close
#EXPO 200 Close

input EMA_1_length = 3; #exponential
input EMA_2_length = 8; #exponential
input EMA_3_length = 20; #exponential
input EMA_4_length = 50; #exponential
input EMA_5_length = 200; #exponential

def EMA_1_closeType = close;
def EMA_2_closeType = close;
def EMA_3_closeType = close;
def EMA_4_closeType = close;
def EMA_5_closeType = close;

def EMA_1_avg = round(ExpAverage(EMA_1_closeType, EMA_1_length),2);
def EMA_2_avg = round(ExpAverage(EMA_2_closeType, EMA_2_length),2);
def EMA_3_avg = round(ExpAverage(EMA_3_closeType, EMA_3_length),2);
def EMA_4_avg = round(ExpAverage(EMA_4_closeType, EMA_4_length),2);
def EMA_5_avg = round(ExpAverage(EMA_5_closeType, EMA_5_length),2);

AddLabel(1, "EMA" + " ", Color.YELLOW);

def EMA_1_above = if currentPrice > EMA_1_avg then 1 else 0;
def EMA_1_below = if currentPrice <= EMA_1_avg then 1 else 0;
AddLabel(EMA_1_above, EMA_1_length + ": " + EMA_1_avg + " ", Color.GREEN);
AddLabel(EMA_1_below, EMA_1_length + ": " + EMA_1_avg + " ", Color.RED);

def EMA_2_above = if currentPrice > EMA_2_avg then 1 else 0;
def EMA_2_below = if currentPrice <= EMA_2_avg then 1 else 0;
AddLabel(EMA_2_above, EMA_2_length + ": " + EMA_2_avg + " ", Color.GREEN);
AddLabel(EMA_2_below, EMA_2_length + ": " + EMA_2_avg + " ", Color.RED);

def EMA_3_above = if currentPrice > EMA_3_avg then 1 else 0;
def EMA_3_below = if currentPrice <= EMA_3_avg then 1 else 0;
AddLabel(EMA_3_above, EMA_3_length + ": " + EMA_3_avg + " ", Color.GREEN);
AddLabel(EMA_3_below, EMA_3_length + ": " + EMA_3_avg + " ", Color.RED);

def EMA_4_above = if currentPrice > EMA_4_avg then 1 else 0;
def EMA_4_below = if currentPrice <= EMA_4_avg then 1 else 0;
AddLabel(EMA_4_above, EMA_4_length + ": " + EMA_4_avg + " ", Color.GREEN);
AddLabel(EMA_4_below, EMA_4_length + ": " + EMA_4_avg + " ", Color.RED);

def EMA_5_above = if currentPrice > EMA_5_avg then 1 else 0;
def EMA_5_below = if currentPrice <= EMA_5_avg then 1 else 0;
AddLabel(EMA_4_above, EMA_5_length + ": " + EMA_5_avg + " ", Color.GREEN);
AddLabel(EMA_4_below, EMA_5_length + ": " + EMA_5_avg + " ", Color.RED);

**Note: This code has 5 of SMA and EMA labels defined and all SMA are fixed to AggregatePeriod.Day where as EMA are current candle.

-Surya

Hi,

I tired to edit your code, SMA to EMA for aggregationperiod.day; However, it keeps showing SMA values. Anything wrong I'm doing. Here is the code. Please help fix the issue. Thank you!

# Expo_MovingAverageLabels

#Default exponential moving average values:
#EXPO 8 Close.DAY
#EXPO 21 Close.DAY
#EXPO 50 Close.DAY
#EXPO 100 Close.DAY
#EXPO 200 Close.DAY


input aP = AggregationPeriod.DAY;

input EMA_1_length = 8; #exponential
input eMA_2_length = 21; #exponential
input eMA_3_length = 50; #exponential
input eMA_4_length = 100; #exponential
input eMA_5_length = 200; #exponential

def eMA_1_closeType = close(period = aP);
def eMA_2_closeType = close(period = aP);
def eMA_3_closeType = close(period = aP);
def eMA_4_closeType = close(period = aP);
def eMA_5_closeType = close(period = aP);

def eMA_1_avg = Round(Average(eMA_1_closeType, eMA_1_length), 2);
def eMA_2_avg = Round(Average(eMA_2_closeType, eMA_2_length), 2);
def eMA_3_avg = Round(Average(eMA_3_closeType, eMA_3_length), 2);
def eMA_4_avg = Round(Average(eMA_4_closeType, eMA_4_length), 2);
def eMA_5_avg = Round(Average(eMA_5_closeType, eMA_5_length), 2);

def currentPrice = close;

AddLabel(1, "EMA" + " ", Color.YELLOW);

def eMA_1_above = if currentPrice > eMA_1_avg then 1 else 0;
def eMA_1_below = if currentPrice <= eMA_1_avg then 1 else 0;
AddLabel(eMA_1_above, eMA_1_length + ": " + eMA_1_avg + " ", Color.GREEN);
AddLabel(eMA_1_below, eMA_1_length + ": " + eMA_1_avg + " ", Color.RED);

def eMA_2_above = if currentPrice > eMA_2_avg then 1 else 0;
def eMA_2_below = if currentPrice <= eMA_2_avg then 1 else 0;
AddLabel(eMA_2_above, eMA_2_length + ": " + eMA_2_avg + " ", Color.GREEN);
AddLabel(eMA_2_below, eMA_2_length + ": " + eMA_2_avg + " ", Color.RED);

def eMA_3_above = if currentPrice > eMA_3_avg then 1 else 0;
def eMA_3_below = if currentPrice <= eMA_3_avg then 1 else 0;
AddLabel(eMA_3_above, eMA_3_length + ": " + eMA_3_avg + " ", Color.GREEN);
AddLabel(eMA_3_below, eMA_3_length + ": " + eMA_3_avg + " ", Color.RED);

def eMA_4_above = if currentPrice > eMA_4_avg then 1 else 0;
def eMA_4_below = if currentPrice <= eMA_4_avg then 1 else 0;
AddLabel(eMA_4_above, eMA_4_length + ": " + eMA_4_avg + " ", Color.GREEN);
AddLabel(eMA_4_below, eMA_4_length + ": " + eMA_4_avg + " ", Color.RED);

def eMA_5_above = if currentPrice > eMA_5_avg then 1 else 0;
def eMA_5_below = if currentPrice <= eMA_5_avg then 1 else 0;
AddLabel(eMA_4_above, eMA_5_length + ": " + eMA_5_avg + " ", Color.GREEN);
AddLabel(eMA_4_below, eMA_5_length + ": " + eMA_5_avg + " ", Color.RED);
 
Last edited:
Hi,

I tired to edit your code, SMA to EMA for aggregationperiod.day; However, it keeps showing SMA values. Anything wrong I'm doing. Here is the code. Please help fix the issue. Thank you!

# Expo_MovingAverageLabels

#Default exponential moving average values:
#EXPO 8 Close.DAY
#EXPO 21 Close.DAY
#EXPO 50 Close.DAY
#EXPO 100 Close.DAY
#EXPO 200 Close.DAY


input aP = AggregationPeriod.DAY;

input EMA_1_length = 8; #exponential
input eMA_2_length = 21; #exponential
input eMA_3_length = 50; #exponential
input eMA_4_length = 100; #exponential
input eMA_5_length = 200; #exponential

def eMA_1_closeType = close(period = aP);
def eMA_2_closeType = close(period = aP);
def eMA_3_closeType = close(period = aP);
def eMA_4_closeType = close(period = aP);
def eMA_5_closeType = close(period = aP);

def eMA_1_avg = Round(Average(eMA_1_closeType, eMA_1_length), 2);
def eMA_2_avg = Round(Average(eMA_2_closeType, eMA_2_length), 2);
def eMA_3_avg = Round(Average(eMA_3_closeType, eMA_3_length), 2);
def eMA_4_avg = Round(Average(eMA_4_closeType, eMA_4_length), 2);
def eMA_5_avg = Round(Average(eMA_5_closeType, eMA_5_length), 2);

def currentPrice = close;

AddLabel(1, "EMA" + " ", Color.YELLOW);

def eMA_1_above = if currentPrice > eMA_1_avg then 1 else 0;
def eMA_1_below = if currentPrice <= eMA_1_avg then 1 else 0;
AddLabel(eMA_1_above, eMA_1_length + ": " + eMA_1_avg + " ", Color.GREEN);
AddLabel(eMA_1_below, eMA_1_length + ": " + eMA_1_avg + " ", Color.RED);

def eMA_2_above = if currentPrice > eMA_2_avg then 1 else 0;
def eMA_2_below = if currentPrice <= eMA_2_avg then 1 else 0;
AddLabel(eMA_2_above, eMA_2_length + ": " + eMA_2_avg + " ", Color.GREEN);
AddLabel(eMA_2_below, eMA_2_length + ": " + eMA_2_avg + " ", Color.RED);

def eMA_3_above = if currentPrice > eMA_3_avg then 1 else 0;
def eMA_3_below = if currentPrice <= eMA_3_avg then 1 else 0;
AddLabel(eMA_3_above, eMA_3_length + ": " + eMA_3_avg + " ", Color.GREEN);
AddLabel(eMA_3_below, eMA_3_length + ": " + eMA_3_avg + " ", Color.RED);

def eMA_4_above = if currentPrice > eMA_4_avg then 1 else 0;
def eMA_4_below = if currentPrice <= eMA_4_avg then 1 else 0;
AddLabel(eMA_4_above, eMA_4_length + ": " + eMA_4_avg + " ", Color.GREEN);
AddLabel(eMA_4_below, eMA_4_length + ": " + eMA_4_avg + " ", Color.RED);

def eMA_5_above = if currentPrice > eMA_5_avg then 1 else 0;
def eMA_5_below = if currentPrice <= eMA_5_avg then 1 else 0;
AddLabel(eMA_4_above, eMA_5_length + ": " + eMA_5_avg + " ", Color.GREEN);
AddLabel(eMA_4_below, eMA_5_length + ": " + eMA_5_avg + " ", Color.RED);
In your input section of code : a #exponential does not state what type of average TOS calculates!
look up AverageType

As for labels script for words will not change Simple to exponential average unless you use some type of if then statement
 
Is there a way to specify data like moving averages from different aggregation periods in the same study. For instance I want to know where the 200 ema is on the 5min time frame and where it is on the daily time frame and then add them both together
 
If you want to display moving averages from higher timeframe such as the hourly or daily on your lower timeframe chart, this indicator will help you do that. It basically displays higher timeframe moving averages on your 5m, 15m, or 30m chart. Anything with a higher timeframe moving average will work.

Here I have the 20 Daily Exponential Moving Average on my 15 minute chart.

iyf4H3R.png


You have the option between EMA, SMA (simple moving average), Hull, Weighted, and Wilders.

thinkScript Code

Rich (BB code):
# MTF Moving Average

input Period = aggregationPeriod.HOUR;
input AvgType = averageType.SIMPLE;
input Length = 50;
input priceclose = close;

plot AVG = MovingAverage(AvgType, close(period = Period), Length);
AVG.setdefaultcolor(color.yellow);

Shareable Link

https://tos.mx/5BpIqL

I'm unable to locate the original developer of this indicator. If you know who made this, please let me know.

Video Tutorial

@BenTen Could you add bubbles to the MTF 20D average?
 
  • Like
Reactions: Yev
Is there a way to smooth the lines out for this MTF MA??



#MTF MA

input price = FundamentalType.high;
input averageType = AverageType.simple;
input length = 9;
input HigherAggPeriod = AggregationPeriod.Day;
def chartAgg = GetAggregationPeriod();


plot MTF_MA = movingAverage(averageType, fundamental(price, period = HigherAggPeriod), length);
MTF_MA.setlineweight(2);
MTF_MA.SetDefaultColor(Color.orange);
 
i dunno its why i asked, i mean theyre accurate - my request is for aesthetics
Higher Frame MA values are calculated on close of the Higher Candle, Assuming your MA price = close. since the Chart frames are much smaller, they looks like steps, If you apply any kind of smoothing, then they are not the MA's as defined but they would be smoothed MA and the value will not match the defined MA length itself.
 
Hey guys I need your help... I'm trying to move this MA based MTF indicator to the chart and have it generate an audible alert and arrow signal to buy and sell.
But I can't achieve it, what are the conditions I need to achieve it. That when the 4 green dots are aligned they generate a sound alert and a signal arrow to buy on the Chart and the 4 red dots are aligned they generate a sound alert and a signal arrow to sell on the Chart...
...I'm sending you a screenshot and the code I'm working on so you have an idea of what I'm trying to accomplish, thanks in advance.
Code:
#MTF_MovingAverage_LowerStudy_Dots
#Caution: Anytime a higher timeframe row changes color between the white dots, the entire row between the white dots will change to the new color.
This will include dots that have previously plotted another color during that span between the white dots.
This could give you a misleading impression when viewing the lower timeframe chart.

# Original Inputs
input showchartbubbles = yes;
input show_white_dots  = yes;
input timeFrame1 = AggregationPeriod.FIFTEEN_MIN;
input timeFrame2 = AggregationPeriod.THIRTY_MIN;
input timeFrame3 = AggregationPeriod.HOUR;
input timeFrame4 = AggregationPeriod.FOUR_HOURS;
input maLength1 = 1;
input maType1 = AverageType.EXPONENTIAL;
input maLength2 = 8;
input maType2 = AverageType.EXPONENTIAL;

#---------- Original MTF Section
def ma1 = MovingAverage(maType1, close(period = timeFrame1), maLength1);
def ma2 = MovingAverage(maType2, close(period = timeFrame1), maLength2);

def ma3 = MovingAverage(maType1, close(period = timeFrame2), maLength1);
def ma4 = MovingAverage(maType2, close(period = timeFrame2), maLength2);

def ma5 = MovingAverage(maType1, close(period = timeFrame3), maLength1);
def ma6 = MovingAverage(maType2, close(period = timeFrame3), maLength2);

def ma7 = MovingAverage(maType1, close(period = timeFrame3), maLength1);
def ma8 = MovingAverage(maType2, close(period = timeFrame3), maLength2);


#White Dots plotted, marking the last Higher Timeframe bar on the Lower Timeframe
input begin   = 0930;
def minutes1 = timeFrame1 / 60000;
def minutes2 = timeFrame2 / 60000;
def minutes3 = timeFrame3 / 60000;
def minutes4 = timeFrame4 / 60000;

def barSeq    = if SecondsTillTime(begin) == 0 and
                   SecondsFromTime(begin) == 0
                then 0
                else barSeq[1] + 1;
def bar = barSeq;

def bar1 = if (bar) % (minutes1 / (GetAggregationPeriod() / 60000)) == 0 then bar1[1] + 1 else bar1[1];
def bar1ext = if !IsNaN(close) and IsNaN(close[-1]) then bar1 else Double.NaN;
def bar2 = if (bar) % (minutes2 / (GetAggregationPeriod() / 60000)) == 0 then bar2[1] + 1 else bar2[1];
def bar2ext = if !IsNaN(close) and IsNaN(close[-1]) then bar2 else Double.NaN;
def bar3 = if (bar) % (minutes3 / (GetAggregationPeriod() / 60000)) == 0 then bar3[1] + 1 else bar3[1];
def bar3ext = if !IsNaN(close) and IsNaN(close[-1]) then bar3 else Double.NaN;
def bar4 = if (bar) % (minutes4 / (GetAggregationPeriod() / 60000)) == 0 then bar4[1] + 1 else bar4[1];
def bar4ext = if !IsNaN(close) and IsNaN(close[-1]) then bar4 else Double.NaN;



#---------- Signals Section

def allGreenDots = ma1 > ma2 and ma3 > ma4 and ma5 > ma6 and ma7 > ma8;
def allRedDots = ma1 <= ma2 and ma3 <= ma4 and ma5 <= ma6 and ma7 <= ma8;

#---------- Plots Section
plot longSignal =  allGreenDots;
longSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
longSignal.SetDefaultColor(Color.CYAN);
longSignal.SetLineWeight(3);
plot shortSignal =  allRedDots;
shortSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
shortSignal.SetDefaultColor(Color.MAGENTA);
shortSignal.SetLineWeight(3);

#---------- Alerts Section
#Alert(longSignal, "Long Signal", Alert.BAR, Sound.RING);
#Alert(shortSignal, "Short Signal", Alert.BAR, Sound.RING);
 
@Yoel Pablo Try this.

Ruby:
#MTF_MovingAverage_LowerStudy_Dots
#Caution: Anytime a higher timeframe row changes color between the white dots, the entire row between the white dots will change to the new color.
#This will include dots that have previously plotted another color during that span between the white dots.
#This could give you a misleading impression when viewing the lower timeframe chart.

# Original Inputs
input showchartbubbles = yes;
input show_white_dots  = yes;
input timeFrame1 = AggregationPeriod.FIFTEEN_MIN;
input timeFrame2 = AggregationPeriod.THIRTY_MIN;
input timeFrame3 = AggregationPeriod.HOUR;
input timeFrame4 = AggregationPeriod.FOUR_HOURS;
input maLength1 = 1;
input maType1 = AverageType.EXPONENTIAL;
input maLength2 = 8;
input maType2 = AverageType.EXPONENTIAL;

#---------- Original MTF Section
def ma1 = MovingAverage(maType1, close(period = timeFrame1), maLength1);
def ma2 = MovingAverage(maType2, close(period = timeFrame1), maLength2);

def ma3 = MovingAverage(maType1, close(period = timeFrame2), maLength1);
def ma4 = MovingAverage(maType2, close(period = timeFrame2), maLength2);

def ma5 = MovingAverage(maType1, close(period = timeFrame3), maLength1);
def ma6 = MovingAverage(maType2, close(period = timeFrame3), maLength2);

def ma7 = MovingAverage(maType1, close(period = timeFrame3), maLength1);
def ma8 = MovingAverage(maType2, close(period = timeFrame3), maLength2);


#White Dots plotted, marking the last Higher Timeframe bar on the Lower Timeframe
input begin   = 0930;
def minutes1 = timeFrame1 / 60000;
def minutes2 = timeFrame2 / 60000;
def minutes3 = timeFrame3 / 60000;
def minutes4 = timeFrame4 / 60000;

def barSeq    = if SecondsTillTime(begin) == 0 and SecondsFromTime(begin) == 0 then 0  else barSeq[1] + 1;
def bar = barSeq;

def bar1 = if (bar) % (minutes1 / (GetAggregationPeriod() / 60000)) == 0 then bar1[1] + 1 else bar1[1];
def bar1ext = if !IsNaN(close) and IsNaN(close[-1]) then bar1 else Double.NaN;
def bar2 = if (bar) % (minutes2 / (GetAggregationPeriod() / 60000)) == 0 then bar2[1] + 1 else bar2[1];
def bar2ext = if !IsNaN(close) and IsNaN(close[-1]) then bar2 else Double.NaN;
def bar3 = if (bar) % (minutes3 / (GetAggregationPeriod() / 60000)) == 0 then bar3[1] + 1 else bar3[1];
def bar3ext = if !IsNaN(close) and IsNaN(close[-1]) then bar3 else Double.NaN;
def bar4 = if (bar) % (minutes4 / (GetAggregationPeriod() / 60000)) == 0 then bar4[1] + 1 else bar4[1];
def bar4ext = if !IsNaN(close) and IsNaN(close[-1]) then bar4 else Double.NaN;

#---------- Signals Section

def allGreenDots = ma1 > ma2 and ma3 > ma4 and ma5 > ma6 and ma7 > ma8;
def allRedDots = ma1 <= ma2 and ma3 <= ma4 and ma5 <= ma6 and ma7 <= ma8;

#---------- Plots Section
plot longSignal = if allGreenDots and !allGreenDots[1] then low else Double.NaN;
longSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
longSignal.SetDefaultColor(Color.CYAN);
longSignal.SetLineWeight(3);
plot shortSignal = if allRedDots and !allRedDots[1] then high else Double.NaN;
shortSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
shortSignal.SetDefaultColor(Color.MAGENTA);
shortSignal.SetLineWeight(3);

#---------- Alerts Section
Alert(longSignal, "Long Signal", Alert.BAR, Sound.RING);
Alert(shortSignal, "Short Signal", Alert.BAR, Sound.DING);
 
I really like this one, but wanted to use it on other time frames besides daily and allow different moving averages and display nonoverlapping bubbles (when the MA lines get close, the bubbles overlap). Note that SuryaKiranC and prolab also made a nice alternative version of Pensar's script for Daily charts in this same thread.

As has been noted by others here, one can put higher time frame MAs on a lower time frame simply by adjusting the numbers, e.g., a 120 period MA on a 5 minute chart is equivalent to the 10 period MA on an hourly chart, etc.

Hopefully a chart and the new code are shown below.

Chart-Mov-Avg-3-Bubbles2.png



Code:
# Modification of Pensar’s Daily Simple Moving Averages with Identifying Bubbles
# Can be used on any time frame & the MAs can be different types
# MovAvg_3Bubbles2

input avg_1 = 20;
input avg_2 = 50;
input avg_3 = 200;
input avg_type1 = AverageType.SIMPLE;
input avg_type2 = AverageType.SIMPLE;
input avg_type3 = AverageType.SIMPLE;


plot ma1 = MovingAverage(avg_type1,close,avg_1);
ma1.SetDefaultColor(Color.DARK_ORANGE);
ma1.SetLineWeight(2);


plot ma2 = MovingAverage(avg_type2,close,avg_2);
ma2.SetDefaultColor(Color.MAGENTA);
ma2.SetLineWeight(2);


plot ma3 = MovingAverage(avg_type3,close,avg_3);
ma3.SetDefaultColor(Color.BLUE);
ma3.SetLineWeight(2);


#Bubbles
input show_bubbles = yes;

def x = !IsNaN(close[-50]) and IsNaN(close[-51]);
def y = !IsNaN(close[-40]) and IsNaN(close[-41]);
def z = !IsNaN(close[-30]) and IsNaN(close[-31]);

AddChartBubble(show_bubbles and x, ma1, avg_1 + " MA", Color.DARK_ORANGE);
AddChartBubble(show_bubbles and y, ma2, avg_2 + " MA", Color.MAGENTA);
AddChartBubble(show_bubbles and z, ma3, avg_3 + " MA", Color.CYAN);

#end code
What does this line of code say?



def x = !IsNaN(close[-50]) and IsNaN(close[-51]);
def y = !IsNaN(close[-40]) and IsNaN(close[-41]);
def z = !IsNaN(close[-30]) and IsNaN(close[-31]);
 
What does this line of code say?



def x = !IsNaN(close[-50]) and IsNaN(close[-51]);
def y = !IsNaN(close[-40]) and IsNaN(close[-41]);
def z = !IsNaN(close[-30]) and IsNaN(close[-31]);
The use of referencing bars back or bars future can be confusing

High[4] is the high from 4 bars ago, High[-4] is the high from 4 bars into the future. Bars that have not been yet traded. when viewing on a chart, those indicators will stop short of the right side of the chart by the negative numbers referenced. When viewed from the left side of the chart, your indicators will perform better than expected due to the use of foresight We all would like to now what the Market will do on Monday so that we could have traded it last Friday!
 
The use of referencing bars back or bars future can be confusing

High[4] is the high from 4 bars ago, High[-4] is the high from 4 bars into the future. Bars that have not been yet traded. when viewing on a chart, those indicators will stop short of the right side of the chart by the negative numbers referenced. When viewed from the left side of the chart, your indicators will perform better than expected due to the use of foresight We all would like to now what the Market will do on Monday so that we could have traded it last Friday!
Thanks. What can I adjust the minus input to just 1 so it’s not a strain on my computer?
 
Hello everyone,

I have looked through the site to try and find this indicator or thinkscript, but have had no luck.
I am looking for a script that would plot the Daily EMAs on multiple time-frames, but instead of drawing the lines from the left, plot smaller lines on the right side of the chart, next to the price bar.

I draw these levels manually and adjust them as needed, but an automated process would be great! So if there is something in here like that, please point me in the right direction!

I tried to post a picture, but no sure how.

Thanks in advance!
 
Last edited:
Hello everyone,

I have looked through the site to try and find this indicator or thinkscript, but have had no luck.
I am looking for a script that would plot the Daily EMAs on multiple time-frames, but instead of drawing the lines from the left, plot smaller lines on the right side of the chart, next to the price bar.

I draw these levels manually and adjust them as needed, but an automated process would be great! So if there is something in here like that, please point me in the right direction!

I tried to post a picture, but no sure how.

Thanks in advance!
I moved your post to this thread. There are 9 pages of discussion of MTF moving average. Plug&Play until you find one that fits your needs.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
295 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