tickets2themoon
New member
Modified the approach here to use charts to draw the side of candle bodies. Also accounted for days where upper aggregation did not start on 1st bar (i.e. barCount = 0) in series. As long as higher time frame is even divisible by lower (i.e. 5min Overlay on 1min chart) overlay seem to work fine. You get odd higher TF candles when this is not the case (i.e. 10m Overlay on 3m chart).
http://tos.mx/MMKvsUQ
http://tos.mx/MMKvsUQ
Ruby:
#-----------------------------------------------------
#
# 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( if (addcloud and sider == 2 and !doji) then O else Double.NaN, if (addcloud and sider == 2 and !doji) then C else Double.NaN, Color.LIGHT_RED, Color.LIGHT_GREEN, yes);
AddCloud( if (addcloud and sider == 1 and !doji) then O else Double.NaN, if (addcloud and sider == 1 and !doji) then C else Double.NaN, Color.LIGHT_RED, Color.LIGHT_GREEN, yes);
AddCloud( if (addcloud and sider == 1 and doji) then O else Double.NaN, if (addcloud and sider == 1 and doji) then C else Double.NaN, Color.WHITE, Color.WHITE, yes);
AddCloud( if (addcloud and sider == 2 and doji) then O else Double.NaN, if (addcloud and sider == 2 and doji) then C else Double.NaN, Color.WHITE, Color.WHITE, 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;
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
Last edited: