Divergent Bar Indicators (MotiveWave) for ThinkorSwim

I would love to see thinkscript for divergent bar for motivewave
A bullish (green) divergent bar, signals a trend switch from bear -> bull
-> The current bar has a lower low than the previous bar, but closes in the upper half of the candle.
-> This means the bulls are pushing from below and are trying to take over, potentially resulting in a trend switch to bullish .
-> We also check if this bar is below the three alligator lines to avoid false positives.

A bearish (red) divergent bar, signals a trend switch from bull -> bear
-> The current bar has a higher high than the previous bar, but closes in the lower half of the candle.
-> This means the bears are pushing the price down and are taking over, potentially resulting in a trend switch to bearish .
-> We also check if this bar is above the three alligator lines to avoid false positives.

Best used in combination with the Bill Williams Alligator indicator.
 
Last edited by a moderator:

New Indicator: Buy the Dip

Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.

Download the indicator

@samiranadhikari - here you go, can you take it for a spin and see if this works for you.
Most Updated Version:
Ruby:
#Divergent Bar from MotiveWave V1.2
# @samiranadhikari request
#
# 2019.12.13 @diazlaz - Bug fix on prevLow and prevHigh
# 2019.12.13 @diazlaz - logic change/feedback from @EMMA
# 2019.12.06 @diazlaz - initial port/interpretation.

def prevLow = Low[1];
def prevHigh = High[1];
def currentAverage = (High + Low) / 2;

def buy = (Low < prevLow AND Close > currentAverage);
def sell = (High > prevHigh AND Close < currentAverage);

def sState = if buy then 100 else if sell then -100 else sState[1];

# ARROWS
input showArrows = yes;
plot pUP = showArrows  and buy;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);

plot pDown = showArrows  and sell;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);

#COLORBARS
input showColorBars = yes;
AssignPriceColor(if showColorBars then
if sState > 0 then Color.GREEN
  else Color.RED
else
  COLOR.CURRENT
);

#LABELS
input showLabels = yes;
AddLabel(showLabels, "Buy",
if isNaN(sState) then COLOR.DARK_GRAY else
If sState == 100 then COLOR.GREEN else COLOR.DARK_GRAY);

AddLabel(showLabels, "Sell",
if isNaN(sState) then COLOR.DARK_GRAY else
If sState == -100 then COLOR.RED else COLOR.DARK_GRAY);

#END of Divergent Bar from MotiveWave V1.2
 
Last edited by a moderator:
DJ864Oz.png
 
Where can I find info about what this study does ? and am I supposed to see a line and arrows or just arrows ?
 
Last edited:
I would love to see a few indicators aligned in the same direction. This helps me to think in terms of probability of success. However, everything can change with a disappointing market moving event. Having said that, odds are more in favor to rely on the finding of divergent bar supported by 50 day EMA or Anchored VWAP or DMI crossover on a larger time frame.
 
DJ864Oz.png

Thanks @diazlaz ! I have been looking for this indicator for a while, so glad to find it here! But after imported it into tos, I found some of the bars are not actually divergent bars. I marked a few bars on the picture that @samiranadhikari uploaded. The lows of the first two bars are not lower than the previous bar, and the high of the third bar is not higher than the previous bar. I am new to thinkscript, can't find any bug in the code. Would someone please take a look? Thanks in advance!

Here is the definition I found for divergent bars: Divergent Bars (Bullish, the current bar must have lower low than previous bar AND current bar must close in the upper half) (Bearish, The current bar must have a higher high than previous bar AND current bar must close in the lower half).

@Buckbull , here is some information https://www.tradingview.com/script/lLgCdjag-Bill-Williams-Divergent-Bars/
 
Last edited:
I just wanted to mention that this repaints. It's honestly not a huge problem since if you take the signals in the trend direction it has a very high success rate, but thought I'd mention. It repaints both the arrows and the candle color. I had two consecutive 15m bearish candles this morning on AMD. Now that AMD is breaking out nearly an hour later those are both green and the red arrows are gone. This is excellent for suggesting a trade though and I like it a lot, but be careful looking at it historically. It only really has failed me so far on a counter trend move, which are tricky to handle anyway unless that's your thing.

My above statement applies to the code in the second post
 
Last edited by a moderator:
@samiranadhikari - here you go, can you take it for a spin and see if this works for you.

Ruby:
#Divergent Bar from MotiveWave
# @samiranadhikari request
#
# 2019.12.06 @diazlaz - initial port/interpretation.
#

def prevLow = Low[-1];
def prevHigh = High[-1];
def currentAverage = (High + Low) / 2;

def buy = (Low < prevLow AND Close > currentAverage);
def sell = (High > prevHigh AND Close < currentAverage);

def sState = if buy then 100 else if sell then -100 else sState[1];

# ARROWS
input showArrows = yes;
plot pUP = sState crosses above 0;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);

plot pDown = sState crosses below 0;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);

#COLORBARS
input showColorBars = yes;
AssignPriceColor(if showColorBars then
if sState > 0 then Color.GREEN
  else Color.RED
else
  COLOR.CURRENT
);

#LABELS
input showLabels = yes;
AddLabel(showLabels, "Buy",
if isNaN(sState) then COLOR.DARK_GRAY else
If sState == 100 then COLOR.GREEN else COLOR.DARK_GRAY);

AddLabel(showLabels, "Sell",
if isNaN(sState) then COLOR.DARK_GRAY else
If sState == -100 then COLOR.RED else COLOR.DARK_GRAY);

#END of Divergent Bar from MotiveWave
Thanks for this code. How can I set up a scan in TOS? In the custom study, what should I make pUp equal to? Thanks!
 
The scan would be: pUp is true.
 
Last edited by a moderator:
How to print Divergent bar colors in current playing bar rather than at the start of new bar? Example: In daily time frame chart, i am not getting the divergent bar confirmation until the next day open. Is there a fix to it?
 
How to print Divergent bar colors in current playing bar rather than at the start of new bar? Example: In daily time frame chart, i am not getting the divergent bar confirmation until the next day open. Is there a fix to it?
I am NOT an expert on TOS but I tweaked one of the scripts form this forum so that I can get 4 colors on the divergent bars. I set Blue as a Bullish buy and pink as a bearish sell. I hope this helps.

Code:
#Divergent Bar from MotiveWave
# [USER=717]@samiranadhikari[/USER] request
#
# 2019.12.06 [USER=258]@diazlaz[/USER] - initial port/interpretation.
#
#Divergent Bar from MotiveWave V1.2
# [USER=717]@samiranadhikari[/USER] request
#
# 2019.12.13 [USER=258]@diazlaz[/USER] - Bug fix on prevLow and prevHigh
# 2019.12.13 [USER=258]@diazlaz[/USER] - logic change/feedback from [USER=1993]@EMMA[/USER]
# 2019.12.06 [USER=258]@diazlaz[/USER] - initial port/interpretation.

def prevLow = low[1];
def prevHigh = high[1];
def currentAverage = (high + low) / 2;

def buyD = (low < prevLow and close > currentAverage);
def sellD = (high > prevHigh and close < currentAverage);
def buy = (low < prevLow and close < currentAverage);
def sell = (high > prevHigh and close > currentAverage);

#def sState = if buy then 100 else if sell then -100 else sState[1];

# ARROWS
input showArrows = yes;
plot pUP = showArrows  and buy;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);

plot pDown = showArrows  and sell;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);

#COLORBARS
input showColorBars = yes;
AssignPriceColor(if buyD then Color.BLUE
else
if sellD then Color.PINK
else
  Color.CURRENT
);

#COLORBARS
#input showColorBars = yes;
#AssignPriceColor(if showColorBars then
#if sState > 0 then Color.GREEN
#  else Color.RED
#else
# COLOR.CURRENT
# );




#LABELS
#input showLabels = yes;
#AddLabel(showLabels, "Buy",
#if IsNaN(sState) then Color.DARK_GRAY else
#if sState == 100 then Color.GREEN else Color.DARK_GRAY);

#AddLabel(showLabels, "Sell",
#if IsNaN(sState) then Color.DARK_GRAY else
#if sState == -100 then Color.RED else Color.DARK_GRAY);

#END of Divergent Bar from MotiveWave V1.2
 

Volatility Trading Range

VTR is a momentum indicator that shows if a stock is overbought or oversold based on its Weekly and Monthly average volatility trading range.

Download the indicator

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
185 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