#-----------------------------------------------------
#
# S I M P L E
# C A N D L E O V E R L A Y
#
# Open line red/green for visualizing FTC
#
# updated by tickets2themoon
# based on STRAT study by Ramon DV. aka Pelonsax
# based on Rob Smith's The STRAT
# Original Candle Overlay concept by Paul Townsend
#
#-----------------------------------------------------
declare upper;
#------------------------------------
# MTF SECTION
#------------------------------------
input Time_Frame = AggregationPeriod.FIFTEEN_MIN;
def H = high(period = Time_Frame);
def L = low(period = Time_Frame);
def O = open(period = Time_Frame);
def C = close(period = Time_Frame);
def NA = Double.NaN;
def modTime = GetTime() % Time_Frame;
def aggPeriod = GetAggregationPeriod();
# Number of bars within the lower timeframe
def lowerTimeFrameBarCount = Time_Frame / aggPeriod;
# Calculate ms of Middle bar from open on higher timeframe
def halfAgg;
if lowerTimeFrameBarCount % 2 == 0
then {
halfAgg = (lowerTimeFrameBarCount / 2) * GetAggregationPeriod();
}
else {
halfAgg = RoundDown(lowerTimeFrameBarCount / 2, 0) * GetAggregationPeriod();
}
# Determine the position of each bar in respect to Higher Time Frame
def barStart = if modTime == 0 then 1 else 0;
def barEnd = if modTime >= (Time_Frame - aggPeriod) then 1 else 0;
#Find the middle bar in the lower timeframe
def midBar = if modTime == halfAgg then 1 else 0;
#If start or end of bar - used to draw side border of candle body
def openbar = if barStart or barEnd then 1 else 0;
#------------------------------------
# ADD CLOUDS
#------------------------------------
input addcloud = yes;
def side;
if modTime < modTime[1]
then {
if side[1] == 1
then {
side = 2;
}
else {
side = 1;
}
} else {
side = side[1];
}
def sider = side;
def doji = C == O;
AddCloud(data1 = if (addcloud and sider == 2 and !doji) then O else Double.NaN, data2 = if (addcloud and sider == 2 and !doji) then C else Double.NaN, color1 = Color.LIGHT_RED, color2 = Color.LIGHT_GREEN, showBorder = yes);
AddCloud(data1 = if (addcloud and sider == 1 and !doji) then O else Double.NaN, data2 = if (addcloud and sider == 1 and !doji) then C else Double.NaN, color1 = Color.LIGHT_RED, color2 = Color.LIGHT_GREEN, showBorder = yes);
AddCloud(data1 = if (addcloud and sider == 1 and doji) then O else Double.NaN, data2 = if (addcloud and sider == 1 and doji) then C else Double.NaN, color1 = Color.WHITE, color2 = Color.WHITE, showBorder = yes);
AddCloud(data1 = if (addcloud and sider == 2 and doji) then O else Double.NaN, data2 = if (addcloud and sider == 2 and doji) then C else Double.NaN, color1 = Color.WHITE, color2 = Color.WHITE, showBorder = yes);
#plot barType = midBar;
#plot barType = Sync;
#barType.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
#barType.AssignValueColor(color.WHITE);
### making stuff up here drawing the wick through the middle candle.
def nan = Double.NaN;
def up = C > O;
def ubh = if up and midBar then H else nan;
def ubc = if up and midBar then C else nan;
def ubo = if up and midBar then O else nan;
def ubl = if up and midBar then L else nan;
def dbh = if !up and !doji and midBar then H else nan;
def dbc = if !up and !doji and midBar then C else nan;
def dbo = if !up and !doji and midBar then O else nan;
def dbl = if !up and !doji and midBar then L else nan;
def djbh = if doji and midBar then H else nan;
def djbc = if doji and midBar then C else nan;
def djbo = if doji and midBar then O else nan;
def djbl = if doji and midBar then L else nan;
#Capture Highs/Lows of Each Overlay Bar---------------------------------------------
def hh = if (up and midBar) or (!up and !doji and midBar) or (doji and midBar) then H else hh[1];
def ll = if (up and midBar) or (!up and !doji and midBar) or (doji and midBar) then L else ll[1];
#-----------------------------------------------------------------------------------
def sideuh = if up and openbar then C else nan;
def sideul = if up and openbar then O else nan;
def sidedh = if !up and !doji and openbar then O else nan;
def sidedl = if !up and !doji and openbar then C else nan;
def sidedjh = if doji and openbar then O else nan;
def sidedjl = if doji and openbar then C else nan;
#Draw Upper Wick Green
AddChart(high = ubh, low = ubc, open = NA, close = NA, type = ChartType.BAR , growcolor = if 1 then Color.LIGHT_GREEN else Color.LIGHT_GREEN);
#Draw Upper Wick Red
AddChart(high = dbh, low = dbo, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_RED);
#Draw Upper Wick White - Doji
AddChart(high = djbh, low = djbo, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.WHITE);
#Draw Lower Wick Green
AddChart(high = ubo, low = ubl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_GREEN);
#Draw Lower Wick Red
AddChart(high = dbc, low = dbl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_RED);
#Draw Lower Wick White - Doji
AddChart(high = djbc, low = djbl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.WHITE);
#Draw Side of Body Green
AddChart(high = sideuh, low = sideul, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_GREEN);
#Draw Side of Body Red
AddChart(high = sidedh, low = sidedl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_RED);
#Draw Side of Body White
AddChart(high = sidedjh, low = sidedjl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.WHITE);
plot highs = ubh;
highs.SetPaintingStrategy(PaintingStrategy.POINTS);
highs.SetDefaultColor(Color.GREEN);
plot lhighs = dbh;
lhighs.SetPaintingStrategy(PaintingStrategy.POINTS);
lhighs.SetDefaultColor(Color.RED);
plot lows = ubl;
lows.SetPaintingStrategy(PaintingStrategy.POINTS);
lows.SetDefaultColor(Color.GREEN);
plot llows = dbl;
llows.SetPaintingStrategy(PaintingStrategy.POINTS);
llows.SetDefaultColor(Color.RED);
#------------------------------------
# ADD LABEL
#------------------------------------
input Show_Label = yes;
AddLabel(Show_Label, Concat(if Time_Frame < 3600000 then Time_Frame / 60000 + "m" else if Time_Frame < 86400000 then Time_Frame / 3600000 + "h" else if Time_Frame < 604800000 then Time_Frame / 86400000 + "D" else if Time_Frame < 2592000000 then Time_Frame / 604800000 + "Wk" else if Time_Frame < 31536000000 then Time_Frame / 2592000000 + "Mo" else Time_Frame / 31536000000 + "Yr", if Time_Frame then " CANDLES" else ""), Color.LIGHT_GRAY);
# end
#High/low bubbles for the overlay candles
def bn = BarNumber();
def lastubh = HighestAll(if IsNaN(ubh[-1]) and !IsNaN(ubh) then bn else Double.NaN);
def lastdbh = HighestAll(if IsNaN(dbh[-1]) and !IsNaN(dbh) then bn else Double.NaN);
def lastdjbh = HighestAll(if IsNaN(djbh[-1]) and !IsNaN(djbh) then bn else Double.NaN);
def lasthigh = Max(lastubh, Max(lastdbh, lastdjbh));
input show_bubbles = yes;
input show_CURRENT_highs_lows = yes;
input show_PRIOR_highs_lows = yes;
input show_LAST_Bubble_only = yes;
#Current Highs/Lows
AddChartBubble(if !show_bubbles or !show_CURRENT_highs_lows then NA
else if show_LAST_Bubble_only then bn == lastubh and bn == lasthigh
else ubh, ubh, "CH " + AsText(ubh), Color.GREEN);
AddChartBubble(if !show_bubbles or !show_CURRENT_highs_lows then NA
else if show_LAST_Bubble_only then bn == lastdjbh and bn == lasthigh
else djbh, djbh, "CH " + AsText(djbh), Color.WHITE);
AddChartBubble(if !show_bubbles or !show_CURRENT_highs_lows then NA
else if show_LAST_Bubble_only then bn == lastdbh and bn == lasthigh
else dbh, dbh, "CH " + AsText(dbh));
AddChartBubble(if !show_bubbles or !show_CURRENT_highs_lows then NA
else if show_LAST_Bubble_only then bn == lastubh and bn == lasthigh
else ubl, ubl, "CL " + AsText(ubl), Color.GREEN, up = no);
AddChartBubble(if !show_bubbles or !show_CURRENT_highs_lows then NA
else if show_LAST_Bubble_only then bn == lastdjbh and bn == lasthigh
else djbl, djbl, "CL " + AsText(djbl), Color.WHITE, up = no);
AddChartBubble(if !show_bubbles or !show_CURRENT_highs_lows then NA
else if show_LAST_Bubble_only then bn == lastdbh and bn == lasthigh
else dbl, dbl, "CL " + AsText(dbl), up = no);
#Previous High/Low
AddChartBubble(if !show_bubbles or !show_PRIOR_highs_lows then NA
else if show_LAST_Bubble_only then lasthigh == lastdbh and bn == lasthigh
else dbh, dbh, "PH " + AsText(hh[1]), Color.RED);
AddChartBubble(if !show_bubbles or !show_PRIOR_highs_lows then NA
else if show_LAST_Bubble_only then lasthigh == lastubh and bn == lasthigh
else ubh, ubh, "PH " + AsText(hh[1]), Color.GREEN);
AddChartBubble(if !show_bubbles or !show_PRIOR_highs_lows then NA
else if show_LAST_Bubble_only then lasthigh == lastdjbh and bn == lasthigh
else djbh, djbh, "PH " + AsText(hh[1]), Color.WHITE);
AddChartBubble(if !show_bubbles or !show_PRIOR_highs_lows then NA
else if show_LAST_Bubble_only then lasthigh == lastdbh and bn == lasthigh
else dbl, dbl, "PL " + AsText(ll[1]), Color.RED, no);
AddChartBubble(if !show_bubbles or !show_PRIOR_highs_lows then NA
else if show_LAST_Bubble_only then lasthigh == lastubh and bn == lasthigh
else ubl, ubl, "PL " + AsText(ll[1]), Color.GREEN, no);
AddChartBubble(if !show_bubbles or !show_PRIOR_highs_lows then NA
else if show_LAST_Bubble_only then lasthigh == lastdjbh and bn == lasthigh
else djbl, djbl, "PL " + AsText(ll[1]), Color.WHITE, no);