Its interesting, i'm noticing differences in the candle price data from ToS and Trading View. Some of the candles have different values, but overall, It looks like it's working correctly. This observation on the data differences is when looking at it in the 1 minute candle.
Original:
Port:
Code:
Original:
Port:
Code:
Ruby:
# Bill William Bull/Bear divergent bars
# See: Book, Trading Chaos by Bill Williams
#
# https://www.tradingview.com/script/lLgCdjag-Bill-Williams-Divergent-Bars/
# Author: polyclick
#
# 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.
#
#
# @@EMMA request
#
# 2019.12.13 @diazlaz - logic bug fixes.
# 2019.12.13 @diazlaz - initial port/interpretation.
#
# LOGIC
def price = hl2;
def jawLength = 13;
def teethLength = 8;
def lipsLength = 5;
def jawDisplace = -8;
def teethDisplace = -5;
def lipsDisplace = -3;
def averageType = AverageType.WILDERS;
def lips = MovingAverage(averageType, price[-lipsDisplace], lipsLength);
def jaw = MovingAverage(averageType, price[-jawDisplace], jawLength);
def teeth = MovingAverage(averageType, price[-teethDisplace], teethLength);
def bullDivSignal = low < low[1] and close > hl2 and high < lips and high < teeth and high < jaw;
def bearDivSignal = high > high[1] and close < hl2 and low > lips and low > teeth and low > jaw;
def sState = if bullDivSignal then 100 else if bearDivSignal then -100 else sState[1];
# ARROWS
input showArrows = yes;
plot pUP = showArrows and bullDivSignal;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);
plot pDown = showArrows and bearDivSignal;
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 bullDivSignal then COLOR.GREEN else COLOR.DARK_GRAY);
AddLabel(showLabels, "Sell",
if isNaN(sState) then COLOR.DARK_GRAY else
If bearDivSignal then COLOR.RED else COLOR.DARK_GRAY);
# END OF Bill William Bull/Bear divergent bars
Last edited by a moderator: