Created
May 9, 2020 15:11
-
-
Save princefr/bc4dd636faf66b755a79090fc58294b8 to your computer and use it in GitHub Desktop.
divergences pines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@version=4 | |
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ | |
// © pondonda | |
study("Divergence", shorttitle="Divergence[BBQDiv]", overlay=true) | |
uHid = input(true, title="Use Hidden Divergence in Strategy") | |
uReg = input(true, title="Use Regular Divergence in Strategy") | |
SHOW_CHANNEL = input(title='Show Channel', type=input.bool, defval=false) | |
SHOW_LABEL = input(title='Show Labels', type=input.bool, defval=true) | |
// || RSI / STOCH / VOLUME / ACC/DIST Input: | |
rsi_smooth = input(title='RSI/STOCH/Volume/ACC-DIST/Fisher/cci Smooth:', type=input.integer, defval=2) | |
// MACD indicator | |
[macd_fast, macd_slow, macd_smooth] = macd(close, 12, 26, 9) | |
// plot(ema(close, 50)) | |
// || Functions: | |
f_top_fractal(_src) => | |
_src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and | |
_src[2] > _src[0] | |
f_bot_fractal(_src) => | |
_src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and | |
_src[2] < _src[0] | |
f_fractalize(_src) => | |
f_bot_fractal__1 = f_bot_fractal(_src) | |
f_top_fractal(_src) ? 1 : f_bot_fractal__1 ? -1 : 0 | |
// ||••> START ACC/DIST FUNCTION | |
f_accdist(_smooth) => | |
_return = sma(cum(close == high and close == low or high == low ? 0 : (2 * close - low - high) / (high - low) * volume), _smooth) | |
_return | |
// ||<•• END ACC/DIST FUNCTION | |
method_high = stoch(close, high, low, rsi_smooth) | |
method_low = stoch(close, high, low, rsi_smooth) | |
fractal_top = f_fractalize(method_high) > 0 ? method_high[1] : na | |
fractal_bot = f_fractalize(method_low) < 0 ? method_low[1] : na | |
high_prev = valuewhen(fractal_top, method_high[1], 1) | |
high_price = valuewhen(fractal_top, high[1], 1) | |
low_prev = valuewhen(fractal_bot, method_low[1], 1) | |
low_price = valuewhen(fractal_bot, low[1], 1) | |
regular_bearish_div = fractal_top and high[2] > high_price and method_high[2] < high_prev | |
hidden_bearish_div = fractal_top and high[2] < high_price and method_high[2] > high_prev | |
regular_bullish_div = fractal_bot and low[2] < low_price and method_low[2] > low_prev | |
hidden_bullish_div = fractal_bot and low[2] > low_price and method_low[2] < low_prev | |
plot(title='H F', series=fractal_top ? high[2] : na, color=regular_bearish_div or hidden_bearish_div ? color.red : not SHOW_CHANNEL ? na : color.silver, offset=-2) | |
plot(title='L F', series=fractal_bot ? low[2] : na, color=regular_bullish_div or hidden_bullish_div ? color.green : not SHOW_CHANNEL ? na : color.silver, offset=-2) | |
plot(title='H D', series=fractal_top ? high[2] : na, style=plot.style_circles, color=regular_bearish_div or hidden_bearish_div ? color.red : not SHOW_CHANNEL ? na : color.silver, linewidth=3, offset=-2) | |
plot(title='L D', series=fractal_bot ? low[2] : na, style=plot.style_circles, color=regular_bullish_div or hidden_bullish_div ? color.green : not SHOW_CHANNEL ? na : color.silver, linewidth=3, offset=-2) | |
plotshape(title='+RBD', series=not SHOW_LABEL ? na : regular_bearish_div ? high[2] : na, text='R', style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, offset=-2) | |
plotshape(title='+HBD', series=not SHOW_LABEL ? na : hidden_bearish_div ? high[2] : na, text='H', style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, offset=-2) | |
plotshape(title='-RBD', series=not SHOW_LABEL ? na : regular_bullish_div ? low[2] : na, text='R', style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, offset=-2) | |
plotshape(title='-HBD', series=not SHOW_LABEL ? na : hidden_bullish_div ? low[2] : na, text='H', style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, offset=-2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment