Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © jeffreyl166
- //@version=5
- indicator(title="Customized Stochastic", shorttitle="Customized Stochastic", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
- periodK = input.int(14, title="%K Length", minval=1)
- smoothK = input.int(1, title="%K Smoothing", minval=1)
- periodD = input.int(3, title="%D Smoothing", minval=1)
- buyzone = input.int(50, title="buyzone from 100 down to =", minval=1)
- sellzone = input.int(50, title="sellzone from 0 up to =", minval=1)
- overbought_zone = input.int(80, title="overbought zone", minval=1)
- oversold_zone = input.int(20, title="oversold zone", minval=1)
- inp = input(close)
- k = ta.sma(ta.stoch(inp, high, low, periodK), smoothK)
- d = ta.sma(k, periodD)
- plot(k, title="%K", color=#2962FF)
- plot(d, title="%D", color=#FF6D00)
- h0 = hline(100, "Upper Band", color=#787B86)
- h1 = hline(buyzone, "middle Band", color=#787B86)
- h2 = hline(sellzone, "middle Band", color=#787B86)
- h3 = hline(0, "Upper Band", color=#787B86)
- fill(h0, h1, color.new(color.green, 85))
- fill(h3, h2, color.new(color.red, 85))
- // Divergences
- pivot_right = 5
- pivot_left = 5
- max_range = 50
- min_range = 5
- pivot_low_true = na(ta.pivotlow(k, pivot_left, pivot_right)) ? false : true
- pivot_high_true = na(ta.pivothigh(k, pivot_left, pivot_right)) ? false : true
- confirm_range(x) =>
- bars = ta.barssince(x == true)
- min_range <= bars and bars <= max_range
- //
- CCI_HL_check = k[pivot_right] > ta.valuewhen(pivot_low_true, k[pivot_right], 1) and confirm_range(pivot_low_true[1])
- CCI_LL_check = k[pivot_right] < ta.valuewhen(pivot_high_true, k[pivot_right], 1) and confirm_range(pivot_high_true[1])
- //
- price_ll_check= low[pivot_right] < ta.valuewhen(pivot_low_true, low[pivot_right], 1)
- price_hl_check= high[pivot_right] > ta.valuewhen(pivot_high_true, high[pivot_right], 1)
- bullcond = price_ll_check and CCI_HL_check and pivot_low_true
- bearcond = price_hl_check and CCI_LL_check and pivot_high_true
- //
- plot(
- pivot_low_true ? k[pivot_right] : na,
- offset=-pivot_right,
- linewidth=3,
- color=(bullcond ? color.green :color.new(color.white, 100)))
- plotshape(
- bullcond ? k[pivot_right] : na,
- offset=-pivot_right,
- text="DIV",
- style=shape.labelup,
- location=location.absolute,
- color=color.green,
- textcolor=color.white)
- plot(
- pivot_high_true ? k[pivot_right] : na,
- offset=-pivot_right,
- linewidth=3,
- color=(bearcond ? color.red :color.new(color.white, 100)))
- plotshape(
- bearcond ? k[pivot_right] : na,
- offset=-pivot_right,
- text="DIV",
- style=shape.labeldown,
- location=location.absolute,
- color=color.red,
- textcolor=color.white)
- // Stochastic overbought and oversold signals
- ob_signal = ta.crossover(k, overbought_zone)
- os_signal = ta.crossunder(k, oversold_zone)
- plotshape(ob_signal, style=shape.circle, color=color.red, location=location.top, size=size.tiny)
- plotshape(os_signal, style=shape.circle, color=color.green, location=location.bottom, size=size.tiny)
- //Alerts
- alertcondition(ob_signal, title="Stochastic overbought", message="Stochastic overbought")
- alertcondition(os_signal, title="Stochastic oversold", message="Stochastic oversold")
- alertcondition(bullcond, title="Stochastic bull divergence", message="Stochastic bull divergence")
- alertcondition(bearcond, title="Stochastic bear divergence", message="Stochastic bear divergence")
- alertcondition(ta.crossover(k,buyzone), title="Stochastic crossover to buyzone", message="Stochastic crossover to buyzone")
- alertcondition(ta.crossunder(k,sellzone), title="Stochastic crossunder to sellzone", message="Stochastic crossunder to sellzone")
Advertisement
Add Comment
Please, Sign In to add comment