Divergent Bar Indicator for ThinkorSwim

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

dolomick

Member
Shouldn't Tesla have triggered on 1/16 on a daily chart? It did for the Simpler trading moderator who defines a divergent bar the way it is defined in the header of the tradingview port version on post #17. Can someone take a look and see if I am wrong somehow? I would like a version that matches what they are doing at Simpler ideally. Thanks....

Okay I figured it out - the Simpler Trading version doesn't use the alligator lines to help confirm the signal, once I removed that part of the code it matches the Simpler trading one.
 
Last edited by a moderator:

J-Fearless

New member
VIP
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:

hexis777

New member
VIP
@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
---
hi my friends, can we use this script en the watchlist?
 

cbfenner

New member
@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!
 

DeeO

New member
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?
 

cbfenner

New member
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
 

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

Similar threads

Top