Repaints Super Trend MTF Enhanced For ThinkOrSwim

Repaints

ApeX Predator

Well-known member
Was debating for a while, if the forum needs yet another Super Trend Indicator. Anyways, decided to post since there isn't one that is selecting Higher Frames automatically based on chart frames. Base parameters of this not not my own, this is a equivalent of Super Trend yahoo version parameters. Feel free to make it your own, with modified nATR and ATRMulti inputs.

There are version that get passed as MTF, but there is only one HF (Higher Frame) defined, that may be fine for an upper indicator, but in my opinion a True, lower MTF version should have more than one higher TF and should be able to auto switch the Higher TF automatically based on Chart TF.

Note: Indicator Repaints, till the candle closes, that's applicable for Higher Frame plots too.

Ruby:
# SuperTrend Multiple Time Frames
# Modifled by SuryaKiranC
# V05.06.2021
# An attempt to Support autoswitch of Highr Frames with chart frame changes.
# Provide Support for Chart Frame 1m to 4H.
# Aggrigate of SuperTrend Bullish is plotted in Green above Dots/ Bearish is plotted in Red below Dots.
# ATRMult & nATR values are different from original and can be adjusted by user.
# Mobius
# V03.01.2016

# I pulled this study down from MyTrade for a reason. It wasn't
# plotting correctly with the multiple aggregations. And like
# all studies with secondary aggregations it tends to replot the
# higher ones. I decided to think about it some more and this is
# where I am with the ST MTF study now.
#
# It's still squirrely and blinks a lot. Using declare Once_Per_Bar
# does some bad things to it. I was considering making intra
# aggregation higher time frames. A pain to do but it gives more
# control over how it plots.
#
# Row 6 is supposed to be the output for all aggregations and the
# signal line. After hours when data isn't moving it's steady and
# has good signals. But since it's after hours, totally useless
# for any intraday trading.

declare hide_on_daily;
declare lower;
declare once_per_bar;
declare real_size;

input audibleAlerts = yes;

def _aP1 = GetAggregationPeriod();
def _aP2 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.THREE_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.FOUR_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.FIVE_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.TWENTY_MIN else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.FOUR_HOURS else AggregationPeriod.DAY);

def _aP3 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.FIVE_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.DAY else AggregationPeriod.TWO_DAYS);

def _aP4 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.TWENTY_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.DAY else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.TWO_DAYS else AggregationPeriod.THREE_DAYS);

def _aP5 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.TWENTY_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.DAY else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.TWO_DAYS else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.THREE_DAYS else AggregationPeriod.FOUR_DAYS);

def agg1 = _aP1;
def agg2 = _aP2;
def agg3 = _aP3;
def agg4 = _aP4;
def agg5 = _aP5;

input AtrMult = 1;
input nATR = 6;
input AvgType = AverageType.HULL;

DefineGlobalColor ("Line", Color.LIGHT_GRAY);
DefineGlobalColor ("TrendUp", Color.LIGHT_GREEN);
DefineGlobalColor ("TrendDown", Color.LIGHT_RED);
DefineGlobalColor ("Buy", Color.GREEN);
DefineGlobalColor ("Sell", Color.RED);

def Line = 1.75;

def Fh = FundamentalType.HIGH;
def Fl = FundamentalType.LOW;
def Fc = FundamentalType.CLOSE;
def Fhl2 = FundamentalType.HL2;

def h = Fundamental(Fh, period = agg1);
def l = Fundamental(Fl, period = agg1);
def c = Fundamental(Fc, period = agg1);
def hl = Fundamental(Fhl2, period = agg1);
def ATR = MovingAverage(AvgType, TrueRange(h, c, l), nATR);
def UP = hl + (AtrMult * ATR);
def DN = hl + (-AtrMult * ATR);
def S = if c < S[1] then Round(UP / TickSize(), 0) * TickSize() else Round(DN / TickSize(), 0) * TickSize();

def h2 = Fundamental(Fh, period = agg2);
def l2 = Fundamental(Fl, period = agg2);
def c2 = Fundamental(Fc, period = agg2);
def hl2 = Fundamental(Fhl2, period = agg2);
def ATR2 = MovingAverage(AvgType, TrueRange(h2, c2, l2), nATR);
def UP2 = hl2 + (AtrMult * ATR2);
def DN2 = hl2 + (-AtrMult * ATR2);
def S2 = if c2 < S2[1] then Round(UP2 / TickSize(), 0) * TickSize() else Round(DN2 / TickSize(), 0) * TickSize();

def h3 = Fundamental(Fh, period = agg3);
def l3 = Fundamental(Fl, period = agg3);
def c3 = Fundamental(Fc, period = agg3);
def hl3 = Fundamental(Fhl2, period = agg3);
def ATR3 = MovingAverage(AvgType, TrueRange(h3, c3, l3), nATR);
def UP3 = hl3 + (AtrMult * ATR3);
def DN3 = hl3 + (-AtrMult * ATR3);
def S3 = if c3 < S3[1] then Round(UP3 / TickSize(), 0) * TickSize() else Round(DN3 / TickSize(), 0) * TickSize();

def h4 = Fundamental(Fh, period = agg4);
def l4 = Fundamental(Fl, period = agg4);
def c4 = Fundamental(Fc, period = agg4);
def hl4 = Fundamental(Fhl2, period = agg4);
def ATR4 = MovingAverage(AvgType, TrueRange(h4, c4, l4), nATR);
def UP4 = hl4 + (AtrMult * ATR4);
def DN4 = hl4 + (-AtrMult * ATR4);
def S4 = if c4 < S4[1] then Round(UP4 / TickSize(), 0) * TickSize() else Round(DN4 / TickSize(), 0) * TickSize();

def h5 = Fundamental(Fh, period = agg5);
def l5 = Fundamental(Fl, period = agg5);
def c5 = Fundamental(Fc, period = agg5);
def hl5 = Fundamental(Fhl2, period = agg5);
def ATR5 = MovingAverage(AvgType, TrueRange(h5, c5, l5), nATR);
def UP5 = hl5 + (AtrMult * ATR5);
def DN5 = hl5 + (-AtrMult * ATR5);
def S5 = if c5 < S5[1] then Round(UP5 / TickSize(), 0) * TickSize() else Round(DN5 / TickSize(), 0) * TickSize();

plot hLine = Line ;
hLine.SetDefaultColor(GlobalColor("Line"));
plot lLine = -Line;
lLine.SetDefaultColor(GlobalColor("Line"));
def cl = close;
def x = IsNaN(cl[2]) and !IsNaN(cl[3]);

def FirstAgg = if c > S then 1 else 0;
plot FirstAggPlot = if IsNaN(cl) then Double.NaN else 1;
FirstAggPlot.SetStyle(Curve.POINTS);
FirstAggPlot.SetLineWeight(2);
FirstAggPlot.AssignValueColor(if FirstAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, 1, (agg1 / 1000 / 60) + " min", Color.WHITE, yes);

def SecondAgg =  if c2 > S2 then 1 else 0;
plot SecondAggPlot = if IsNaN(cl) then Double.NaN else 0.5;
SecondAggPlot.SetStyle(Curve.POINTS);
SecondAggPlot.SetLineWeight(3);
SecondAggPlot.AssignValueColor(if SecondAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, 0.5, (agg2 / 1000 / 60) + " min", Color.WHITE, yes);

def ThirdAgg =  if c3 > S3 then 1 else 0;
plot ThirdAggPlot = if IsNaN(cl) then Double.NaN else 0;
ThirdAggPlot.SetStyle(Curve.POINTS);
ThirdAggPlot.SetLineWeight(3);
ThirdAggPlot.AssignValueColor(if ThirdAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, 0, (agg3 / 1000 / 60) + " min", Color.WHITE, yes);

def FourthAgg =  if c4 > S4 then 1 else 0;
plot FourthAggPlot = if IsNaN(cl) then Double.NaN else -0.5;
FourthAggPlot.SetStyle(Curve.POINTS);
FourthAggPlot.SetLineWeight(4);
FourthAggPlot.AssignValueColor(if FourthAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, -0.5, (agg4 / 1000 / 60) + " min", Color.WHITE, yes);

def FifthAgg =  if c5 > S5 then 1 else 0;
plot FifthAggPlot = if IsNaN(cl) then Double.NaN else -1;
FifthAggPlot.SetStyle(Curve.POINTS);
FifthAggPlot.SetLineWeight(4);
FifthAggPlot.AssignValueColor(if FifthAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));

AddChartBubble(x, -1, (agg5 / 1000 / 60) + " min", Color.WHITE, yes);
plot Direction = if (FirstAgg and SecondAgg and ThirdAgg and FourthAgg and FifthAgg) then hLine + .5 else if (!FirstAgg and !SecondAgg and !ThirdAgg and !FourthAgg and !FifthAgg) then lLine - .5 else Double.NaN;

def Bullish = (if FirstAgg and SecondAgg and ThirdAgg and FourthAgg and FifthAgg then 1 else 0);
def Bearish = (if !FirstAgg and !SecondAgg and !ThirdAgg and !FourthAgg and !FifthAgg then 1 else 0);

Direction.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Direction.SetLineWeight(4);
Direction.AssignValueColor(if Bullish then GlobalColor ("Buy") else if Bearish then GlobalColor ("Sell") else Color.BLACK);

Alert(audibleAlerts and Bullish, "SuperTrend UpTrend Started",   Alert.BAR, Sound.Ding);
Alert(audibleAlerts and Bearish, "SuperTrend DownTrend Started", Alert.BAR, Sound.Ring);

# End Code ST MTF
 
Last edited:
Was debating for a while, if the forum needs yet another Super Trend Indicator. Anyways, decided to post since there isn't one that is selecting Higher Frames automatically based on chart frames. Base parameters of this not not my own, this is a equivalent of Super Trend yahoo version parameters. Feel free to make it your own, with modified nATR and ATRMulti inputs.

There are version that get passed as MTF, but there is only one HF (Higher Frame) defined, that may be fine for an upper indicator, but in my opinion a True, lower MTF version should have more than one higher TF and should be able to auto switch the Higher TF automatically based on Chart TF.

Note: Indicator Repaints, till the candle closes, that's applicable for Higher Frame plots too.

Ruby:
# SuperTrend Multiple Time Frames
# Modifled by SuryaKiranC
# V05.06.2021
# An attempt to Support autoswitch of Highr Frames with chart frame changes.
# Provide Support for Chart Frame 1m to 4H.
# Aggrigate of SuperTrend Bullish is plotted in Green above Dots/ Bearish is plotted in Red below Dots.
# ATRMult & nATR values are different from original and can be adjusted by user.
# Mobius
# V03.01.2016

# I pulled this study down from MyTrade for a reason. It wasn't
# plotting correctly with the multiple aggregations. And like
# all studies with secondary aggregations it tends to replot the
# higher ones. I decided to think about it some more and this is
# where I am with the ST MTF study now.
#
# It's still squirrely and blinks a lot. Using declare Once_Per_Bar
# does some bad things to it. I was considering making intra
# aggregation higher time frames. A pain to do but it gives more
# control over how it plots.
#
# Row 6 is supposed to be the output for all aggregations and the
# signal line. After hours when data isn't moving it's steady and
# has good signals. But since it's after hours, totally useless
# for any intraday trading.

declare hide_on_daily;
declare lower;
declare once_per_bar;
declare real_size;

input audibleAlerts = yes;

def _aP1 = GetAggregationPeriod();
def _aP2 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.THREE_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.FOUR_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.FIVE_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.TWENTY_MIN else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.FOUR_HOURS else AggregationPeriod.DAY);

def _aP3 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.FIVE_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.DAY else AggregationPeriod.TWO_DAYS);

def _aP4 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.TWENTY_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.DAY else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.TWO_DAYS else AggregationPeriod.THREE_DAYS);

def _aP5 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.TWENTY_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.DAY else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.TWO_DAYS else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.THREE_DAYS else AggregationPeriod.FOUR_DAYS);

def agg1 = _aP1;
def agg2 = _aP2;
def agg3 = _aP3;
def agg4 = _aP4;
def agg5 = _aP5;

input AtrMult = 1;
input nATR = 6;
input AvgType = AverageType.HULL;

DefineGlobalColor ("Line", Color.LIGHT_GRAY);
DefineGlobalColor ("TrendUp", Color.LIGHT_GREEN);
DefineGlobalColor ("TrendDown", Color.LIGHT_RED);
DefineGlobalColor ("Buy", Color.GREEN);
DefineGlobalColor ("Sell", Color.RED);

def Line = 1.75;

def Fh = FundamentalType.HIGH;
def Fl = FundamentalType.LOW;
def Fc = FundamentalType.CLOSE;
def Fhl2 = FundamentalType.HL2;

def h = Fundamental(Fh, period = agg1);
def l = Fundamental(Fl, period = agg1);
def c = Fundamental(Fc, period = agg1);
def hl = Fundamental(Fhl2, period = agg1);
def ATR = MovingAverage(AvgType, TrueRange(h, c, l), nATR);
def UP = hl + (AtrMult * ATR);
def DN = hl + (-AtrMult * ATR);
def S = if c < S[1] then Round(UP / TickSize(), 0) * TickSize() else Round(DN / TickSize(), 0) * TickSize();

def h2 = Fundamental(Fh, period = agg2);
def l2 = Fundamental(Fl, period = agg2);
def c2 = Fundamental(Fc, period = agg2);
def hl2 = Fundamental(Fhl2, period = agg2);
def ATR2 = MovingAverage(AvgType, TrueRange(h2, c2, l2), nATR);
def UP2 = hl2 + (AtrMult * ATR2);
def DN2 = hl2 + (-AtrMult * ATR2);
def S2 = if c2 < S2[1] then Round(UP2 / TickSize(), 0) * TickSize() else Round(DN2 / TickSize(), 0) * TickSize();

def h3 = Fundamental(Fh, period = agg3);
def l3 = Fundamental(Fl, period = agg3);
def c3 = Fundamental(Fc, period = agg3);
def hl3 = Fundamental(Fhl2, period = agg3);
def ATR3 = MovingAverage(AvgType, TrueRange(h3, c3, l3), nATR);
def UP3 = hl3 + (AtrMult * ATR3);
def DN3 = hl3 + (-AtrMult * ATR3);
def S3 = if c3 < S3[1] then Round(UP3 / TickSize(), 0) * TickSize() else Round(DN3 / TickSize(), 0) * TickSize();

def h4 = Fundamental(Fh, period = agg4);
def l4 = Fundamental(Fl, period = agg4);
def c4 = Fundamental(Fc, period = agg4);
def hl4 = Fundamental(Fhl2, period = agg4);
def ATR4 = MovingAverage(AvgType, TrueRange(h4, c4, l4), nATR);
def UP4 = hl4 + (AtrMult * ATR4);
def DN4 = hl4 + (-AtrMult * ATR4);
def S4 = if c4 < S4[1] then Round(UP4 / TickSize(), 0) * TickSize() else Round(DN4 / TickSize(), 0) * TickSize();

def h5 = Fundamental(Fh, period = agg5);
def l5 = Fundamental(Fl, period = agg5);
def c5 = Fundamental(Fc, period = agg5);
def hl5 = Fundamental(Fhl2, period = agg5);
def ATR5 = MovingAverage(AvgType, TrueRange(h5, c5, l5), nATR);
def UP5 = hl5 + (AtrMult * ATR5);
def DN5 = hl5 + (-AtrMult * ATR5);
def S5 = if c5 < S5[1] then Round(UP5 / TickSize(), 0) * TickSize() else Round(DN5 / TickSize(), 0) * TickSize();

plot hLine = Line ;
hLine.SetDefaultColor(GlobalColor("Line"));
plot lLine = -Line;
lLine.SetDefaultColor(GlobalColor("Line"));
def cl = close;
def x = IsNaN(cl[2]) and !IsNaN(cl[3]);

def FirstAgg = if c > S then 1 else 0;
plot FirstAggPlot = if IsNaN(cl) then Double.NaN else 1;
FirstAggPlot.SetStyle(Curve.POINTS);
FirstAggPlot.SetLineWeight(2);
FirstAggPlot.AssignValueColor(if FirstAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, 1, (agg1 / 1000 / 60) + " min", Color.WHITE, yes);

def SecondAgg =  if c2 > S2 then 1 else 0;
plot SecondAggPlot = if IsNaN(cl) then Double.NaN else 0.5;
SecondAggPlot.SetStyle(Curve.POINTS);
SecondAggPlot.SetLineWeight(3);
SecondAggPlot.AssignValueColor(if SecondAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, 0.5, (agg2 / 1000 / 60) + " min", Color.WHITE, yes);

def ThirdAgg =  if c3 > S3 then 1 else 0;
plot ThirdAggPlot = if IsNaN(cl) then Double.NaN else 0;
ThirdAggPlot.SetStyle(Curve.POINTS);
ThirdAggPlot.SetLineWeight(3);
ThirdAggPlot.AssignValueColor(if ThirdAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, 0, (agg3 / 1000 / 60) + " min", Color.WHITE, yes);

def FourthAgg =  if c4 > S4 then 1 else 0;
plot FourthAggPlot = if IsNaN(cl) then Double.NaN else -0.5;
FourthAggPlot.SetStyle(Curve.POINTS);
FourthAggPlot.SetLineWeight(4);
FourthAggPlot.AssignValueColor(if FourthAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, -0.5, (agg4 / 1000 / 60) + " min", Color.WHITE, yes);

def FifthAgg =  if c5 > S5 then 1 else 0;
plot FifthAggPlot = if IsNaN(cl) then Double.NaN else -1;
FifthAggPlot.SetStyle(Curve.POINTS);
FifthAggPlot.SetLineWeight(4);
FifthAggPlot.AssignValueColor(if FifthAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));

AddChartBubble(x, -1, (agg5 / 1000 / 60) + " min", Color.WHITE, yes);
plot Direction = if (FirstAgg and SecondAgg and ThirdAgg and FourthAgg and FifthAgg) then hLine + .5 else if (!FirstAgg and !SecondAgg and !ThirdAgg and !FourthAgg and !FifthAgg) then lLine - .5 else Double.NaN;

def Bullish = (if FirstAgg and SecondAgg and ThirdAgg and FourthAgg and FifthAgg then 1 else 0);
def Bearish = (if !FirstAgg and !SecondAgg and !ThirdAgg and !FourthAgg and !FifthAgg then 1 else 0);

Direction.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Direction.SetLineWeight(4);
Direction.AssignValueColor(if Bullish then GlobalColor ("Buy") else if Bearish then GlobalColor ("Sell") else Color.BLACK);

Alert(audibleAlerts and Bullish, "SuperTrend UpTrend Started",   Alert.BAR, Sound.Ding);
Alert(audibleAlerts and Bearish, "SuperTrend DownTrend Started", Alert.BAR, Sound.Ring);

# End Code ST MTF
hey @SuryaKiranC is there a break down or explanation anywhere of this, im pretty new and trying to figure this thing out
 
@bennyRA Super Trend is a well know Price/Upper Chat indicator that that tacks trend and plots there are various version out there. Following is the Original code for Super Trend to the best of my knowledge.

https://usethinkscript.com/threads/supertrend-indicator-by-mobius-for-thinkorswim.7/

Super Trend MTF is a lower indicator, where it can plot the 3 or 4 different, including Current chart Timeframe and/or Higher Frames. They plot green or red dots, based on trend.

What I found was, the higher timeframes were static and was convenient for somebody like me who would flip through timetrames multiple times in a day on multiple tickers.

So, I have coded this to show Super_Trend for current chart timeframe and 4 other Higher Frames, and the Higher Frames are auto selected based on your chart current time frame.

In addition to that what I am doing is, if all 5 TimeFrames, current and 4 Higher are in the same trend plot a Green Triangle or Red Triangle in the bottom if all the 5 Time Frame Trends are Red.

Let me know if this help, of you need more information.

PS: Chart frames to use is anything upto 4 hrs. Above that this version of SuperTrend_MTF will not plot anything.

-S
 
Thanks for the indicator and detailed info. So i can understand well, first green or red triangle will appear and stay after first candle of the lower time closed or it would do so after the larger time frame closes its candle? Lets say I'm on 1 min chart so first triangle appear after 1 min candle and based on others timeframes?
 
@tem2005 Just like the Super_Trend upper indicator this is a repainting Indicator, that mean each Green/Red Dot will continue to repaint till the correspondent TF candle is closed, and the Triangle appears Green as long as all 5 Frames old the same trend, It helps visually, what side of the trade you would want to take.
 
@tem2005 Just like the Super_Trend upper indicator this is a repainting Indicator, that mean each Green/Red Dot will continue to repaint till the correspondent TF candle is closed, and the Triangle appears Green as long as all 5 Frames old the same trend, It helps visually, what side of the trade you would want to take.
Is it possible to add an extra option to the indicator that lets we can set the confirmation factors to how many timeframe we want? Like i do 3 timeframes instead of 5 to make triangles appear quicker?
 
Is it possible to add an extra option to the indicator that lets we can set the confirmation factors to how many timeframe we want? Like i do 3 timeframes instead of 5 to make triangles appear quicker?

Sure. The following are my conditions to plot those Green or Red Triangles, you can always add additional condition options in the if/then/else statements and give yourself different color triangle plots for your conditions.

Ruby:
def Bullish = (if FirstAgg and SecondAgg and ThirdAgg and FourthAgg and FifthAgg then 1 else 0);
def Bearish = (if !FirstAgg and !SecondAgg and !ThirdAgg and !FourthAgg and !FifthAgg then 1 else 0);
 
Was debating for a while, if the forum needs yet another Super Trend Indicator. Anyways, decided to post since there isn't one that is selecting Higher Frames automatically based on chart frames. Base parameters of this not not my own, this is a equivalent of Super Trend yahoo version parameters. Feel free to make it your own, with modified nATR and ATRMulti inputs.

There are version that get passed as MTF, but there is only one HF (Higher Frame) defined, that may be fine for an upper indicator, but in my opinion a True, lower MTF version should have more than one higher TF and should be able to auto switch the Higher TF automatically based on Chart TF.

Note: Indicator Repaints, till the candle closes, that's applicable for Higher Frame plots too.

Ruby:
# SuperTrend Multiple Time Frames
# Modifled by SuryaKiranC
# V05.06.2021
# An attempt to Support autoswitch of Highr Frames with chart frame changes.
# Provide Support for Chart Frame 1m to 4H.
# Aggrigate of SuperTrend Bullish is plotted in Green above Dots/ Bearish is plotted in Red below Dots.
# ATRMult & nATR values are different from original and can be adjusted by user.
# Mobius
# V03.01.2016

# I pulled this study down from MyTrade for a reason. It wasn't
# plotting correctly with the multiple aggregations. And like
# all studies with secondary aggregations it tends to replot the
# higher ones. I decided to think about it some more and this is
# where I am with the ST MTF study now.
#
# It's still squirrely and blinks a lot. Using declare Once_Per_Bar
# does some bad things to it. I was considering making intra
# aggregation higher time frames. A pain to do but it gives more
# control over how it plots.
#
# Row 6 is supposed to be the output for all aggregations and the
# signal line. After hours when data isn't moving it's steady and
# has good signals. But since it's after hours, totally useless
# for any intraday trading.

declare hide_on_daily;
declare lower;
declare once_per_bar;
declare real_size;

input audibleAlerts = yes;

def _aP1 = GetAggregationPeriod();
def _aP2 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.THREE_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.FOUR_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.FIVE_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.TWENTY_MIN else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.FOUR_HOURS else AggregationPeriod.DAY);

def _aP3 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.FIVE_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.DAY else AggregationPeriod.TWO_DAYS);

def _aP4 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.TWENTY_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.DAY else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.TWO_DAYS else AggregationPeriod.THREE_DAYS);

def _aP5 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.TWENTY_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.DAY else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.TWO_DAYS else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.THREE_DAYS else AggregationPeriod.FOUR_DAYS);

def agg1 = _aP1;
def agg2 = _aP2;
def agg3 = _aP3;
def agg4 = _aP4;
def agg5 = _aP5;

input AtrMult = 1;
input nATR = 6;
input AvgType = AverageType.HULL;

DefineGlobalColor ("Line", Color.LIGHT_GRAY);
DefineGlobalColor ("TrendUp", Color.LIGHT_GREEN);
DefineGlobalColor ("TrendDown", Color.LIGHT_RED);
DefineGlobalColor ("Buy", Color.GREEN);
DefineGlobalColor ("Sell", Color.RED);

def Line = 1.75;

def Fh = FundamentalType.HIGH;
def Fl = FundamentalType.LOW;
def Fc = FundamentalType.CLOSE;
def Fhl2 = FundamentalType.HL2;

def h = Fundamental(Fh, period = agg1);
def l = Fundamental(Fl, period = agg1);
def c = Fundamental(Fc, period = agg1);
def hl = Fundamental(Fhl2, period = agg1);
def ATR = MovingAverage(AvgType, TrueRange(h, c, l), nATR);
def UP = hl + (AtrMult * ATR);
def DN = hl + (-AtrMult * ATR);
def S = if c < S[1] then Round(UP / TickSize(), 0) * TickSize() else Round(DN / TickSize(), 0) * TickSize();

def h2 = Fundamental(Fh, period = agg2);
def l2 = Fundamental(Fl, period = agg2);
def c2 = Fundamental(Fc, period = agg2);
def hl2 = Fundamental(Fhl2, period = agg2);
def ATR2 = MovingAverage(AvgType, TrueRange(h2, c2, l2), nATR);
def UP2 = hl2 + (AtrMult * ATR2);
def DN2 = hl2 + (-AtrMult * ATR2);
def S2 = if c2 < S2[1] then Round(UP2 / TickSize(), 0) * TickSize() else Round(DN2 / TickSize(), 0) * TickSize();

def h3 = Fundamental(Fh, period = agg3);
def l3 = Fundamental(Fl, period = agg3);
def c3 = Fundamental(Fc, period = agg3);
def hl3 = Fundamental(Fhl2, period = agg3);
def ATR3 = MovingAverage(AvgType, TrueRange(h3, c3, l3), nATR);
def UP3 = hl3 + (AtrMult * ATR3);
def DN3 = hl3 + (-AtrMult * ATR3);
def S3 = if c3 < S3[1] then Round(UP3 / TickSize(), 0) * TickSize() else Round(DN3 / TickSize(), 0) * TickSize();

def h4 = Fundamental(Fh, period = agg4);
def l4 = Fundamental(Fl, period = agg4);
def c4 = Fundamental(Fc, period = agg4);
def hl4 = Fundamental(Fhl2, period = agg4);
def ATR4 = MovingAverage(AvgType, TrueRange(h4, c4, l4), nATR);
def UP4 = hl4 + (AtrMult * ATR4);
def DN4 = hl4 + (-AtrMult * ATR4);
def S4 = if c4 < S4[1] then Round(UP4 / TickSize(), 0) * TickSize() else Round(DN4 / TickSize(), 0) * TickSize();

def h5 = Fundamental(Fh, period = agg5);
def l5 = Fundamental(Fl, period = agg5);
def c5 = Fundamental(Fc, period = agg5);
def hl5 = Fundamental(Fhl2, period = agg5);
def ATR5 = MovingAverage(AvgType, TrueRange(h5, c5, l5), nATR);
def UP5 = hl5 + (AtrMult * ATR5);
def DN5 = hl5 + (-AtrMult * ATR5);
def S5 = if c5 < S5[1] then Round(UP5 / TickSize(), 0) * TickSize() else Round(DN5 / TickSize(), 0) * TickSize();

plot hLine = Line ;
hLine.SetDefaultColor(GlobalColor("Line"));
plot lLine = -Line;
lLine.SetDefaultColor(GlobalColor("Line"));
def cl = close;
def x = IsNaN(cl[2]) and !IsNaN(cl[3]);

def FirstAgg = if c > S then 1 else 0;
plot FirstAggPlot = if IsNaN(cl) then Double.NaN else 1;
FirstAggPlot.SetStyle(Curve.POINTS);
FirstAggPlot.SetLineWeight(2);
FirstAggPlot.AssignValueColor(if FirstAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, 1, (agg1 / 1000 / 60) + " min", Color.WHITE, yes);

def SecondAgg =  if c2 > S2 then 1 else 0;
plot SecondAggPlot = if IsNaN(cl) then Double.NaN else 0.5;
SecondAggPlot.SetStyle(Curve.POINTS);
SecondAggPlot.SetLineWeight(3);
SecondAggPlot.AssignValueColor(if SecondAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, 0.5, (agg2 / 1000 / 60) + " min", Color.WHITE, yes);

def ThirdAgg =  if c3 > S3 then 1 else 0;
plot ThirdAggPlot = if IsNaN(cl) then Double.NaN else 0;
ThirdAggPlot.SetStyle(Curve.POINTS);
ThirdAggPlot.SetLineWeight(3);
ThirdAggPlot.AssignValueColor(if ThirdAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, 0, (agg3 / 1000 / 60) + " min", Color.WHITE, yes);

def FourthAgg =  if c4 > S4 then 1 else 0;
plot FourthAggPlot = if IsNaN(cl) then Double.NaN else -0.5;
FourthAggPlot.SetStyle(Curve.POINTS);
FourthAggPlot.SetLineWeight(4);
FourthAggPlot.AssignValueColor(if FourthAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, -0.5, (agg4 / 1000 / 60) + " min", Color.WHITE, yes);

def FifthAgg =  if c5 > S5 then 1 else 0;
plot FifthAggPlot = if IsNaN(cl) then Double.NaN else -1;
FifthAggPlot.SetStyle(Curve.POINTS);
FifthAggPlot.SetLineWeight(4);
FifthAggPlot.AssignValueColor(if FifthAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));

AddChartBubble(x, -1, (agg5 / 1000 / 60) + " min", Color.WHITE, yes);
plot Direction = if (FirstAgg and SecondAgg and ThirdAgg and FourthAgg and FifthAgg) then hLine + .5 else if (!FirstAgg and !SecondAgg and !ThirdAgg and !FourthAgg and !FifthAgg) then lLine - .5 else Double.NaN;

def Bullish = (if FirstAgg and SecondAgg and ThirdAgg and FourthAgg and FifthAgg then 1 else 0);
def Bearish = (if !FirstAgg and !SecondAgg and !ThirdAgg and !FourthAgg and !FifthAgg then 1 else 0);

Direction.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Direction.SetLineWeight(4);
Direction.AssignValueColor(if Bullish then GlobalColor ("Buy") else if Bearish then GlobalColor ("Sell") else Color.BLACK);

Alert(audibleAlerts and Bullish, "SuperTrend UpTrend Started",   Alert.BAR, Sound.Ding);
Alert(audibleAlerts and Bearish, "SuperTrend DownTrend Started", Alert.BAR, Sound.Ring);

# End Code ST MTF
any idea on How I can scan for FirstAgg? thanks
 
@fingerlakes FirstAggr is always the chart aggr, up to 4 hours anyways, you don't need a special scanner. Just look for a SuperMTF Scanner here on the forum, match the setting of this indicator. what you define the timeframe on the scanner would be matching the chart timeframe you like to trade.
 
@fingerlakes FirstAggr is always the chart aggr, up to 4 hours anyways, you don't need a special scanner. Just look for a SuperMTF Scanner here on the forum, match the setting of this indicator. what you define the timeframe on the scanner would be matching the chart timeframe you like to trade.
I dont see a scanner script on the thread. I use a 5 min chart, when I search it has 0 results so its not working. How would you scan for firstagg on a 5 min chart? thanks
 
@bennyRA Super Trend is a well know Price/Upper Chat indicator that that tacks trend and plots there are various version out there. Following is the Original code for Super Trend to the best of my knowledge.

https://usethinkscript.com/threads/supertrend-indicator-by-mobius-for-thinkorswim.7/

Super Trend MTF is a lower indicator, where it can plot the 3 or 4 different, including Current chart Timeframe and/or Higher Frames. They plot green or red dots, based on trend.

What I found was, the higher timeframes were static and was convenient for somebody like me who would flip through timetrames multiple times in a day on multiple tickers.

So, I have coded this to show Super_Trend for current chart timeframe and 4 other Higher Frames, and the Higher Frames are auto selected based on your chart current time frame.

In addition to that what I am doing is, if all 5 TimeFrames, current and 4 Higher are in the same trend plot a Green Triangle or Red Triangle in the bottom if all the 5 Time Frame Trends are Red.

Let me know if this help, of you need more information.

PS: Chart frames to use is anything upto 4 hrs. Above that this version of SuperTrend_MTF will not plot anything.

-S


Hey good afternoon. This study is amazing, best I've come across. Is there a way to remove the bubbles in the lower study that show the timeframe for each aggregation? Mine has bubbles for 2min, 4 min, etc. And those bubbles are in the way :-(
 
@jdouglas2002 you would want that, so you know what timeframes you are looking at. they way to handle it is give yourself about 20 bars space on the time chart. Settings --> TimeAccess --> Expansion Area (20 or 25) should do.

But if you want it gone, just remove or comment all the AddChartBubble Lines

Ex:
Ruby:
#AddChartBubble(x, 1, (agg1 / 1000 / 60) + " min", Color.WHITE, yes);

-S
 
Was debating for a while, if the forum needs yet another Super Trend Indicator. Anyways, decided to post since there isn't one that is selecting Higher Frames automatically based on chart frames. Base parameters of this not not my own, this is a equivalent of Super Trend yahoo version parameters. Feel free to make it your own, with modified nATR and ATRMulti inputs.

There are version that get passed as MTF, but there is only one HF (Higher Frame) defined, that may be fine for an upper indicator, but in my opinion a True, lower MTF version should have more than one higher TF and should be able to auto switch the Higher TF automatically based on Chart TF.

Note: Indicator Repaints, till the candle closes, that's applicable for Higher Frame plots too.

Ruby:
# SuperTrend Multiple Time Frames
# Modifled by SuryaKiranC
# V05.06.2021
# An attempt to Support autoswitch of Highr Frames with chart frame changes.
# Provide Support for Chart Frame 1m to 4H.
# Aggrigate of SuperTrend Bullish is plotted in Green above Dots/ Bearish is plotted in Red below Dots.
# ATRMult & nATR values are different from original and can be adjusted by user.
# Mobius
# V03.01.2016

# I pulled this study down from MyTrade for a reason. It wasn't
# plotting correctly with the multiple aggregations. And like
# all studies with secondary aggregations it tends to replot the
# higher ones. I decided to think about it some more and this is
# where I am with the ST MTF study now.
#
# It's still squirrely and blinks a lot. Using declare Once_Per_Bar
# does some bad things to it. I was considering making intra
# aggregation higher time frames. A pain to do but it gives more
# control over how it plots.
#
# Row 6 is supposed to be the output for all aggregations and the
# signal line. After hours when data isn't moving it's steady and
# has good signals. But since it's after hours, totally useless
# for any intraday trading.

declare hide_on_daily;
declare lower;
declare once_per_bar;
declare real_size;

input audibleAlerts = yes;

def _aP1 = GetAggregationPeriod();
def _aP2 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.THREE_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.FOUR_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.FIVE_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.TWENTY_MIN else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.FOUR_HOURS else AggregationPeriod.DAY);

def _aP3 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.FIVE_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.DAY else AggregationPeriod.TWO_DAYS);

def _aP4 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.TEN_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.TWENTY_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.DAY else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.TWO_DAYS else AggregationPeriod.THREE_DAYS);

def _aP5 = (
if _aP1 == AggregationPeriod.MIN then AggregationPeriod.FIFTEEN_MIN else
if _aP1 == AggregationPeriod.TWO_MIN then AggregationPeriod.TWENTY_MIN else
if _aP1 == AggregationPeriod.THREE_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.FOUR_MIN then AggregationPeriod.THIRTY_MIN else
if _aP1 == AggregationPeriod.FIVE_MIN then AggregationPeriod.HOUR else
if _aP1 == AggregationPeriod.TEN_MIN then AggregationPeriod.TWO_HOURS else
if _aP1 == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.TWENTY_MIN then AggregationPeriod.FOUR_HOURS else
if _aP1 == AggregationPeriod.THIRTY_MIN then AggregationPeriod.DAY else
if _aP1 == AggregationPeriod.HOUR then AggregationPeriod.TWO_DAYS else
if _aP1 == AggregationPeriod.TWO_HOURS then AggregationPeriod.THREE_DAYS else AggregationPeriod.FOUR_DAYS);

def agg1 = _aP1;
def agg2 = _aP2;
def agg3 = _aP3;
def agg4 = _aP4;
def agg5 = _aP5;

input AtrMult = 1;
input nATR = 6;
input AvgType = AverageType.HULL;

DefineGlobalColor ("Line", Color.LIGHT_GRAY);
DefineGlobalColor ("TrendUp", Color.LIGHT_GREEN);
DefineGlobalColor ("TrendDown", Color.LIGHT_RED);
DefineGlobalColor ("Buy", Color.GREEN);
DefineGlobalColor ("Sell", Color.RED);

def Line = 1.75;

def Fh = FundamentalType.HIGH;
def Fl = FundamentalType.LOW;
def Fc = FundamentalType.CLOSE;
def Fhl2 = FundamentalType.HL2;

def h = Fundamental(Fh, period = agg1);
def l = Fundamental(Fl, period = agg1);
def c = Fundamental(Fc, period = agg1);
def hl = Fundamental(Fhl2, period = agg1);
def ATR = MovingAverage(AvgType, TrueRange(h, c, l), nATR);
def UP = hl + (AtrMult * ATR);
def DN = hl + (-AtrMult * ATR);
def S = if c < S[1] then Round(UP / TickSize(), 0) * TickSize() else Round(DN / TickSize(), 0) * TickSize();

def h2 = Fundamental(Fh, period = agg2);
def l2 = Fundamental(Fl, period = agg2);
def c2 = Fundamental(Fc, period = agg2);
def hl2 = Fundamental(Fhl2, period = agg2);
def ATR2 = MovingAverage(AvgType, TrueRange(h2, c2, l2), nATR);
def UP2 = hl2 + (AtrMult * ATR2);
def DN2 = hl2 + (-AtrMult * ATR2);
def S2 = if c2 < S2[1] then Round(UP2 / TickSize(), 0) * TickSize() else Round(DN2 / TickSize(), 0) * TickSize();

def h3 = Fundamental(Fh, period = agg3);
def l3 = Fundamental(Fl, period = agg3);
def c3 = Fundamental(Fc, period = agg3);
def hl3 = Fundamental(Fhl2, period = agg3);
def ATR3 = MovingAverage(AvgType, TrueRange(h3, c3, l3), nATR);
def UP3 = hl3 + (AtrMult * ATR3);
def DN3 = hl3 + (-AtrMult * ATR3);
def S3 = if c3 < S3[1] then Round(UP3 / TickSize(), 0) * TickSize() else Round(DN3 / TickSize(), 0) * TickSize();

def h4 = Fundamental(Fh, period = agg4);
def l4 = Fundamental(Fl, period = agg4);
def c4 = Fundamental(Fc, period = agg4);
def hl4 = Fundamental(Fhl2, period = agg4);
def ATR4 = MovingAverage(AvgType, TrueRange(h4, c4, l4), nATR);
def UP4 = hl4 + (AtrMult * ATR4);
def DN4 = hl4 + (-AtrMult * ATR4);
def S4 = if c4 < S4[1] then Round(UP4 / TickSize(), 0) * TickSize() else Round(DN4 / TickSize(), 0) * TickSize();

def h5 = Fundamental(Fh, period = agg5);
def l5 = Fundamental(Fl, period = agg5);
def c5 = Fundamental(Fc, period = agg5);
def hl5 = Fundamental(Fhl2, period = agg5);
def ATR5 = MovingAverage(AvgType, TrueRange(h5, c5, l5), nATR);
def UP5 = hl5 + (AtrMult * ATR5);
def DN5 = hl5 + (-AtrMult * ATR5);
def S5 = if c5 < S5[1] then Round(UP5 / TickSize(), 0) * TickSize() else Round(DN5 / TickSize(), 0) * TickSize();

plot hLine = Line ;
hLine.SetDefaultColor(GlobalColor("Line"));
plot lLine = -Line;
lLine.SetDefaultColor(GlobalColor("Line"));
def cl = close;
def x = IsNaN(cl[2]) and !IsNaN(cl[3]);

def FirstAgg = if c > S then 1 else 0;
plot FirstAggPlot = if IsNaN(cl) then Double.NaN else 1;
FirstAggPlot.SetStyle(Curve.POINTS);
FirstAggPlot.SetLineWeight(2);
FirstAggPlot.AssignValueColor(if FirstAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, 1, (agg1 / 1000 / 60) + " min", Color.WHITE, yes);

def SecondAgg =  if c2 > S2 then 1 else 0;
plot SecondAggPlot = if IsNaN(cl) then Double.NaN else 0.5;
SecondAggPlot.SetStyle(Curve.POINTS);
SecondAggPlot.SetLineWeight(3);
SecondAggPlot.AssignValueColor(if SecondAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, 0.5, (agg2 / 1000 / 60) + " min", Color.WHITE, yes);

def ThirdAgg =  if c3 > S3 then 1 else 0;
plot ThirdAggPlot = if IsNaN(cl) then Double.NaN else 0;
ThirdAggPlot.SetStyle(Curve.POINTS);
ThirdAggPlot.SetLineWeight(3);
ThirdAggPlot.AssignValueColor(if ThirdAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, 0, (agg3 / 1000 / 60) + " min", Color.WHITE, yes);

def FourthAgg =  if c4 > S4 then 1 else 0;
plot FourthAggPlot = if IsNaN(cl) then Double.NaN else -0.5;
FourthAggPlot.SetStyle(Curve.POINTS);
FourthAggPlot.SetLineWeight(4);
FourthAggPlot.AssignValueColor(if FourthAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));
AddChartBubble(x, -0.5, (agg4 / 1000 / 60) + " min", Color.WHITE, yes);

def FifthAgg =  if c5 > S5 then 1 else 0;
plot FifthAggPlot = if IsNaN(cl) then Double.NaN else -1;
FifthAggPlot.SetStyle(Curve.POINTS);
FifthAggPlot.SetLineWeight(4);
FifthAggPlot.AssignValueColor(if FifthAgg then GlobalColor("TrendUp") else  GlobalColor("TrendDown"));

AddChartBubble(x, -1, (agg5 / 1000 / 60) + " min", Color.WHITE, yes);
plot Direction = if (FirstAgg and SecondAgg and ThirdAgg and FourthAgg and FifthAgg) then hLine + .5 else if (!FirstAgg and !SecondAgg and !ThirdAgg and !FourthAgg and !FifthAgg) then lLine - .5 else Double.NaN;

def Bullish = (if FirstAgg and SecondAgg and ThirdAgg and FourthAgg and FifthAgg then 1 else 0);
def Bearish = (if !FirstAgg and !SecondAgg and !ThirdAgg and !FourthAgg and !FifthAgg then 1 else 0);

Direction.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Direction.SetLineWeight(4);
Direction.AssignValueColor(if Bullish then GlobalColor ("Buy") else if Bearish then GlobalColor ("Sell") else Color.BLACK);

Alert(audibleAlerts and Bullish, "SuperTrend UpTrend Started",   Alert.BAR, Sound.Ding);
Alert(audibleAlerts and Bearish, "SuperTrend DownTrend Started", Alert.BAR, Sound.Ring);

# End Code ST MTF
Came across this today and tested it. Seems to test well, but noticed the repaint is worse than expected. It updates various candles back than just previous. Have you been able to resolve this or is it something with my system? I'm using 2m chart.
 
Came across this today and tested it. Seems to test well, but noticed the repaint is worse than expected. It updates various candles back than just previous. Have you been able to resolve this or is it something with my system? I'm using 2m chart.
When placing a higher timeframe indicator on a lower timeframe chart there will ALWAYS be repainting until the higher timeframe candle closes. If there is a 4hr indicator on a 15min chart, it will continually repaint all the previous 16 bars because it has no idea what the close of the 4hr bar is until the 4hr candle close, 4hrs from now.

5min on a 2min will be correct once every 10bars.

This is because we can't predict what those future bars are going to look like. You will find that this is built-into the DNA of all multi-timeframe indicators. By definition the bars cannot know what the final close is going to be until the close actually happens.
 
Last edited:
When placing a higher timeframe indicator on a lower timeframe chart there will ALWAYS be repainting until the higher timeframe candle closes. If there is a 4hr indicator on a 15min chart, it will continually repaint all the previous 16 bars because it has no idea what the close of the 4hr bar is until the 4hr candle close, 4hrs from now.

5min on a 2min will be correct once every 10bars.

Because we can't predict what those future bars are going to look like, you will find that this is built-into the DNA of all multi-timeframe indicators. By definition the bars cannot know what the final close is going to be until the close actually happens.
Makes sense. thanks for the clarification.
 
I want to extend a huge thank you to the OP for posting this study. It has been a total game changer for me. Previously I was using supertrend with mixed success. Now I'm using this study and waiting until all the dots are aligned before entering a trade. Thank you!!
 
Would it be possible to modify this to a custom watchlist column, to display the green/red triangle condition?
I want to extend a huge thank you to the OP for posting this study. It has been a total game changer for me. Previously I was using supertrend with mixed success. Now I'm using this study and waiting until all the dots are aligned before entering a trade. Thank you!!

Multiple Time Frames

The ToS platform does not allow multiple timeframes to be used in the scan hacker, watchlists, conditional orders, etc...
multiple timeframes can only be used for plotting on a chart.

Using MTFs on a chart:
  1. Use of multiple time frames in a strategy can be integral to success. Plotting the higher time frame on the time-frame that you are trading on, eliminates the need to have multiple charts open.
  2. MTF indicators should ONLY be used for the overall analysis.
  3. MTF indicators should NOT be used to analyze the current bar / candle for entry or exit due to repainting behavior which causes phantom signals to appear and disappear until the candle closes on the higher aggregation.
Having Problems? Does the MTF indicator appear to be not working or partially working when you load the study onto your chart?
A common error when using MTF indicators is trying to use a time frame that is lower than the chart you are posting it on. On the TOS platform, you can display data from a higher timeframe onto a lower timeframe but not the other way around.
https://tlc.thinkorswim.com/center/...hapter-11---Referencing-Secondary-Aggregation

HTH
 
Last edited:
Thanks for this info! I've just discovered supertrend, and MTF, and the two combined seem really powerful. As an alternative to a watchlist column, would it be possible to have an upper chart label that indicates when the green or red condition is met?
 

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