Multi-TimeFrame Candles Overlay for ThinkOrSwim

Can I have this same setup but painting Heikin Ashi Candles Colors, The other Heikin Ashi Scripts I found have wicks and I only want the box of high and bottom like this one but showing the color of the heikin ashi candle on that time frame.

Added Cloud Coloring Choice at the Input Screen with this snippet basis:
Code:
#### Cloud Coloring
def cloud_o;
def cloud_c;
def Heiken_close = (o + h + l + c) / 4;
def Heiken_open  = CompoundValue(1, (Heiken_open[1] + Heiken_close[1]) / 2, (o[1] + c[1]) / 2);

input cloud_color = {default candle, heiken_ashi};
switch (cloud_color) {
case candle:
    cloud_o = o;
    cloud_c = c;
case heiken_ashi:
    cloud_o = Heiken_open;
    cloud_c = Heiken_close;
}

Here is the full revised code with the snippet and other necessary changes referencing the choice made.
The image shows a 1d1m chart with a 15m chart overlay with Heiken Ashi coloring.
Screenshot 2024-01-23 055542.png
Code:
#CandleOverlay_MTF_Using_VolumeProfile
#Added Cloud Coloring Choice between Candle/Heiken_Ashi

input ShowTodayOnly = { default "No", "Yes"};
input showbubbles   = yes;
input aggperiod     = {"1 MIN", "2 MIN", "3 MIN", "5 MIN", "10 MIN", "15 MIN", "30 MIN", "1 HOUR", default "DAY", "WEEK", "MONTH", "QUARTER", "YEAR"};
input displace      = 0;

def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(0);
def month = GetYear() * 12 + GetMonth();
def qtr = (GetMonth() - 1 ) % 3;
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def dom = GetDayOfMonth(yyyymmdd);
def dow = GetDayOfWeek(yyyymmdd - dom + 1);

switch (aggperiod) {
case "1 MIN":
    period = Floor(seconds / 60 + day_number * 24 * 60);
case "2 MIN":
    period = Floor(seconds / 120 + day_number * 24);
case "3 MIN":
    period = Floor(seconds / 180 + day_number * 24);
case "5 MIN":
    period = Floor(seconds / 300 + day_number * 24);
case "10 MIN":
    period = Floor(seconds / 600 + day_number * 24);
case "15 MIN":
    period = Floor(seconds / 900 + day_number * 24);
case "30 MIN":
    period = Floor(seconds / 1800 + day_number * 24);
case "1 HOUR":
    period = Floor(seconds / 3600 + day_number * 24);
case "DAY":
    period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case "WEEK":
    period = Floor(day_number / 7);
case "MONTH":
    period = Floor(month - First(month));
case QUARTER:
    period = qtr == 0 and qtr[1] != 0;
case "YEAR":
    period = GetYear();
}
def bn = BarNumber();
def na = Double.NaN;
def o  = open(period = aggperiod)[displace];
def c  = close(period = aggperiod)[displace];
def h  = high(period = aggperiod)[displace];
def l  = low(period = aggperiod)[displace];
def r  = if period != period[1] then 0 else 1;
def b  = if period != period[1] then bn else b[1];
def xb = b;

#### Cloud Coloring
def cloud_o;
def cloud_c;
def Heiken_close = (o + h + l + c) / 4;
def Heiken_open  = CompoundValue(1, (Heiken_open[1] + Heiken_close[1]) / 2, (o[1] + c[1]) / 2);

input cloud_color = {default candle, heiken_ashi};
switch (cloud_color) {
case candle:
    cloud_o = o;
    cloud_c = c;
case heiken_ashi:
    cloud_o = Heiken_open;
    cloud_c = Heiken_close;
}

plot ORH = if ShowTodayOnly and !IsNaN(close(period = aggperiod)[-1]) then Double.NaN else high(period = aggperiod)[displace];
plot ORL = if ShowTodayOnly and !IsNaN(close(period = aggperiod)[-1]) then Double.NaN else  low(period = aggperiod)[displace];

ORH.AssignValueColor(if cloud_c > cloud_o then Color.GREEN else if cloud_c < cloud_o then Color.RED else Color.WHITE);
ORH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORH.SetLineWeight(2);

ORL.AssignValueColor(if cloud_c > cloud_o then Color.GREEN else if cloud_c < cloud_o then Color.RED else Color.WHITE);
ORL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORL.SetLineWeight(2);


input showcloud = yes;
AddCloud( if showcloud and r and cloud_c > cloud_o then ORH else Double.NaN, if r then ORL else Double.NaN,  Color.GREEN, Color.GREEN);
AddCloud( if showcloud and r and cloud_c < cloud_o then ORH else Double.NaN, if r then ORL else Double.NaN,  Color.RED, Color.RED);
AddCloud( if showcloud and r and cloud_c == cloud_o then ORH else Double.NaN, if r then ORL else Double.NaN,  Color.WHITE, Color.WHITE);

AddCloud( if showcloud and Between(bn, xb - 1, xb + 1) and cloud_c > cloud_o then ORH else Double.NaN, if Between(bn, xb - 1, xb + 1) then ORL else Double.NaN,  Color.GREEN, Color.GREEN);
AddCloud( if showcloud and Between(bn, xb - 1, xb + 1) and cloud_c < cloud_o then ORH else Double.NaN, if Between(bn, xb - 1, xb + 1) then ORL else Double.NaN,  Color.RED, Color.RED);
AddCloud( if showcloud and Between(bn, xb - 1, xb + 1) and cloud_c == cloud_o then ORH else Double.NaN, if Between(bn, xb - 1, xb + 1) then ORL else Double.NaN,  Color.WHITE, Color.WHITE);

#
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

How can we make it so we can change the opacity on this script?

Use Defineglobalcolor to change opacity of clouds.

defineglobalColor ("Up", color.lime);
defineglobalColor ("Dn", color.red);
defineglobalColor ("Flat", color.white);

input showcloud = yes;

AddCloud( if showcloud and r and c > o then ORH else Double.NaN, if r then ORL else Double.NaN, globalColor ("Up"), globalColor ("Up"));
AddCloud( if showcloud and r and c < o then ORH else Double.NaN, if r then ORL else Double.NaN, globalColor ("Dn"), globalColor ("Dn"));
AddCloud( if showcloud and r and c == o then ORH else Double.NaN, if r then ORL else Double.NaN, globalColor ("Flat"), globalColor ("Flat"));
 

Attachments

  • Candles Overlay4.jpg
    Candles Overlay4.jpg
    95.7 KB · Views: 197
  • Candles Overlay3.jpg
    Candles Overlay3.jpg
    240.5 KB · Views: 193
  • Candles Overlay2.jpg
    Candles Overlay2.jpg
    278.5 KB · Views: 192
This colors the MTF Candle Overlay from High to Low
I couldn’t get this to work. Could you help me in identifying what I am doing wrong as this is the 4-5th created study I’ve had something like this show up .
 

Attachments

  • IMG_2731.jpeg
    IMG_2731.jpeg
    357.1 KB · Views: 152
I couldn’t get this to work. Could you help me in identifying what I am doing wrong as this is the 4-5th created study I’ve had something like this show up .

No, there is nothing wrong with the script.
Perhaps you are having cutting and pasting difficulties?
Be sure to copy ONLY the code and ALL the code.

Here is a chart with the indicator already plotted on it.
By loading this shared chart link, the script will show up at the bottom of your study tab with a 'shared' prefix.
shared chart link: http://tos.mx/rVP3Tgw Click here for --> Easiest way to load shared links
FYI: Schwab will not make shared links fully-functional for everyone until after May 13
F12eslF.png
 
No, there is nothing wrong with the script.
Perhaps you are having cutting and pasting difficulties?
Be sure to copy ONLY the code and ALL the code.

Here is a chart with the indicator already plotted on it.
By loading this shared chart link, the script will show up at the bottom of your study tab with a 'shared' prefix.
shared chart link: http://tos.mx/rVP3Tgw Click here for --> Easiest way to load shared links
FYI: Schwab will not make shared links fully-functional for everyone until after May 13
F12eslF.png

Very kind of you. Thank you.
 
I dont know why this MTF candle overlay
https://usethinkscript.com/threads/...verlay-for-thinkorswim.1425/page-5#post-76970
only paints half a candle when its set to 2min
Can someone fix it???
mtf-candle-overlay-is-displaying-half-candles-for-2min-v0-7h98xf06qjid1.png

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.FIVE_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, createColor(168, 165, 165 ), createColor(93, 162, 253 ), 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, createColor(168, 165, 165 ), createColor(93, 162, 253 ), 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.GRAY, Color.WHITE, yes);# Color.WHITE
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.GRAY, Color.WHITE, yes);;# Color.WHITE
#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 createColor(93, 162, 253 ) else createColor(93, 162, 253 ));#grn 15, 131, 0

#Draw Upper Wick Red
AddChart(high = dbh, low = dbo, open = na, close = na, type = ChartType.bar, growcolor = createColor(168, 165, 165 ));#red 172, 46, 46

#Draw Upper Wick White - Doji
AddChart(high = djbh, low = djbo, open = na, close = na, type = ChartType.bar, growcolor = color.GRAY);#color.WHITE

#Draw Lower Wick Green
AddChart(high = ubo, low = ubl, open = na, close = na, type = ChartType.bar, growcolor = createColor(93, 162, 253 ));#color.GREEN

#Draw Lower Wick Red
AddChart(high = dbc, low = dbl, open = na, close = na, type = ChartType.bar, growcolor = createColor(168, 165, 165 ));

#Draw Lower Wick White - Doji
AddChart(high = djbc, low = djbl, open = na, close = na, type = ChartType.bar, growcolor = color.GRAY);#color.WHITE

#Draw Side of Body Green
AddChart(high = sideuh, low = sideul, open = na, close = na, type = ChartType.bar, growcolor = createColor(93, 162, 253 ));#grn(15, 131, 0 )

#Draw Side of Body Red
AddChart(high = sidedh, low = sidedl, open = na, close = na, type = ChartType.bar, growcolor = createColor(168, 165, 165 ));

#Draw Side of Body White
AddChart(high = sidedjh, low = sidedjl, open = na, close = na, type = ChartType.bar, growcolor = color.GRAY);#color.WHITE


#plot highs = ubh;
#highs.setpaintingStrategy(PaintingStrategy.POINTS);
#highs.setDefaultColor(createColor(0,0,0));
#plot lhighs = dbh;
#lhighs.setpaintingStrategy(paintingstrategy.points);
#lhighs.setdefaultColor(createColor(0,0,0));
#plot lows = ubl;
#lows.setpaintingStrategy(PaintingStrategy.Points);
#lows.setdefaultColor(createColor(0,0,0));
#plot llows = dbl;
#llows.setpaintingStrategy(PaintingStrategy.POINTS);
#llows.SetDefaultColor(createColor(0,0,0));


#------------------------------------
# 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 by a moderator:
I dont know why this MTF candle overlay only paints half a candle when its set to 2min
Can someone fix it???
mtf-candle-overlay-is-displaying-half-candles-for-2min-v0-7h98xf06qjid1.png

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.FIVE_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, createColor(168, 165, 165 ), createColor(93, 162, 253 ), 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, createColor(168, 165, 165 ), createColor(93, 162, 253 ), 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.GRAY, Color.WHITE, yes);# Color.WHITE
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.GRAY, Color.WHITE, yes);;# Color.WHITE
#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 createColor(93, 162, 253 ) else createColor(93, 162, 253 ));#grn 15, 131, 0

#Draw Upper Wick Red
AddChart(high = dbh, low = dbo, open = na, close = na, type = ChartType.bar, growcolor = createColor(168, 165, 165 ));#red 172, 46, 46

#Draw Upper Wick White - Doji
AddChart(high = djbh, low = djbo, open = na, close = na, type = ChartType.bar, growcolor = color.GRAY);#color.WHITE

#Draw Lower Wick Green
AddChart(high = ubo, low = ubl, open = na, close = na, type = ChartType.bar, growcolor = createColor(93, 162, 253 ));#color.GREEN

#Draw Lower Wick Red
AddChart(high = dbc, low = dbl, open = na, close = na, type = ChartType.bar, growcolor = createColor(168, 165, 165 ));

#Draw Lower Wick White - Doji
AddChart(high = djbc, low = djbl, open = na, close = na, type = ChartType.bar, growcolor = color.GRAY);#color.WHITE

#Draw Side of Body Green
AddChart(high = sideuh, low = sideul, open = na, close = na, type = ChartType.bar, growcolor = createColor(93, 162, 253 ));#grn(15, 131, 0 )

#Draw Side of Body Red
AddChart(high = sidedh, low = sidedl, open = na, close = na, type = ChartType.bar, growcolor = createColor(168, 165, 165 ));

#Draw Side of Body White
AddChart(high = sidedjh, low = sidedjl, open = na, close = na, type = ChartType.bar, growcolor = color.GRAY);#color.WHITE


#plot highs = ubh;
#highs.setpaintingStrategy(PaintingStrategy.POINTS);
#highs.setDefaultColor(createColor(0,0,0));
#plot lhighs = dbh;
#lhighs.setpaintingStrategy(paintingstrategy.points);
#lhighs.setdefaultColor(createColor(0,0,0));
#plot lows = ubl;
#lows.setpaintingStrategy(PaintingStrategy.Points);
#lows.setdefaultColor(createColor(0,0,0));
#plot llows = dbl;
#llows.setpaintingStrategy(PaintingStrategy.POINTS);
#llows.SetDefaultColor(createColor(0,0,0));


#------------------------------------
# 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

how many times does 2 go into 5?

the default study time is 5 min
if you pick 2 min for chart time, 2 doesn't go into 5 , so it could have strange results.
i see candles of alternating widths , 2 minute candle ,then a 3 min candles, then a 2 min,....
 
Last edited by a moderator:
I dont know why this MTF candle overlay
https://usethinkscript.com/threads/...verlay-for-thinkorswim.1425/page-5#post-76970
only paints half a candle when its set to 2min
Can someone fix it???
mtf-candle-overlay-is-displaying-half-candles-for-2min-v0-7h98xf06qjid1.png

Perhaps you might find this useful

As @halcyonguy indicated, that code does not work well for a 2m chart and a 5m MTF Candle Overlay.
The following is a modification to a MTF Candle Overlay that plots the Overlay Candle from the High to the Low. The close and open are also plotted.
The candles will start at a chart 2m agg candle time for a 5m overlay, resulting in sometimes a 2 candle formation and other times a 3 candle formation.
The addcloud function is limited and will not plot a cloud on the 2 candle formation
The image shows the 5m Candle Overlay on a 2m chart in the upper panel and the actual corresponding 5m Candles in the lower panel for comparison to the overlay

Screenshot 2024-08-30 090916.jpg
Code:
#-----------------------------------------------------
#
#       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
#
#-----------------------------------------------------
# Modified by sleepyz to put a box around time_frame high/low

declare upper;
#------------------------------------
# MTF SECTION
#------------------------------------
input Time_Frame = AggregationPeriod.FIVE_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
#------------------------------------

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;

### 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 H else nan;
def ubo = if up and midBar then L 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 H else nan;
def dbo = if !up and !doji and midBar then L 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 H else nan;
def djbo = if doji and midBar then L else nan;
def djbl = if doji and midBar then L else nan;

def sideuh = if up and openbar then H else nan;
def sideul = if up and openbar then L else nan;
def sidedh = if !up and !doji and openbar then H else nan;
def sidedl = if !up and !doji and openbar then L else nan;
def sidedjh = if doji and openbar then H else nan;
def sidedjl = if doji and openbar then L else nan;



#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);

#-------------------------
#Plots of High/Low/Close/Open
plot highs = H;
highs.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
highs.AssignValueColor(if O > C then Color.RED else if C == O then Color.WHITE else Color.GREEN);

plot lows = L;
lows.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lows.AssignValueColor(if O > C then Color.RED else if C == O then Color.WHITE else Color.GREEN);

plot closeagg = C;
plot openagg  = O;
closeagg.SetPaintingStrategy(PaintingStrategy.SQUARES);
openagg.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
closeagg.SetLineWeight(2);
openagg.SetLineWeight(2);
closeagg.AssignValueColor(if C > O then Color.GREEN else if C == O then Color.WHITE else Color.RED);
openagg.AssignValueColor(if C > O then Color.GREEN else if C == O then Color.WHITE else Color.RED);

#------------------------------------
#Clouds - for 1 bar formation will plot continuously (kinda messy look); for 2 bars formation will not plot; otherwise these should appear

input show_cloud = yes;
DefineGlobalColor("Up", Color.LIGHT_GREEN);
DefineGlobalColor("Dn", Color.LIGHT_RED);
AddCloud(if !show_cloud or sider[1] != sider[0] then Double.NaN else if O < C then H else Double.NaN, L, GlobalColor("Up"), GlobalColor("Up"));
AddCloud(if !show_cloud or sider[1] != sider[0] then Double.NaN else if O > C then H else Double.NaN, L, GlobalColor("Dn"), GlobalColor("Dn"));
AddCloud(if !show_cloud or sider != sider[-1] then Double.NaN else if O < C then H else Double.NaN, L, GlobalColor("Up"), GlobalColor("Up"));
AddCloud(if !show_cloud or sider != sider[-1] then Double.NaN else if O > C then H else Double.NaN, L, GlobalColor("Dn"), GlobalColor("Dn"));

#-----------------------------
#Plots Sides in case missed by code above
def hgreen = if (modTime == 0 or barEnd[1] == 1) and C >= O then H else NA;
def lgreen = if (modTime == 0 or barEnd[1] == 1) and C >= 0 then L else NA;
AddChart(high = hgreen, low = lgreen, open = Double.NaN, close = Double.NaN, growColor = Color.GREEN, type = ChartType.BAR);
def hred = if (modTime == 0 or barEnd[1] == 1) and C < O then H else NA;
def lred = if (modTime == 0 or barEnd[1] == 1) and C < O then L else NA;
AddChart(high = hred, low = lred, open = Double.NaN, close = Double.NaN, growColor = Color.RED, type = ChartType.BAR);


#------------------------------------
# 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
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
310 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top