<edited code 08-09-2025>:
Added user-controlled colors for BARs, CANDLEs, Highest & Lowest, Last price
The following are enhanced studies based on the works of @petergluis and @halcyonguy found on this thread:
Heikin-Ashi Candles Lower Chart For ThinkorSwim (assorted versions)
In the image are default tos BAR and CANDLE charts on the top with the enhanced CANDLE and BAR studies in the lower charts.
The tos default BAR chart does not treat 'doji' bars (color of WHITE) as defined in Investopedia:
"...in which a security has an open and close that are virtually equal, which resembles a candlestick on a chart."
The enhanced BAR study meets the above definition.
The colors of both BARs and CANDLEs may be changed to user's preference in the code.
CANDLE fill is user controlled (on/off).
CANDLE code:
BAR code:
Added user-controlled colors for BARs, CANDLEs, Highest & Lowest, Last price
The following are enhanced studies based on the works of @petergluis and @halcyonguy found on this thread:
Heikin-Ashi Candles Lower Chart For ThinkorSwim (assorted versions)
In the image are default tos BAR and CANDLE charts on the top with the enhanced CANDLE and BAR studies in the lower charts.
The tos default BAR chart does not treat 'doji' bars (color of WHITE) as defined in Investopedia:
"...in which a security has an open and close that are virtually equal, which resembles a candlestick on a chart."
The enhanced BAR study meets the above definition.
The colors of both BARs and CANDLEs may be changed to user's preference in the code.
CANDLE fill is user controlled (on/off).
CANDLE code:
Code:
declare lower;
input Fill = yes;
def O = open;
def H = high;
def L = low;
def C = close;
#== Up CANDLE
def UpO;
def UpH;
def UpL;
def UpC;
if O <= C
then {
UpO = if Fill then C else O;
UpH = H;
UpL = L;
UpC = if Fill then O else C;
} else {
UpO = Double.NaN;
UpH = Double.NaN;
UpL = Double.NaN;
UpC = Double.NaN;
}
#== Down CANDLE
def DnO;
def DnH;
def DnL;
def DnC;
if O >= C
then {
DnO = if Fill then O else C;
DnH = H;
DnL = L;
DnC = if Fill then C else O;
} else {
DnO = Double.NaN;
DnH = Double.NaN;
DnL = Double.NaN;
DnC = Double.NaN;
}
#== Doji CANDLE
def DUpO;
def DUpH;
def DUpL;
def DUpC;
if O == C
then {
DUpO = O;
DUpH = H;
DUpL = L;
DUpC = C;
} else {
DUpO = Double.NaN;
DUpH = Double.NaN;
DUpL = Double.NaN;
DUpC = Double.NaN;
}
def DDnO;
def DDnH;
def DDnL;
def DDnC;
if O == C
then {
DDnO = O;
DDnH = H;
DDnL = L;
DDnC = C;
} else {
DDnO = Double.NaN;
DDnH = Double.NaN;
DDnL = Double.NaN;
DDnC = Double.NaN;
}
#== Up & Down CANDLE colors
DefineGlobalColor("Up", GetColor(6));
AddChart(high = UpH, low = UpL, open = UpO, close = UpC, type = ChartType.CANDLE, GlobalColor("Up"));
DefineGlobalColor("Down", GetColor(5));
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.CANDLE, GlobalColor("Down"));
#== Doji CANDLE color
AddChart(high = DUpH, low = DUpL, open = DUpO, close = DUpO, type = ChartType.CANDLE, growColor = Color.WHITE);
AddChart(high = DDnH, low = DDnL, open = DDnO, close = DDnO, type = ChartType.CANDLE, growColor = Color.WHITE);
#== Last Price color
DefineGlobalColor("Last", GetColor(9));
AddChartBubble(IsNaN(C[-1]), text = Round(C, 2), "price location" = C, GlobalColor("Last"));
#== Highest & Lowest of period color
def HA = HighestAll(H);
def LA = LowestAll(L);
DefineGlobalColor("Highest", GetColor(6));
AddChartBubble(H == HA, H, "Hi: " + Round(HA, 2), GlobalColor("Highest"));
DefineGlobalColor("Lowest", GetColor(5));
AddChartBubble(L == LA, L, "Lo: " + Round(LA, 2), GlobalColor("Lowest"), no);
BAR code:
Code:
declare lower;
def O = open;
def H = high;
def L = low;
def C = close;
#== Up BAR
def UpO;
def UpH;
def UpL;
def UpC;
if O <= C
then {
UpO = O;
UpH = H;
UpL = L;
UpC = C;
} else {
UpO = Double.NaN;
UpH = Double.NaN;
UpL = Double.NaN;
UpC = Double.NaN;
}
#== Down BAR
def DnO;
def DnH;
def DnL;
def DnC;
if O >= C
then {
DnO = O;
DnH = H;
DnL = L;
DnC = C;
} else {
DnO = Double.NaN;
DnH = Double.NaN;
DnL = Double.NaN;
DnC = Double.NaN;
}
#== Doji BAR
def DUpO;
def DUpH;
def DUpL;
def DUpC;
if O == C
then {
DUpO = O;
DUpH = H;
DUpL = L;
DUpC = C;
} else {
DUpO = Double.NaN;
DUpH = Double.NaN;
DUpL = Double.NaN;
DUpC = Double.NaN;
}
def DDnO;
def DDnH;
def DDnL;
def DDnC;
if O == C
then {
DDnO = O;
DDnH = H;
DDnL = L;
DDnC = C;
} else {
DDnO = Double.NaN;
DDnH = Double.NaN;
DDnL = Double.NaN;
DDnC = Double.NaN;
}
#== Up & Down BAR colors
DefineGlobalColor("Up", GetColor(6));
AddChart(high = UpH, low = UpL, open = UpO, close = UpC, type = ChartType.BAR, GlobalColor("Up"));
DefineGlobalColor("Down", GetColor(5));
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.BAR, GlobalColor("Down"));
#== Doji BAR color
AddChart(high = DUpH, low = DUpL, open = DUpO, close = DUpO, type = ChartType.BAR, growColor = Color.WHITE);
AddChart(high = DDnH, low = DDnL, open = DDnO, close = DDnO, type = ChartType.BAR, growColor = Color.WHITE);
#== Last Price color
DefineGlobalColor("Last", GetColor(9));
AddChartBubble(IsNaN(C[-1]), text = Round(C, 2), "price location" = C, GlobalColor("Last"));
#== Highest & Lowest of period color
def HA = HighestAll(H);
def LA = LowestAll(L);
DefineGlobalColor("Highest", GetColor(6));
AddChartBubble(H == HA, H, "Hi: " + Round(HA, 2), GlobalColor("Highest"));
DefineGlobalColor("Lowest", GetColor(5));
AddChartBubble(L == LA, L, "Lo: " + Round(LA, 2), GlobalColor("Lowest"), no);
Last edited: