Reversal Candle Anomaly Detector w/Volume-Colored Candles - VPA for ThinkOrSwim

Wiinii

Member
UPDATED 1/28/23

VPA (Volume Price Analysis) taught by Anna Couling (A Complete Guide To Volume Price Analysis) and Thor Young (A Complete Day Trading System). This shows low/high volume candles/bars, but more importantly, candle anomalies/divergence (irregular bodies) often signifying a trend reversal or the direction the market makers want the stock to go.

Indicates:
  • Candles with high volume (bright green/red)
  • Candles with low volume (dark green/red)
  • Average volume (standard green/red)
  • Detects candle anomaly: short candle and/or candle body but with high volume (Cyan/Magenta)
  • Detects candle anomaly: tall candle and/or candle body but with low volume very light green/red (nearly white)
  • I've added an RSI option for the short anomaly candles/bodies as well to help reduce the noise
Tall_Candle_X = Candle % Taller than average.
Short_Candle_X = Candle % Shorter than average.
X_VolAvg = % higher or lower volume than average.
Volume_Candles_Average = Number of candles it's averaging anomalous candle size and volume to.

IMPORTANT NOTES How to trade these:
  1. Specifically, on the magenta/cyan anomaly candles ('magic candles' as my friends affectionally call them), you only trade them if the price reverses off of them (usually on the next candle).
  2. However, the next candle nearly always retests first, on all timeframes (you will see it do it to the 1min candles first, then again on the 5min, and so-on), so again see note 1 above.
  3. When you see one of these that seems to be in the middle of nowhere, you are most likely missing something! There's nearly always support/resistance there, be it daily or intraday price level, trendline, premarket high/low, previous day high/low/close, something! So if you don't see why, learn why and start looking for whatever that is in the future.
  4. I believe that these magic candles are actually someone taking profit, not buying or selling, which stalls the price and can signal for the bears/bulls to pounce, and this causes a reversal. So think about it, when the bulls start to take profit they sell, this causes other bulls to take profit and sell, and the bears see that and pounce and start shorting along with them - reversal!
    Large buyers and sellers I believe are tall high volume and fast moving red and green candles. Otherwise large buyers and sellers enter trades when you see the L2 spinning but the price not moving, and likely over time rather than all at once.
  5. Stocks often reverse on the low-volume tall anomaly candles instead, this means the market makers wanted to turn the price, so they just grab it and do it fast on low volume. But watch out! This sometimes means the MMs are about to purposely fake a bunch of people out, for example moving quickly through all of the MAs which makes people get in, only to drop it right back the other direction again. This gives them the momentum then need to break a level. Remember, the market moves on market orders (not limit orders), the best way to get market orders is by faking people out and using their stops as momentum.
  6. Lastly, if you see a reversal candle and it works in your favor, and you're very extended from the open so you might have caught a full reversal (perhaps near cam levels 3 and 4) - and then (I'm going to use a reversal from way up high, so you're going short - but this works the other way too) suddenly the price goes back up then spikes very hard up past the high of day, stalls, and then goes right back down on the next candle , that is a UTDAD (Up Thrust After Distribution, at the top) or Wykoff Spring (from the bottom), also known simply as the selling or buying climax . This usually looks like 2 tall candles nearly the same height and often wickless, and this happens on the 1-minute or 5-minute timeframe (not both). This too is meant to grab some momentum stops to shoot the other direction. Example Wykoff Spring on the 5min timeframe.

Shared Link: http://tos.mx/0XSGjXM (or use code below). Click here for --> Easiest way to load shared links

F4LOyt2.png


U4ETbN9.png


Code:
# VPA Candles & Bars with Anomaly Detector by Wiinii
# Version 1.2
# Original Volume-colored candles code by BenTen
#https://usethinkscript.com/threads/vpa-candles-bars-with-anomaly-detector-for-thinkorswim.13831/

#hint: Indicates candles with high volume (bright green/red), candles with low volume (dark green/red) average volume (standard green/red), and detects candle anomalies with high volume - short candles (Cyan/Magenta) and low volume - tall candles (very light green/red). \n Tall_Candle_X = Candle % Taller than average. \n Short_Candle_X = Candle % Shorter than average. \n X_VolAvg = % higher or lower volume than average. \n Volume_Candles_Average = Number of candles it's averaging anomalous candle size and volume to.

declare on_volume;

input Irregular = {default "Bodies", "Both", "Candles"};
input CandlesAndVolAvg = 5;
input VolAvgType = AverageType.EXPONENTIAL;
input Use_RSI = yes;
def RSIType = RSI(averageType = "EXPONENTIAL");
input RSIHi = 65;
input RSILo = 35;

input ShortCandleVolMulti = 1.0;

input PaintLoVolTallCandles = yes;
input TallCandleVolMulti = 0.8;


def AvgCandle = SimpleMovingAvg(price = (high[1] - low[1]), length = CandlesAndVolAvg);
def AvgCandleBody = Average(BodyHeight(), CandlesAndVolAvg);

def CurrentCandle = high - low;

plot Vol = volume;
Vol.SetHiding (1 == 1);
plot VolAvg = MovingAverage(VolAvgType, volume, CandlesAndVolAvg);
VolAvg.SetPaintingStrategy(PaintingStrategy.LINE);
VolAvg.SetDefaultColor(Color.CYAN);

def VolHi = volume > VolAvg * 1.2;
def VolMed = volume >= VolAvg * 0.8 and volume <= VolAvg * 1.2;
def VolLo = volume < VolAvg * 0.8;

def UVolHi = VolHi and close > open;
def UVolMed = VolMed and close > open;
def UVolLow = VolLo and close > open;

def DVolHi = VolHi and close < open;
def DVolMed = VolMed and close < open;
def DVolLow = VolLo and close < open;

def S_Candle = CurrentCandle <= AvgCandle;
def S_Body = BodyHeight() <= AvgCandleBody;
def ShortVolAnomolyCandleUp = if (if Irregular == irregular.Candles then S_Candle else if Irregular == irregular.Bodies then S_Body else S_Candle or S_Body) and (volume > VolAvg * ShortCandleVolMulti) and (if Use_RSI then (RSIType >= RSIHi or RSIType <= RSILo) else RSI()) and close > open then 1 else Double.NaN;
def ShortVolAnomolyCandleDn = if (if Irregular == irregular.Candles then S_Candle else if Irregular == irregular.Bodies then S_Body else S_Candle or S_Body) and (volume > VolAvg * ShortCandleVolMulti) and (if Use_RSI then (RSIType >= RSIHi or RSIType <= RSILo) else RSI()) and close < open then 1 else Double.NaN;

def T_Candle = CurrentCandle >= AvgCandle;
def T_Body = BodyHeight() >= AvgCandleBody;
def TallVolAnomolyCandleUp = if PaintLoVolTallCandles and (if Irregular == irregular.Candles then T_Candle else if Irregular == irregular.Bodies then T_Body else T_Candle or T_Body) and (volume < VolAvg * TallCandleVolMulti) and close > open then 1 else Double.NaN;
def TallVolAnomolyCandleDn = if PaintLoVolTallCandles and (if Irregular == irregular.Candles then T_Candle else if Irregular == irregular.Bodies then T_Body else T_Candle or T_Body) and (volume < VolAvg * TallCandleVolMulti) and close < open then 1 else Double.NaN;

Vol.DefineColor("UVolHi", CreateColor(0, 255, 0));
Vol.DefineColor("UVolMed", CreateColor(0, 175, 0));
Vol.DefineColor("UVolLow", CreateColor(0, 40, 0));
Vol.DefineColor("DVolHi", CreateColor(255, 0, 0));
Vol.DefineColor("DVolMed", CreateColor(175, 0, 0));
Vol.DefineColor("DVolLow", CreateColor(60, 0, 0));
Vol.DefineColor("NoVol", Color.GRAY);
Vol.DefineColor("HiVol_ShortCandleUp", Color.CYAN);
Vol.DefineColor("HiVol_ShortCandleDn", Color.MAGENTA);
Vol.DefineColor("LoVol_TallCandleUp", CreateColor(153,255,153));
Vol.DefineColor("LoVol_TallCandleDn", CreateColor(255,225,255));

AssignPriceColor(
    if UVolHi then Vol.Color("UVolHi")
    else if DVolHi then Vol.Color("DVolHi")
    else if UVolMed then Vol.Color("UVolMed")
    else if DVolMed then Vol.Color("DVolMed")
    else if UVolLow then Vol.Color("UVolLow")
    else if DVolLow then Vol.Color("DVolLow")
    else Color.CURRENT);

AssignPriceColor(if ShortVolAnomolyCandleUp then Vol.Color("HiVol_ShortCandleUp") else Color.CURRENT);
AssignPriceColor(if ShortVolAnomolyCandleDn then Vol.Color("HiVol_ShortCandleDn") else Color.CURRENT);
AssignPriceColor(if TallVolAnomolyCandleUp then Vol.Color("LoVol_TallCandleUp") else Color.CURRENT);
AssignPriceColor(if TallVolAnomolyCandleDn then Vol.Color("LoVol_TallCandleDn") else Color.CURRENT);

TROUBLESHOOTING:

1. Above your chart click the Gear icon and check 'Show volume subgraph' like so:

eOCL93N.png


2. General > Layout > Show price subgraph (need to check this option)
3. Appearance > Volume bars > Color as symbol ticks (need to check this option)
 
Last edited:
@Wiinii Great work again!
My request is to provide an option(Yes/No) for each of the plots, so users can selectively enable plots of interest(to them).
For eg, lets say I just want to highlight the candle bars, that have low spread(ie small candle body), but high volume(ie Cyan)...

Also, for the tall candles with low volumes, I'd want to paint the candle with a color thats still indicative of bull bar(greenish) or bear bar(reddish)...instead of statically painting them Magenta. For eg, if I have a tall bull candle with low volume, paint it "light green" and if there's a tall bear candle with low volume, I'd want it to paint "pink or magenta" ..so it retains the original bias.

Thanks!
 
@Wiinii Great work again!
My request is to provide an option(Yes/No) for each of the plots, so users can selectively enable plots of interest(to them).
For eg, lets say I just want to highlight the candle bars, that have low spread(ie small candle body), but high volume(ie Cyan)...

Also, for the tall candles with low volumes, I'd want to paint the candle with a color thats still indicative of bull bar(greenish) or bear bar(reddish)...instead of statically painting them Magenta. For eg, if I have a tall bull candle with low volume, paint it "light green" and if there's a tall bear candle with low volume, I'd want it to paint "pink or magenta" ..so it retains the original bias.

Thanks!
Done.
 
Last edited:
I may indeed make those changes. but for now, you might prefer my other similar work that does what you're asking found here.
Thanks but that one doesnt allow me to define what constitutes a long candle, short candle ..like this one does. I'll see if I can tweak the colors manually and see if it works for me..
 
Quite a few updates added:
  • Now differently colored anomaly up/down candles.
  • Option to look for anomaly candles, candle bodies, or both.
  • Option to disabled tall anomalies.
  • RSI Option for the short anomaly candles/bodies to clean up noise.
Prolly more I'm forgetting. It's a beast!

EDIT 3/30/23: Added instructions on how to use them in the first post.
 
Last edited:
@Wiinii Do you think it's possible to turn this into a scan?

For example.

To detect candle anomalies with high volume - short candles (*Cyan/Magenta) and low volume - tall candles (*very light green/red).

Thanks
 
@Wiinii Do you think it's possible to turn this into a scan?

For example.

To detect candle anomalies with high volume - short candles (*Cyan/Magenta) and low volume - tall candles (*very light green/red).

Thanks

I am not sure that this script is working the way you and the @Wiinii envision.

This script cannot work.
In the ToS app, only ONE AssignPriceColor statement is allowed per chart to color the candles.
This script has FIVE 'AssignPriceColor statements, Oh My!
The OP will need to fix the script to make it work correctly.

If you accept that this script may perhaps present flaky results, and you still want your scan then here ya go:

1. Change the "def" statement that applies to whatever color you think you are seeing to say "plot" instead of "def"
2. And then choose that filter in your scan hacker.
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/
 
Last edited:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
469 Online
Create Post

Similar threads

Similar threads

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