Advertisement
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/
- // © DarkPoolTrading
- // Based on the Function Sine Wave Indicator by RicardoSantos
- //@version=5
- indicator(title='Function Cosine Wave', precision=12)
- method1 = input.string('Median', options=['EMA', 'Median', 'SMA'])
- length1 = input(5)
- mult1 = input.int(1, minval=0, maxval=1)
- method2 = input.string('Median', options=['EMA', 'Median', 'SMA'])
- length2 = input(7)
- mult2 = input.int(1, minval=0, maxval=1)
- method3 = input.string('Median', options=['EMA', 'Median', 'SMA'])
- length3 = input(9)
- mult3 = input.int(1, minval=0, maxval=1)
- //----
- Avg(x, length, method) =>
- sma_1 = ta.sma(x, length)
- ema_1 = ta.ema(x, length)
- percentile_linear_interpolation_1 = ta.percentile_linear_interpolation(x, length, 50)
- method == 'SMA' ? sma_1 : method == 'EMA' ? ema_1 : percentile_linear_interpolation_1
- //----
- a1 = ta.highest(length1) - math.max(close, open)
- b1 = math.min(close, open) - ta.lowest(length1)
- c1 = math.max(close, open) + a1 * mult1
- d1 = math.min(close, open) - b1 * mult1
- a2 = ta.highest(length2) - math.max(close, open)
- b2 = math.min(close, open) - ta.lowest(length2)
- c2 = math.max(close, open) + a2 * mult2
- d2 = math.min(close, open) - b2 * mult2
- a3 = ta.highest(length3) - math.max(close, open)
- b3 = math.min(close, open) - ta.lowest(length3)
- c3 = math.max(close, open) + a3 * mult3
- d3 = math.min(close, open) - b3 * mult3
- //----
- e1 = Avg(c1, length1, method1)
- f1 = Avg(d1, length1, method1)
- g1 = 0
- cross_1 = ta.cross(close, f1)
- g1 := ta.cross(close, e1) ? 1 : cross_1 ? 0 : nz(g1[1])
- e2 = Avg(c2, length2, method2)
- f2 = Avg(d2, length2, method2)
- g2 = 0
- cross_2 = ta.cross(close, f2)
- g2 := ta.cross(close, e2) ? 1 : cross_2 ? 0 : nz(g2[1])
- e3 = Avg(c3, length3, method3)
- f3 = Avg(d3, length3, method3)
- g3 = 0
- cross_3 = ta.cross(close, f3)
- g3 := ta.cross(close, e3) ? 1 : cross_3 ? 0 : nz(g3[1])
- //---
- hilo1 = g1 * f1 + (1 - g1) * e1
- css1 = g1 == 1 ? color.green : color.red
- plot(hilo1, color=css1, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
- hilo2 = g2 * f2 + (1 - g2) * e2
- css2 = g2 == 1 ? color.green : color.red
- plot(hilo2, color=css2, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
- hilo3 = g3 * f3 + (1 - g3) * e3
- css3 = g3 == 1 ? color.green : color.red
- plot(hilo3, color=css3, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
- //end of this part
- wave_height = input(100)
- wave_duration = input(50)
- n = bar_index
- f_cosine_wave(_wave_height, _wave_duration) =>
- _pi = 3.14159265359
- _w = 2 * _pi / _wave_duration
- _cosine_wave = _wave_height * math.sin(_w * n + _pi / 2)
- _cosine_wave
- wave = f_cosine_wave(wave_height, wave_duration)
- wave2 = f_cosine_wave(wave_height, close)
- plot(series=wave, title='Normal', color=color.new(#FFFFFF, 0))
- //plot(series=wave2, title='Price as cycle duration', color=#C9A0DC)
- //end of this part
- //end of this part
- //study(title="[RS]Compounded Risk Score", shorttitle="CRS")
- // if you took a trade for every bars close for the duration of the length
- // how would those trades fair atm?
- // values closer to (100 | -100) are better for its (bull | bear), closer to 0 will be closer to break eaven.
- // this indicator is optimal for trending markets.
- length = input(100)
- avg_length = input(25)
- f_compound_risk(_source, _length) =>
- _total = 0.0
- _absolute = 0.0
- for _i = 1 to _length by 1
- _container0 = _total
- _container1 = _absolute
- _total := _container0 + _source[0] - _source[_i]
- _absolute := _container1 + math.abs(_source[0] - _source[_i])
- _absolute
- if _total > 0
- _container = _total
- _total := _total / _absolute
- _total
- else
- _container = _total
- _total := 0 - math.abs(_container) / _absolute
- _total
- _total * 100
- //inp = input(close)
- cr = f_compound_risk(wave, length)
- ma = ta.ema(cr, avg_length)
- plot(series=cr, color=color.new(color.black, 0))
- plot(series=ma, color=color.new(color.navy, 0))
- hline(100)
- hline(50)
- hline(0)
- hline(-50)
- hline(-100)
- //end of this part
- //@version=5
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © Electrified (electrifiedtrading)
- //indicator(title='Stochastic RSI+', shorttitle='Stoch RSI+', format=format.price, precision=2, timeframe='') // v2
- kcolor = #0094FF
- dcolor = #FF6A00
- WMA = 'WMA'
- EMA = 'EMA'
- SMA = 'SMA'
- VWMA = 'VWMA'
- VAWMA = 'VAWMA'
- ///////////////////////////////////////////////////
- // Input
- k_mode = input.string(SMA, 'K Mode', inline='Source', options=[SMA, EMA, WMA, VWMA, VAWMA])
- src = wave
- smoothK = input.int(3, 'K', inline='Values', minval=1)
- smoothD = input.int(3, 'D', inline='Values', minval=1)
- lengthRSI = input.int(14, 'RSI', group='Lengths', inline='Lengths', minval=1)
- lengthStoch = input.int(14, 'Stochastic', group='Lengths', inline='Lengths', minval=1)
- upperBand = input.int(80, 'Upper', group='Band', minval=50, maxval=100)
- lowerBand = input.int(20, 'Lower', group='Band', maxval=50, minval=0)
- ///////////////////////////////////////////////////
- // Functions
- vawma(src, len) =>
- sum = 0.0
- vol = 0.0
- for m = 1 to len by 1 // m = triangular multiple
- i = len - m
- v = volume[i] * m
- vol += v
- sum += src[i] * v
- sum
- sum / vol
- ////
- getMA(series, mode, len) =>
- mode == WMA ? ta.wma(series, len) : mode == EMA ? ta.ema(series, len) : mode == VWMA ? ta.vwma(series, len) : mode == VAWMA ? vawma(series, len) : ta.sma(series, len)
- ////
- ///////////////////////////////////////////////////
- // Calculation
- rsi1 = ta.rsi(src, lengthRSI)
- stoch = ta.stoch(rsi1, rsi1, rsi1, lengthStoch)
- k = getMA(stoch, k_mode, smoothK)
- d = ta.sma(k, smoothD)
- k_c = ta.change(k)
- d_c = ta.change(d)
- kd = k - d
- ///////////////////////////////////////////////////
- // Visualization
- h0 = hline(upperBand, 'Upper Band', color=#606060)
- hline(50, 'Middle Band', color=#606060)
- h1 = hline(lowerBand, 'Lower Band', color=#606060)
- fill(h0, h1, color=color.new(#9915FF, 95), title='Band Background')
- signalColor = k > lowerBand and d < upperBand and k > d and k_c > 0 and d_c > 0 ? kcolor : k < upperBand and d > lowerBand and k < d and k_c < 0 and d_c < 0 ? dcolor : na
- kp = plot(k, 'K', color=color.new(kcolor, 0))
- dp = plot(d, 'D', color=color.new(dcolor, 0))
- fill(kp, dp, color=color.new(signalColor, 50), title='K-D')
- signalUp = not na(signalColor) and kd > 0
- signalDown = not na(signalColor) and kd < 0
- plot(signalUp ? kd : na, 'Signal Up', color=color.new(kcolor, 0), style=plot.style_columns)
- plot(signalDown ? kd + 100 : na, 'Signal Down', color=color.new(dcolor, 0), style=plot.style_columns, histbase=100)
- ///////////////////////////////////////////////////
- // Alerts
- alertcondition(d < lowerBand, '1: Over-sold', 'Stoch RSI+: Over-sold\nD value below lower band. ({{ticker}} {{interval}})')
- alertcondition(d < lowerBand and k > d, '2: Over-sold & Rising ▲', 'Stoch RSI+ Over-sold & Rising ▲\nK>D and D value below lower band. ({{ticker}} {{interval}})')
- alertcondition(signalUp, '3: Postitive (+) Momentum ▲', 'Stoch RSI+: Postitive (+) Momentum ▲\nK&D rising ▲ within band. ({{ticker}} {{interval}})')
- alertcondition(d > upperBand, '4: Over-bought', 'Stoch RSI+: Over-bought\nD value above upper band. ({{ticker}} {{interval}})')
- alertcondition(d > upperBand and k < d, '5: Over-bought & Falling ▼', 'Stoch RSI+: Over-bought & Falling ▼\nK<D and D value above upper band. ({{ticker}} {{interval}})')
- alertcondition(signalDown, '6: Negative (-) Momentum ▼', 'Stoch RSI+: Negative (-) Momentum ▼\nK&D falling ▼ within band. ({{ticker}} {{interval}})')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement