#mtf_grn_red
#https://usethinkscript.com/threads/simple-tfc-time-frame-continuity-study.16420/
#Simple TFC (Time Frame Continuity) Study
#
#
# 2025-11-26 modified by vollermist for MTF and visual rework to dashboard format.
declare lower;
def na = double.nan;
#def bn = barnumber();
DefineGlobalColor("up", Color.GREEN);
DefineGlobalColor("down", Color.RED);
DefineGlobalColor("neutral", Color.YELLOW);
# chart-level aggregation
def o = open;
def c = close;
def red = o > c;
def green = o < c;
def dir = if o < c then 1 else if o > c then -1 else 0;
plot dots = if !isnan(close) then 1 else na;
dots.SetPaintingStrategy(PaintingStrategy.POINTS);
dots.AssignValueColor(if dir > 0 then GlobalColor("up") else if dir < 0 then GlobalColor("down") else GlobalColor("neutral"));
dots.setlineweight(2);
dots.hidebubble();
# htf1 aggregation
input tf1 = AggregationPeriod.HOUR;
def o1 = open(period = tf1);
def c1 = close(period = tf1);
def red1 = o1 > c1;
def green1 = o1 < c1;
def dir1 = if o1 < c1 then 1 else if o1 > c1 then -1 else 0;
plot dots1 = if !isnan(close) then 2 else na;
dots1.SetPaintingStrategy(PaintingStrategy.SQUARES);
dots1.AssignValueColor(if dir1 > 0 then GlobalColor("up") else if dir1 < 0 then GlobalColor("down") else GlobalColor("neutral"));
dots1.setlineweight(5);
dots1.hidebubble();
# htf2 aggregation
input tf2 = AggregationPeriod.DAY;
def o2 = open(period = tf2);
def c2 = close(period = tf2);
def red2 = o2 > c2;
def green2 = o2 < c2;
def dir2 = if o2 < c2 then 2 else if o2 > c2 then -2 else 0;
plot dots2 = if !isnan(close) then 3 else na;
dots2.SetPaintingStrategy(PaintingStrategy.SQUARES);
dots2.AssignValueColor(if dir2 > 0 then GlobalColor("up") else if dir2 < 0 then GlobalColor("down") else GlobalColor("neutral"));
dots2.setlineweight(5);
dots2.hidebubble();
# htf3 aggregation
input tf3 = AggregationPeriod.WEEK;
def o3 = open(period = tf3);
def c3 = close(period = tf3);
def red3 = o3 > c3;
def green3 = o3 < c3;
def dir3 = if o3 < c3 then 3 else if o3 > c3 then -3 else 0;
plot dots3 = if !isnan(close) then 4 else na;
dots3.SetPaintingStrategy(PaintingStrategy.SQUARES);
dots3.AssignValueColor(if dir3 > 0 then GlobalColor("up") else if dir3 < 0 then GlobalColor("down") else GlobalColor("neutral"));
dots3.setlineweight(5);
dots3.hidebubble();
# htf4 aggregation
input tf4 = AggregationPeriod.MONTH;
def o4 = open(period = tf4);
def c4 = close(period = tf4);
def red4 = o4 > c4;
def green4 = o4 < c4;
def dir4 = if o4 < c4 then 4 else if o4 > c4 then -4 else 0;
plot dots4 = if !isnan(close) then 5 else na;
dots4.SetPaintingStrategy(PaintingStrategy.SQUARES);
dots4.AssignValueColor(if dir4 > 0 then GlobalColor("up") else if dir4 < 0 then GlobalColor("down") else GlobalColor("neutral"));
dots4.setlineweight(5);
dots4.hidebubble();
#