Candlestick Sentiment Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
My recent discovery in terms of trading learning materials is "YTC Price Action Trader" book. It contains numerous invaluable clues, which I couldn't find anywhere else. One YTC chapter covers Candle Sentiment analysis. Watching where 'close' of the candle happens can give early hints about future market action. Most of time you get those hints before the indicators provide it.

Close Sentiment: This is single-candle analysis. Divide entire range of a candle (low to high) into 3 equal parts. The candle is:
  • "High Close" - if 'close' is in the upper 1/3
  • "Mid Close" - if 'close' is in the middle 1/3
  • "Low Close" - if 'close' is in the lower 1/3
Close Comparison: Compare position of 'close' with entire range of the previous candle. The candle is:
  1. Bull Candle - if 'close' is above 'high' of the previous candle
  2. Range Candle - if 'close' is between 'high' and 'low' of the previous candle
  3. Bear Candle - if 'close' is below 'low' of the previous candle
What can you do with this? It gives very good and early reversal hints. Mid/ranging signals should be considered "no signals" - in other words: market will continue in the same direction.



thinkScript Code

Code:
# YTC Candlestick Sentiment
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/5fSgjYoM-YTC-Candlestick-Sentiment/

def highclose = (close - low) >= (2 * (high - low) / 3);
def midclose=(close-low)>((high-low)/3) and (close-low)<(2* (high-low)/3);
def lowclose = (close - low) <= ((high - low) / 3);
def YTCbullcandle = close > high[1];
def YTCrangecandle = close < high[1] and close>low[1];
def YTCbearcandle = close < low[1];

assignPriceColor(if YTCbullcandle then Color.GREEN else if YTCbearcandle then Color.RED else Color.WHITE);
 
markos

markos

Well-known member
VIP
You may have stumbled onto something here.... on the ROKU chart you seem to get a white candle between polarity changes. Just a clue? Maybe.
 
D

diazlaz

Well-known member
2019 Donor
VIP
ben - very cool - glad you're bring/porting price based indicators. this one has potential!

Does a nice job on daily chart stop trends and reversal - here is the longer time frame 1Y on SPY

 
Last edited by a moderator:
D

diazlaz

Well-known member
2019 Donor
VIP
Here is the revised version.

Ruby:
# YTC Candlestick Sentiment
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/5fSgjYoM-YTC-Candlestick-Sentiment/
# 2019.10.08 - diazlaz - Adding states, thresholds, arrows and color bars.

def highclose = (close - low) >= (2 * (high - low) / 3);
def midclose=(close-low)>((high-low)/3) and (close-low)<(2* (high-low)/3);
def lowclose = (close - low) <= ((high - low) / 3);
def YTCbullcandle = close > high[1];
def YTCrangecandle = close < high[1] and close>low[1];
def YTCbearcandle = close < low[1];

# assignPriceColor(if YTCbullcandle then Color.GREEN else if YTCbearcandle then Color.RED else Color.WHITE);

#INPUTS
input showColorBars = yes;
input showArrows = yes;
input YTCThreshold = 2;

#STATES
def sYTC1 = if YTCbullcandle then 100 else if YTCbearcandle then -100 else sYTC1[1];
def sYTC2 = if Sum(sYTC1, YTCThreshold) >= (YTCThreshold * 100) then 100 else if Sum(sYTC1, YTCThreshold) <= (YTCThreshold * -100) then -100 else sYTC2[1];
def sState = sYTC2;

#ARROWS
def sUP = sState crosses above 0;
def sDown = sState crosses below 0;

plot pUP = if !isNan(sUP) then sUP else Double.NaN;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);
pUP.SetHiding(!showArrows);

plot pDown = if !isNan(sDown) then sDown else Double.NaN;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);
pDown.SetHiding(!showArrows);

#COLORBARS
def pCB = sState;

AssignPriceColor(
if showColorBars then
 
 if IsNaN(pCB) then Color.DARK_GRAY else
 if pCB == 100 then Color.GREEN else
 Color.RED

else

  Color.CURRENT
);

# End of YTC Candlestick Sentiment
 
Last edited by a moderator:
J007RMC

J007RMC

Active member
2019 Donor
VIP
Nice using this indicator today would have caught and or confirmed many moves in PANW today.
 
C

Charles

New member
Lifetime
Thanks @BenTen it's great that you can take an idea from the page of a book and make something with it. @diazlaz great addon for this one!
 
BenTen

BenTen

Administrative
Staff
VIP
@Charles Wish I can take credit but I can't. The original developer was the real genius. I just converted his script from TradingView to ThinkorSwim.
 
horserider

horserider

Well-known member
VIP
Most reversals of a trend occur with a consolidation phase of two or more candles. Since this highlights range bound candles it may highlight those areas of potential reversal. Be careful of trading isolated white candles.
 
J

jimothy

New member
@Charles Wish I can take credit but I can't. The original developer was the real genius. I just converted his script from TradingView to ThinkorSwim.
@BenTen and @diazlaz
I added GetTime() < RegularTradingEnd(GetYYYYMMDD()) and GetTime() > RegularTradingStart(GetYYYYMMDD()) to the definitions.

is there any reason after doing that, that adding a SMA 50 will prevent the UP indicator from showing up in instances?

this simple line will make the arrow not appear some times.
plot SMA2_plot = SimpleMovingAvg(close, 50);

complete code is

Code:
# YTC Candlestick Sentiment
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/5fSgjYoM-YTC-Candlestick-Sentiment/
# 2019.10.08 - diazlaz - Adding states, thresholds, arrows and color bars.

def highclose = (close - low) >= (2 * (high - low) / 3) and GetTime() < RegularTradingEnd(GetYYYYMMDD()) and GetTime() > RegularTradingStart(GetYYYYMMDD());
def midclose=(close-low)>((high-low)/3) and (close-low)<(2* (high-low)/3) and GetTime() < RegularTradingEnd(GetYYYYMMDD()) and GetTime() > RegularTradingStart(GetYYYYMMDD());
def lowclose = (close - low) <= ((high - low) / 3) and GetTime() < RegularTradingEnd(GetYYYYMMDD()) and GetTime() > RegularTradingStart(GetYYYYMMDD());
def YTCbullcandle = close > high[1] and GetTime() < RegularTradingEnd(GetYYYYMMDD()) and GetTime() > RegularTradingStart(GetYYYYMMDD());
def YTCrangecandle = close < high[1] and close>low[1] and GetTime() < RegularTradingEnd(GetYYYYMMDD()) and GetTime() > RegularTradingStart(GetYYYYMMDD());
def YTCbearcandle = close < low[1] and GetTime() < RegularTradingEnd(GetYYYYMMDD()) and GetTime() > RegularTradingStart(GetYYYYMMDD());

# assignPriceColor(if YTCbullcandle then Color.GREEN else if YTCbearcandle then Color.RED else Color.WHITE);

#INPUTS
input showColorBars = yes;
input showArrows = yes;
input YTCThreshold = 2;

#STATES
def sYTC1 = if YTCbullcandle then 100 else if YTCbearcandle then -100 else sYTC1[1];
def sYTC2 = if Sum(sYTC1, YTCThreshold) >= (YTCThreshold * 100) then 100 else if Sum(sYTC1, YTCThreshold) <= (YTCThreshold * -100) then -100 else sYTC2[1];
def sState = sYTC2;

#ARROWS
def sUP = sState crosses above 0;
def sDown = sState crosses below 0;

plot pUP = if !isNan(sUP) then sUP else Double.NaN;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);
pUP.SetHiding(!showArrows);

plot pDown = if !isNan(sDown) then sDown else Double.NaN;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);
pDown.SetHiding(!showArrows);

#COLORBARS
def pCB = sState;

AssignPriceColor(
if showColorBars then

if IsNaN(pCB) then Color.DARK_GRAY else
if pCB == 100 then Color.GREEN else
Color.RED

else

  Color.CURRENT
);

# End of YTC Candlestick Sentiment

plot SMA2_plot = SimpleMovingAvg(close, 50);
with SMA on within the script


with SMA off within the script



looks like having the SMA50 also turns the previous candles red?

edit ok I think the problem is that the original is using either the overnight candle sentiment, or, using my code, it is using the previous days sentiment in conjunction with the first bar of this day, etc.

is there a way to modify this to basically look at every day in isolation? assume you wanted to automate this script to give u a buy signal or sell signal for day trading
 
Last edited:

Similar threads

Top