#### 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.

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: