Here is my version of the TTM Trend "5 Bar" It does not match up bar for bar, but as an indicator it works out.
Here is the Labels for the above indicator they will show support from the higher time frames. Plot several of them in the same section of the chart.
Code:
####################################################
declare Lower;
def o = Open;
def C = Close;
def H = High;
def L = Low;
def data = Sum((O+H+L+C)/4,6)/6;
def TRend1 = if C >= data then 1 else 0;
def TRend2 = if C >= data[1] then 1 else 0;
def TRend3 = if C >= data[2] then 1 else 0;
def TRend4 = if C >= data[3] then 1 else 0;
def TRend5 = if C >= data[4] then 1 else 0;
def half = 2.5;
Plot TotalT = (TRend1 + TRend2 + TRend3 + TRend4 + Trend5);
TotalT.AssignValueColor(if TotalT < half then Color.RED else Color.GREEN);
TotalT.setLineWeight(3);
AddCloud(TotalT, Half, Color.Light_Green, Color.Light_Red, no);
#################################################
Here is the Labels for the above indicator they will show support from the higher time frames. Plot several of them in the same section of the chart.
Code:
##################################################
declare lower;
input period = AggregationPeriod.DAY;
DefineGlobalColor("Long", Color.Green);
DefineGlobalColor("Short", Color.RED);
DefineGlobalColor("Neutral", Color.Yellow);
DefineGlobalColor("arrow Buy", Color.Cyan);
DefineGlobalColor("arrow Sell", Color.Orange);
Script SymbolTTrend{
input period = AggregationPeriod.DAY;
def OP = Open(period= period);
def CP = Close(Period= period);
def HP = High(period= period);
def LP = Low(Period= period);
def data = Sum((OP+HP+LP+CP)/4,6)/6;
def TRend1 = if CP >= data then 1 else 0;
def TRend2 = if CP >= data[1] then 1 else 0;
def TRend3 = if CP >= data[2] then 1 else 0;
def TRend4 = if CP >= data[3] then 1 else 0;
def TRend5 = if CP >= data[4] then 1 else 0;
Def TotalT = (TRend1 + TRend2 + TRend3 + TRend4 + Trend5);
Plot Result = If TotalT > 2.5 then 1 else 0;}
Script SymbolSignal{
input period = AggregationPeriod.DAY;
def OP = Open(period= period);
def CP = Close(Period= period);
def HP = High(period= period);
def LP = Low(Period= period);
def data = Sum((OP+HP+LP+CP)/4,6)/6;
def TRend1 = if CP >= data then 1 else 0;
def TRend2 = if CP >= data[1] then 1 else 0;
def TRend3 = if CP >= data[2] then 1 else 0;
def TRend4 = if CP >= data[3] then 1 else 0;
def TRend5 = if CP >= data[4] then 1 else 0;
Def TotalT = (TRend1 + TRend2 + TRend3 + TRend4 + Trend5);
Plot Result = If TotalT crosses Above 2.5 then 1 else If TotalT Crosses Below 2.5 then -1 else 0;}
def currentPeriod = GetAggregationPeriod();
def s1;
def h1;
if period >= currentPeriod {
s1 = SymbolTTrend(period = period );
h1 = SymbolSignal(period = period);
} else {
s1 = Double.NaN;
h1 = DOuble.Nan;
}
AddLabel(!IsNaN(s1), "TTMT:" + (if period == AggregationPeriod.MONTH then "M"
else
if period == AggregationPeriod.WEEK then "W"
else
if period == AggregationPeriod.FOUR_DAYS then "4D"
else
if period == AggregationPeriod.THREE_DAYS then "3D"
else
if period == AggregationPeriod.TWO_DAYS then "2D"
else
if period == AggregationPeriod.DAY then "D"
else
if period == AggregationPeriod.FOUR_HOURS then "4H"
else
if period == AggregationPeriod.TWO_HOURS then "2H"
else
if period == AggregationPeriod.HOUR then "60m"
else
if period == AggregationPeriod.THIRTY_MIN then "30m"
else
if period == AggregationPeriod.TWENTY_MIN then "20m"
else
if period == AggregationPeriod.FIFTEEN_MIN then "15m"
else
if period == AggregationPeriod.TEN_MIN then "10m"
else
if period == AggregationPeriod.FIVE_MIN then "5m"
else
if period == AggregationPeriod.FOUR_MIN then "4m"
else
if period == AggregationPeriod.THREE_MIN then "3m"
else
if period == AggregationPeriod.TWO_MIN then "2m"
else
if period == AggregationPeriod.MIN then "1m"
else ""), if s1 == 1 then GlobalColor("Long") else if s1 == 0 then GlobalColor("Short") else GlobalColor("Neutral"));
AddLabel(!IsNaN(h1) and h1 != 0, If h1 == 1 then "B" else if h1 == -1 then "S" else "-", if h1 == 1 then GlobalColor("arrow Buy") else if h1 == -1 then GlobalColor("arrow Sell") else color.gray);
TTM Trend Multi-TimeFrame
Code:
##############################
Declare Lower;
# GLOBAL DEFINITIONS
DefineGlobalColor("TrendUp", CreateColor(0, 254, 30));
DefineGlobalColor("TrendDown", CreateColor(255, 3, 2));
input agg = AggregationPeriod.FIVE_MIN;
input agg2 = AggregationPeriod.THIRTY_MIN;
input agg3 = AggregationPeriod.HOUR;
input agg4 = AggregationPeriod.TWO_Hours;;
input agg5 = AggregationPeriod.FOUR_HOURs;
input agg6 = AggregationPeriod.DAY;
input DotSize = 3;
input n = 6;
def n1 = n + 1;
#Aggregation 1
def o = Open(Period = AGG);
def C = Close(Period =AGG);
def H = High(Period = AGG);
def L = Low(Period = AGG);
def Adata = Sum((O+H+L+C)/4,6)/6;
def ATRend1 = if C >= Adata then 1 else 0;
def ATRend2 = if C >= Adata[1] then 1 else 0;
def ATRend3 = if C >= Adata[2] then 1 else 0;
def ATRend4 = if C >= Adata[3] then 1 else 0;
def ATRend5 = if C >= Adata[4] then 1 else 0;
Def TotalT = (ATRend1 + ATRend2 + ATRend3 + ATRend4 + ATrend5);
plot TT1_Dot = if IsNaN(c) then Double.NaN else 1;
TT1_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
TT1_Dot.SetLineWeight(DotSize);
TT1_Dot.AssignValueColor(if 2.5 > TotalT then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(c [n1]) and IsNaN(c [n]), 1, (agg/1000/60) + " min", Color.Yellow, yes);
#Aggregation 2
def o2 = Open(Period = AGG2);
def C2 = Close(Period =AGG2);
def H2 = High(Period = AGG2);
def L2 = Low(Period = AGG2);
def Bdata = Sum((O2+H2+L2+C2)/4,6)/6;
def BTRend1 = if C2 >= Bdata then 1 else 0;
def BTRend2 = if C2 >= Bdata[1] then 1 else 0;
def BTRend3 = if C2 >= Bdata[2] then 1 else 0;
def BTRend4 = if C2 >= Bdata[3] then 1 else 0;
def BTRend5 = if C2 >= Bdata[4] then 1 else 0;
Def TotalT2 = (BTRend1 + BTRend2 + BTRend3 + BTRend4 + BTrend5);
plot TT2_Dot = if IsNaN(c2) then Double.NaN else 2;
TT2_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
TT2_Dot.SetLineWeight(DotSize);
TT2_Dot.AssignValueColor(if 2.5 > TotalT2 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(c2[n1]) and IsNaN(c2[n]), 2, (agg2/1000/60) + " min", Color.Yellow, yes);
#Aggregation 3
def O3 = Open(Period = AGG3);
def C3 = Close(Period =AGG3);
def H3 = High(Period = AGG3);
def L3 = Low(Period = AGG3);
def Cdata = Sum((O3+H3+L3+C3)/4,6)/6;
def CTRend1 = if C3 >= Cdata then 1 else 0;
def CTRend2 = if C3 >= Cdata[1] then 1 else 0;
def CTRend3 = if C3 >= Cdata[2] then 1 else 0;
def CTRend4 = if C3 >= Cdata[3] then 1 else 0;
def CTRend5 = if C3 >= Cdata[4] then 1 else 0;
Def TotalT3 = (CTRend1 + CTRend2 + CTRend3 + CTRend4 + CTrend5);
plot TT3_Dot = if IsNaN(c3) then Double.NaN else 3;
TT3_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
TT3_Dot.SetLineWeight(DotSize);
TT3_Dot.AssignValueColor(if 2.5 > TotalT3 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(c3[n1]) and IsNaN(c3[n]), 3, (agg3/1000/60) + " min", Color.Yellow, yes);
#Aggregation 4
def O4 = Open(Period = AGG4);
def C4 = Close(Period =AGG4);
def H4 = High(Period = AGG4);
def L4= Low(Period = AGG4);
def Ddata = Sum((O4+H4+L4+C4)/4,6)/6;
def DTRend1 = if C4 >= Ddata then 1 else 0;
def DTRend2 = if C4 >= Ddata[1] then 1 else 0;
def DTRend3 = if C4 >= Ddata[2] then 1 else 0;
def DTRend4 = if C4 >= Ddata[3] then 1 else 0;
def DTRend5 = if C4 >= Ddata[4] then 1 else 0;
Def TotalT4 = (DTRend1 + DTRend2 + DTRend3 + DTRend4 + DTrend5);
plot TT4_Dot = if IsNaN(c4) then Double.NaN else 4;
TT4_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
TT4_Dot.SetLineWeight(DotSize);
TT4_Dot.AssignValueColor(if 2.5 > TotalT4 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(c4[n1]) and IsNaN(c4[n]), 4, (agg4/1000/60) + " min", Color.Yellow, yes);
#Aggregation 5
def O5 = Open(Period = AGG5);
def C5 = Close(Period =AGG5);
def H5 = High(Period = AGG5);
def L5 = Low(Period = AGG5);
def Edata = Sum((O5+H5+L5+C5)/4,6)/6;
def ETRend1 = if C5 >= Edata then 1 else 0;
def ETRend2 = if C5 >= Edata[1] then 1 else 0;
def ETRend3 = if C5 >= Edata[2] then 1 else 0;
def ETRend4 = if C5 >= Edata[3] then 1 else 0;
def ETRend5 = if C5 >= Edata[4] then 1 else 0;
Def TotalT5 = (ETRend1 + ETRend2 + ETRend3 + ETRend4 + ETrend5);
plot TT5_Dot = if IsNaN(c5) then Double.NaN else 5;
TT5_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
TT5_Dot.SetLineWeight(DotSize);
TT5_Dot.AssignValueColor(if 2.5 > TotalT5 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(c5[n1]) and IsNaN(c5[n]), 5, (agg5/1000/60) + " min", Color.Yellow, yes);
#Aggregation 6
def O6 = Open(Period = AGG6);
def C6 = Close(Period =AGG6);
def H6 = High(Period = AGG6);
def L6 = Low(Period = AGG6);
def Fdata = Sum((O6+H6+L6+C6)/4,6)/6;
def FTRend1 = if C6 >= Fdata then 1 else 0;
def FTRend2 = if C6 >= Fdata[1] then 1 else 0;
def FTRend3 = if C6 >= Fdata[2] then 1 else 0;
def FTRend4 = if C6 >= Fdata[3] then 1 else 0;
def FTRend5 = if C6 >= Fdata[4] then 1 else 0;
Def TotalT6 = (FTRend1 + FTRend2 + FTRend3 + FTRend4 + FTrend5);
plot TT6_Dot = if IsNaN(C6) then Double.NaN else 6;
TT6_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
TT6_Dot.SetLineWeight(DotSize);
TT6_Dot.AssignValueColor(if 2.5 > TotalT6 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(C6[n1]) and IsNaN(C6[n]), 6, (agg6/1000/60) + " min", Color.Yellow, yes);
Def Bull = ((TotalT6[1] > TotalT6) + (TotalT5[1] > TotalT5) + (TotalT4[1] > TotalT4) + (TotalT3[1] > TotalT3) + (TotalT2[1] > TotalT2) + (TotalT[1] > TotalT));
Def Bear = ((TotalT6[1] < TotalT6) + (TotalT5[1] < TotalT5) + (TotalT4[1] < TotalT4) + (TotalT3[1] < TotalT3) + (TotalT2[1] < TotalT2) + (TotalT[1] < TotalT));
Alert(Bull >3,"", Alert.BAR, Sound.Chimes);
Alert (Bear >3,"", Alert.BAR, Sound.Chimes);
Last edited: