#----------------------------------------------------- # # 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 and Wiinii (added Global candle color/transpoarency option) # based on STRAT study by Ramon DV. aka Pelonsax # based on Rob Smith's The STRAT # Original Candle Overlay concept by Paul Townsend # Added HeikinAshi Candels by Sam4COK @ Samer800 - 08/2022 #----------------------------------------------------- DECLARE UPPER; #------------------------------------ # MTF SECTION #------------------------------------ input candleType = { Default "CandleStick", "HeikinAshi"}; input Time_Frame = AggregationPeriod.FIFTEEN_MIN; input addcloud = yes; 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 #------------------------------------ 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 (candleType == candleType.Candlestick and addcloud and sider == 2 and !doji) then O else na, if (addcloud and sider == 2 and !doji) then C else na, CreateColor(236,64,122), CreateColor(2,160,174), yes); AddCloud( if (candleType == candleType.Candlestick and addcloud and sider == 1 and !doji) then O else na, if (addcloud and sider == 1 and !doji) then C else na, CreateColor(236,64,122), CreateColor(2,160,174), yes); AddCloud( if (candleType == candleType.Candlestick and addcloud and sider == 1 and doji) then O else na, if (addcloud and sider == 1 and doji) then C else na, Color.WHITE, Color.WHITE, yes); AddCloud( if (candleType == candleType.Candlestick and addcloud and sider == 2 and doji) then O else na, if (addcloud and sider == 2 and doji) then C else na, Color.WHITE, Color.WHITE, yes); ### making stuff up here drawing the wick through the middle candle. def up = c > o; def ubh; def ubc; def ubo; def ubl; if candleType == candleType.Candlestick and up and midBar then { ubh = h; ubc = c; ubo = o; ubl = l;} else { ubh = na; ubc = na; ubo = na; ubl = na;} def dbh; def dbc; def dbo; def dbl; if candleType == candleType.Candlestick and !up and !doji and midBar then { dbh = h; dbc = c; dbo = o; dbl = l;} else { dbh = na; dbc = na; dbo = na; dbl = na;} def djbh; def djbc; def djbo; def djbl; if candleType == candleType.Candlestick and doji and midBar then { djbh = h; djbc = c; djbo = o; djbl = l;} else { djbh = na; djbc = na; djbo = na; djbl = na;} def sideuh = if candleType == candleType.Candlestick and up and openbar then C else na; def sideul = if candleType == candleType.Candlestick and up and openbar then O else na; def sidedh = if candleType == candleType.Candlestick and !up and !doji and openbar then O else na; def sidedl = if candleType == candleType.Candlestick and !up and !doji and openbar then C else na; def sidedjh = if candleType == candleType.Candlestick and doji and openbar then O else na; def sidedjl = if candleType == candleType.Candlestick and doji and openbar then C else na; #Draw Upper Wick Green AddChart(high = ubh, low = ubc, open = na, close = na, type = ChartType.BAR , growcolor = CreateColor(2,160,174)); #Draw Upper Wick Red AddChart(high = dbh, low = dbo, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(236,64,122)); #Draw Lower Wick Green AddChart(high = ubo, low = ubl, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(2,160,174)); #Draw Lower Wick Red AddChart(high = dbc, low = dbl, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(236,64,122)); #Draw Side of Body Green AddChart(high = sideuh, low = sideul, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(2,160,174)); #Draw Side of Body Red AddChart(high = sidedh, low = sidedl, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(236,64,122)); #Draw Upper Wick White - Doji AddChart(high = djbh, low = djbo, open = na, close = na, type = ChartType.BAR, growcolor = color.WHITE); #Draw Lower Wick White - Doji AddChart(high = djbc, low = djbl, open = na, close = na, type = ChartType.BAR, growcolor = color.WHITE); #Draw Side of Body White AddChart(high = sidedjh, low = sidedjl, open = na, close = na, type = ChartType.BAR, growcolor = color.WHITE); #plot highs = if o==l then na else ubh; #highs.setpaintingStrategy(PaintingStrategy.POINTS); #highs.setDefaultColor(CreateColor(2,160,174)); #plot lhighs = if o==h then na else dbh; #lhighs.setpaintingStrategy(paintingstrategy.points); #lhighs.setdefaultColor(Color.DARK_RED); #plot lows = if o==l then na else ubl; #lows.setpaintingStrategy(PaintingStrategy.Points); #lows.setdefaultColor(CreateColor(236,64,122)); #plot llows = if o==h then na else dbl; #llows.setpaintingStrategy(PaintingStrategy.POINTS); #llows.SetDefaultColor(Color.DARK_RED); ######## def haOpen; def haHigh; def haLow; def haClose; haClose = (o + h + l + c) / 4; haOpen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose); haHigh = Max(Max(h, haOpen), haClose); haLow = Min(Min(l, haOpen), haClose); def hh1r = if haClose > haOpen then 1 else if haClose < haOpen then -1 else 0; def HUp = hh1r > 0; def Hdoji = haClose==haOpen; def haO = haOpen; def haC = haClose; # Plot UP candle def UpO; def UpH; def UpL; def UpC; if HUp and midbar and candleType == candleType.HeikinAshi then { UpO = haOpen ; UpH = haHigh ; UpL = haLow ; UpC = haClose; } else { UpO = na; UpH = na; UpL = na; UpC = na; } # Plot DOWN candle def DnO; def DnH; def DnL; def DnC; if !HUp and !Hdoji and midBar and candleType == candleType.HeikinAshi then { DnO = haOpen ; DnH = haHigh ; DnL = haLow ; DnC = haClose; } else { DnO = na; DnH = na; DnL = na; DnC = na; } def Hdjbh; def Hdjbc; def Hdjbo; def Hdjbl; if candleType == candleType."HeikinAshi" and Hdoji and midBar then { Hdjbh = haHigh; Hdjbc = haClose; Hdjbo = haOpen; Hdjbl = haLow;} else { Hdjbh = na; Hdjbc = na; Hdjbo = na; Hdjbl = na;} def Hsideuh = if candleType == candleType.HeikinAshi and HUp and openbar then haClose else na; def Hsideul = if candleType == candleType.HeikinAshi and HUp and openbar then haOpen else na; def Hsidedh = if candleType == candleType.HeikinAshi and !HUp and !Hdoji and openbar then haOpen else na; def Hsidedl = if candleType == candleType.HeikinAshi and !HUp and !Hdoji and openbar then haClose else na; def Hsidedjh = if candleType == candleType.HeikinAshi and Hdoji and openbar then haOpen else na; def Hsidedjl = if candleType == candleType.HeikinAshi and Hdoji and openbar then haClose else na; # Plot the new Chart #Draw Upper Wick Green AddChart(high = UpH, low = UpC, open = na, close = na, type = ChartType.BAR , growcolor = CreateColor(2,160,174)); #Draw Upper Wick Red AddChart(high = DnH, low = DnO, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(192,0,192)); #Draw Lower Wick Green AddChart(high = Upo, low = Upl, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(2,160,174)); #Draw Lower Wick Red AddChart(high = Dnc, low = Dnl, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(192,0,192)); #Draw Side of Body Green AddChart(high = hsideuh, low = hsideul, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(2,160,174)); #Draw Side of Body Red AddChart(high = hsidedh, low = hsidedl, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(192,0,192)); #Draw Upper Wick White - Doji AddChart(high = Hdjbh, low = Hdjbo, open = na, close = na, type = ChartType.BAR, growcolor = color.WHITE); #Draw Lower Wick White - Doji AddChart(high = hdjbc, low = hdjbl, open = na, close = na, type = ChartType.BAR, growcolor = color.WHITE); #Draw Side of Body White AddChart(high = hsidedjh, low = hsidedjl, open = na, close = na, type = ChartType.BAR, growcolor = color.WHITE); AddCloud(if (candleType == candleType.HeikinAshi and addcloud and sider == 2 and !hdoji) then haO else na, if (addcloud and sider == 2 and !hdoji) then haC else na, CreateColor(192,0,192), CreateColor(2,160,174), yes); AddCloud( if (candleType == candleType.HeikinAshi and addcloud and sider == 1 and !hdoji) then haO else na, if (addcloud and sider == 1 and !hdoji) then haC else na, CreateColor(192,0,192), CreateColor(2,160,174), yes); AddCloud( if (candleType == candleType.HeikinAshi and addcloud and sider == 1 and hdoji) then haO else na, if (addcloud and sider == 1 and hdoji) then haC else na, Color.WHITE, Color.WHITE, yes); AddCloud( if (candleType == candleType.HeikinAshi and addcloud and sider == 2 and hdoji) then haO else na, if (addcloud and sider == 2 and hdoji) then haC else na, Color.WHITE, Color.WHITE, yes); #plot Hahighs = if haOpen==haHigh then na else uph; #hahighs.setpaintingStrategy(PaintingStrategy.POINTS); #hahighs.setDefaultColor(Color.Green); #plot halhighs = if haOpen==haHigh then na else dnh; #halhighs.setpaintingStrategy(paintingstrategy.points); #halhighs.setdefaultColor(Color.Red); #plot halows = if haOpen==haLow then na else upl; #halows.setpaintingStrategy(PaintingStrategy.Points); #halows.setdefaultColor(Color.Green); #plot hallows = if haOpen==haLow then na else dnl; #hallows.setpaintingStrategy(PaintingStrategy.POINTS); #hallows.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 candleType else ""), Color.light_Gray); # end