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(161)
- wave_duration_bigwave = input(217)
- 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
- f_cosine_wave2(_wave_height, _wave_duration_bigwave) =>
- _pi = 3.14159265359
- _w2 = 2 * _pi / _wave_duration_bigwave
- _cosine_wave2 = _wave_height * math.sin(_w2 * n + _pi / 2)
- _cosine_wave2
- wave = f_cosine_wave(wave_height, wave_duration)
- //wave2 = f_cosine_wave(wave_height, close)
- big_wave = f_cosine_wave2(wave_height, wave_duration_bigwave)
- plot(series=wave, title='Normal', color=color.new(#FFFFFF, 0))
- plot(series=big_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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement