Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator("Osmosis [ChartPrime]", precision = 0, explicit_plot_zorder = true, max_labels_count = 500)
- type palette
- color black = #000000
- color blue = #0000FF
- color cyan = #00FCFC
- color green = #00FF00
- color yellow = #FFFF00
- color red = #FF0000
- color very_high = #501414
- color cooked = #330e0e
- color top = #107906
- color bottom = #8e11a7
- int max_top_alpha = 0
- int max_bottom_alpha = 0
- int min_top_alpha = 0
- int min_bottom_alpha = 0
- int fill_alpha_max = 50
- int fill_alpha_min = 50
- alt_source = input.source(close, "Alternate Source", inline = "Source", group = "Source")
- alt_enable = input.bool(false, "", inline = "Source", group = "Source")
- style = input.string(
- "Normalized MACD"
- , "Style"
- , ["MACD Histogram", "Normalized MACD", "Slow MACD", "MACD Percent Rank", "MA Delta", "BB Width", "BB Width Percentile"
- , "Stochastic" , "RSI", "True Range OSC", "Normalized Volume", "Volume Delta", "True Range", "Rate of Change", "OBV"
- , "MFI", "Trend Angle"]
- , group = "Settings")
- len_norm = input.int(90, "Lookback", minval = 1, group = "Settings")
- len_mad = input.int(4, "Delta Length", minval = 1, maxval = 10, group = "Settings")
- half_range = input.bool(false, "Fast Mode", group = "Settings")
- smoothing_length = input.int(2, "Enable Smoothing", minval = 1, maxval = 6, group = "Settings", inline = "Smooth")
- filter = input.bool(false, "", group = "Settings", inline = "Smooth")
- highlight_max = input.bool(true, "Max Region", group = "Max Regions")
- max_threshold = input.float(71, "Max Threshold", minval = 50, maxval = 100, group = "Max Regions")
- max_min_size = input.int(5, "Minimum Max Width", minval = 0, maxval = 30, group = "Max Regions")
- max_color_color = input.color(#107906, "Max Region Color", group = "Max Regions")
- max_top_alpha = input.int(0, "Max Top Line Alpha", minval = 0, maxval = 100, group = "Max Regions")
- max_bottom_alpha = input.int(0, "Max Bottom Line Alpah", minval = 0, maxval = 100, group = "Max Regions")
- max_line_size = input.int(3, "Line Width", minval = 1, maxval = 4, group = "Max Regions")
- max_region_start = input.string("Bottom", "Region Start Indication", ["Both", "Top", "Bottom", "None"], group = "Max Regions")
- fill_max = input.bool(true, "Fill Max", inline = "BC", group = "Max Regions")
- fill_alpha_max = input.int(75, "", inline = "BC", group = "Max Regions")
- highlight_min = input.bool(true, "Minimum Region", group = "Minimum Regions")
- min_threshold = input.float(28, "Minimum Threshold", minval = 0, maxval = 50, group = "Minimum Regions")
- min_min_size = input.int(5, "Minimum Minimum Width", minval = 0, maxval = 30, group = "Minimum Regions")
- min_color = input.color(#8e11a7, "Minimum Region Color", group = "Minimum Regions")
- min_top_alpha = input.int(0, "Minimum Top Line Alpha", minval = 0, maxval = 100, group = "Minimum Regions")
- min_bottom_alpha = input.int(0, "Minimum Bottom Line Alpha", minval = 0, maxval = 100, group = "Minimum Regions")
- min_line_size = input.int(3, "Line Width", minval = 1, maxval = 4, group = "Minimum Regions")
- min_region_start = input.string("Bottom", "Region Start Indication", ["Both", "Top", "Bottom", "None"], group = "Minimum Regions")
- fill_min = input.bool(true, "Fill Minimum", inline = "bc", group = "Minimum Regions")
- fill_alpha_min = input.int(75, "", inline = "bc", group = "Minimum Regions")
- preset_colors = input.string("Prime", "Color Presets", ["User", "Prime", "Standard"], group = "Gradient")
- invert = input.bool(false, "Invert Color Scale", group = "Gradient")
- black = input.color(#000000, "", group = "Gradient", inline = "Grad")
- blue = input.color(#0000FF, "", group = "Gradient", inline = "Grad")
- cyan = input.color(#00FCFC, "", group = "Gradient", inline = "Grad")
- green = input.color(#00FF00, "", group = "Gradient", inline = "Grad")
- yellow = input.color(#FFFF00, "", group = "Gradient", inline = "Grad")
- red = input.color(#FF0000, "", group = "Gradient", inline = "Grad")
- very_high = input.color(#501414, "", group = "Gradient", inline = "Grad")
- cooked = input.color(#330e0e, "", group = "Gradient", inline = "Grad")
- preset = switch preset_colors
- "User" => palette.new(
- black
- , blue
- , cyan
- , green
- , yellow
- , red
- , very_high
- , cooked
- , max_color_color
- , min_color
- , max_top_alpha
- , max_bottom_alpha
- , min_top_alpha
- , min_bottom_alpha
- , fill_alpha_max
- , fill_alpha_min
- )
- "Prime" => palette.new(#00000040, #FF000040, #ff910040, #FFFF0040, #9dff0040, #00a10040, #00580040, #13311340, #00FF00, #FF0000, 100, 0, 100, 0, 75, 75)
- "Standard" => palette.new()
- method find_streak(float[] self, float threshold, bool is_above, int min_count, bool enable) =>
- streak = 0
- int streak_start_index = na
- max_streak = 0
- int max_streak_start_index = na
- int max_streak_end_index = na
- if enable
- i = 0
- while i < array.size(self) - 1
- if max_streak > array.size(self) - 1
- break
- current = array.get(self, i)
- if (is_above and current >= threshold) or (not is_above and current <= threshold)
- streak := 1
- j = i + 1
- while j < array.size(self) - 1 and ((is_above and array.get(self, j) >= threshold) or (not is_above and array.get(self, j) <= threshold))
- streak := streak + 1
- j := j + 1
- if streak > max_streak
- max_streak := streak
- max_streak_start_index := i
- max_streak_end_index := j + 1
- i := j
- else
- i := i + 1
- if max_streak >= min_count
- [max_streak_end_index, max_streak_start_index]
- else
- [na, na]
- grad(src)=>
- source = invert ? 100 - src : src
- var color grad = na
- if source >= 0 and source < 1/7. * 100
- grad := color.from_gradient(source, 0, 1/7. * 100, preset.black, preset.blue)
- else if source >= 1/7. * 100 and source < 2/7. * 100
- grad := color.from_gradient(source, 1/7. * 100, 2/7. * 100, preset.blue, preset.cyan)
- else if source >= 2/7. * 100 and source < 50
- grad := color.from_gradient(source, 2/7. * 100, 50, preset.cyan, preset.green)
- else if source >= 50 and source < 5/7. * 100
- grad := color.from_gradient(source, 50, 5/7. * 100, preset.green, preset.yellow)
- else if source >= 5/7. * 100 and source < 6/7. * 100
- grad := color.from_gradient(source, 5/7. * 100, 6/7. * 100, preset.yellow, preset.red)
- else if source >= 6/7. * 100 and source <= 99
- grad := color.from_gradient(source, 6/7. * 100, 99, preset.red, preset.very_high)
- else if source > 99 and source <= 100
- grad := color.from_gradient(source, 99, 100, preset.very_high, preset.cooked)
- normalize(source, len) =>
- (source - ta.lowest(source, len))/(ta.highest(source, len) - ta.lowest(source, len)) * 100
- diff(float _source, len_mad) =>
- float smooth_diff = 0.0
- if len_mad == 1
- smooth_diff := (_source - _source[1]) / 1
- smooth_diff
- if len_mad == 2
- smooth_diff := (_source - _source[2]) / 2
- smooth_diff
- else if len_mad == 3
- smooth_diff := (_source + _source[1] - _source[2] - _source[3]) / 4
- smooth_diff
- else if len_mad == 4
- smooth_diff := (_source + 2 * _source[1] - 2 * _source[3] - _source[4]) / 8
- smooth_diff
- else if len_mad == 5
- smooth_diff := (_source + 3 * _source[1] + 2 * _source[2] - 2 * _source[3] - 3 * _source[4] - _source[5]) / 16
- smooth_diff
- else if len_mad == 6
- smooth_diff := (_source + 4 * _source[1] + 5 * _source[2] - 5 * _source[4] - 4 * _source[5] - _source[6]) / 32
- smooth_diff
- else if len_mad == 7
- smooth_diff := (_source + 5 * _source[1] + 9 * _source[2] + 5 * _source[3] - 5 * _source[4] - 9 * _source[5] - 5 * _source[6] - _source[7]) / 64
- smooth_diff
- else if len_mad == 8
- smooth_diff := (_source + 6 * _source[1] + 14 * _source[2] + 14 * _source[3] - 14 * _source[5] - 14 * _source[6] - 6 * _source[7] - _source[8]) / 128
- smooth_diff
- else if len_mad == 9
- smooth_diff := (_source + 7 * _source[1] + 20 * _source[2] + 28 * _source[3] + 14 * _source[4] - 14 * _source[5] - 28 * _source[6] - 20 * _source[7] - 7 * _source[8] - _source[9]) / 256
- smooth_diff
- else if len_mad == 10
- smooth_diff := (_source + 8 * _source[1] + 27 * _source[2] + 48 * _source[3] + 42 * _source[4] - 42 * _source[6] - 48 * _source[7] - 27 * _source[8] - 8 * _source[9] - _source[10]) / 512
- smooth_diff
- smooth_diff
- ema(float source = close, float length = 9)=>
- alpha = 2 / (length + 1)
- var float smoothed = na
- smoothed := alpha * source + (1 - alpha) * nz(smoothed[1])
- stdev(x, n)=>
- out = math.sqrt(math.sum(math.pow(x - ta.ema(x, n), 2), n) * 0.5) * 0.5
- out
- cwma(float source, int length)=>
- sum = 0.
- weights = 0
- even = length * 2
- for i = 0 to even - 1
- j = i + 1
- k = even - j + 1
- w = (j <= even / 2 ? j : k)
- sum += source[i] * w
- weights += w
- sum / weights
- filter(src, filter)=>
- filter ? cwma(src, smoothing_length) : src
- rsi(source, len) =>
- rsi = ta.rsi(source, len)
- f = -math.pow(math.abs(math.abs(rsi - 50) - 50), 1 + math.pow(len / 14, 0.618) - 1) / math.pow(50, math.pow(len / 14, 0.618) - 1) + 50
- rsia = if rsi > 50
- f + 50
- else
- -f + 50
- rsia
- average_true_range(source, length)=>
- true_range = high - low
- _range = math.abs(open - close)
- a_range = (true_range * 2 + _range)/3
- average_true_range = ta.rma(a_range, length)
- tr_score(source, length)=>
- mean = ta.sma(source, length)
- tr = average_true_range(source, length)
- z_score = (source - mean)/tr
- max(source, outlier_level, dev_lookback)=>
- var float mx = na
- src = array.new<float>()
- stdev = math.abs((source - ta.ema(source, dev_lookback))/ta.stdev(source, dev_lookback))
- array.push(src, stdev < outlier_level ? source : -1.7976931348623157e+308)
- mx := math.max(nz(mx[1]), array.get(src, 0))
- min(source, outlier_level, dev_lookback) =>
- var float min = na
- src = array.new<float>()
- stdev = math.abs((source - ta.ema(source, dev_lookback))/ta.stdev(source, dev_lookback))
- array.push(src, stdev < outlier_level ? source : 1.7976931348623157e+308)
- min := math.min(nz(min[1]), array.get(src, 0))
- min_max(src, outlier_level, dev_lookback) =>
- out = (src - min(src, outlier_level, dev_lookback))/(max(src, outlier_level, dev_lookback) - min(src, outlier_level, dev_lookback)) * 100
- math.max(math.min(100, out), 0)
- tr_osc(source, length, smooth)=>
- true_rance_osc = min_max(ta.sma(tr_score(source, length), smooth), 1, length)
- trend_angle(src, length)=>
- atr = ta.atr(length)
- slope = (src - src[length]) / atr
- angle_rad = math.atan(slope)
- degrees = filter((math.todegrees(angle_rad) + 90) / 180 * 100, filter)
- half(n)=>
- half_range ? math.max(1, int(n/2)) : n
- indicator_picker(n)=>
- src = filter(alt_enable ? alt_source : close, filter)
- alt_high = filter(alt_enable ? alt_source : high, filter)
- alt_low = filter(alt_enable ? alt_source : low, filter)
- ret = style == "Normalized MACD" ? (n == 1 ? normalize(ta.ema(src, half(3)) - ta.ema(src, half(5)), len_norm) : normalize(ta.ema(src, half(5)) - ta.ema(src, 1 + (half(6) * n)), len_norm)) :
- style == "MACD Histogram" ? normalize((ema(src, half(2) * n * 0.5 + 2) - ema(src, half(4) * n * 0.5 + 2)) - ema(ema(src, half(2) * n * 0.5 + 2) - ema(src, half(4) * n * 0.5 + 2), 9), len_norm) :
- style == "MACD Percent Rank" ? ta.percentrank(ta.ema(src, half(5)) - ta.ema(src, 1 + (half(6) * n)) , len_norm) :
- style == "Slow MACD" ? normalize(ta.ema(src, half(15)) - ta.ema(src, half(20) + n * half(5)), len_norm) :
- style == "RSI" ? rsi(filter(src, true), half(2) * n) :
- style == "True Range OSC" ? tr_osc(src, half(2) * n, 3) :
- style == "Normalized Volume" ? normalize(filter(ta.wma(volume, 1 + (half(3) * (n - 1))), filter), len_norm) :
- style == "Volume Delta" ? normalize(filter(diff(ta.wma(volume, 1 + (half(3) * (n - 1))), len_mad), filter), len_norm) :
- style == "MA Delta" ? normalize(diff(ta.ema(src, half(6) * n), len_mad), len_norm) :
- style == "True Range" ? normalize(ta.rma(high - low, half(2) * n), len_norm) :
- style == "Rate of Change" ? normalize(ta.roc(src, n * half(3)), len_norm) :
- style == "OBV" ? normalize(filter(ta.obv - ta.wma(ta.obv, 2 + half(2) * n), filter), len_norm) :
- style == "MFI" ? normalize(ta.mfi(filter(hlc3, filter), half(3) + n), len_norm) :
- style == "BB Width" ? normalize(((ta.sma(src, 5 + n * half(5)) + ta.stdev(src, 5 + n * half(5))) - (ta.sma(src, 5 + n * half(5)) - ta.stdev(src, 5 + n * half(5))))/ta.sma(src, 5 + n * half(5)), len_norm) :
- style == "BB Width Percentile" ? ta.percentrank(((ta.sma(src, 5 + n * half(5)) + ta.stdev(src, 5 + n * half(5))) - (ta.sma(src, 5 + n * half(5)) - ta.stdev(src, 5 + n * half(5))))/ta.sma(src, 5 + n * half(5)), len_norm) :
- style == "Stochastic" ? ta.sma(ta.stoch(src, alt_high, alt_low, half(2) * n), 3) :
- style == "Trend Angle" ? trend_angle(close, half(2) * n) :
- na
- heatmap(src)=>
- heatmap = grad(src)
- // heatmap_1 = heatmap(1)
- indi_2 = indicator_picker(2)
- indi_3 = indicator_picker(3)
- indi_4 = indicator_picker(4)
- indi_5 = indicator_picker(5)
- indi_6 = indicator_picker(6)
- indi_7 = indicator_picker(7)
- indi_8 = indicator_picker(8)
- indi_9 = indicator_picker(9)
- indi_10 = indicator_picker(10)
- indi_11 = indicator_picker(11)
- indi_12 = indicator_picker(12)
- indi_13 = indicator_picker(13)
- indi_14 = indicator_picker(14)
- indi_15 = indicator_picker(15)
- indi_16 = indicator_picker(16)
- indi_17 = indicator_picker(17)
- indi_18 = indicator_picker(18)
- indi_19 = indicator_picker(19)
- indi_20 = indicator_picker(20)
- indi_21 = indicator_picker(21)
- indi_22 = indicator_picker(22)
- indi_23 = indicator_picker(23)
- indi_24 = indicator_picker(24)
- indi_25 = indicator_picker(25)
- indi_26 = indicator_picker(26)
- indi_27 = indicator_picker(27)
- indi_array = array.from(
- indi_2
- , indi_3
- , indi_4
- , indi_5
- , indi_6
- , indi_7
- , indi_8
- , indi_9
- , indi_10
- , indi_11
- , indi_12
- , indi_13
- , indi_14
- , indi_15
- , indi_16
- , indi_17
- , indi_18
- , indi_19
- , indi_20
- , indi_21
- , indi_22
- , indi_23
- , indi_24
- , indi_25
- , indi_26
- , indi_27)
- [max_top, max_bottom] = indi_array.find_streak(max_threshold, true, max_min_size, highlight_max)
- [min_top, min_bottom] = indi_array.find_streak(min_threshold, false, min_min_size, highlight_min)
- heatmap_2 = grad(indi_2 )
- heatmap_3 = grad(indi_3 )
- heatmap_4 = grad(indi_4 )
- heatmap_5 = grad(indi_5 )
- heatmap_6 = grad(indi_6 )
- heatmap_7 = grad(indi_7 )
- heatmap_8 = grad(indi_8 )
- heatmap_9 = grad(indi_9 )
- heatmap_10 = grad(indi_10)
- heatmap_11 = grad(indi_11)
- heatmap_12 = grad(indi_12)
- heatmap_13 = grad(indi_13)
- heatmap_14 = grad(indi_14)
- heatmap_15 = grad(indi_15)
- heatmap_16 = grad(indi_16)
- heatmap_17 = grad(indi_17)
- heatmap_18 = grad(indi_18)
- heatmap_19 = grad(indi_19)
- heatmap_20 = grad(indi_20)
- heatmap_21 = grad(indi_21)
- heatmap_22 = grad(indi_22)
- heatmap_23 = grad(indi_23)
- heatmap_24 = grad(indi_24)
- heatmap_25 = grad(indi_25)
- heatmap_26 = grad(indi_26)
- heatmap_27 = grad(indi_27)
- plot(1 , 'MA-2' , heatmap_2, style = plot.style_area, histbase = 0 , editable = false, display = display.pane)
- plot(2 , 'MA-4' , heatmap_3, style = plot.style_area, histbase = 1 , editable = false, display = display.pane)
- plot(3 , 'MA-6' , heatmap_4, style = plot.style_area, histbase = 2 , editable = false, display = display.pane)
- plot(4 , 'MA-8' , heatmap_5, style = plot.style_area, histbase = 3 , editable = false, display = display.pane)
- plot(5 , 'MA-10', heatmap_6, style = plot.style_area, histbase = 4 , editable = false, display = display.pane)
- plot(6 , 'MA-12', heatmap_7, style = plot.style_area, histbase = 5 , editable = false, display = display.pane)
- plot(7 , 'MA-14', heatmap_8, style = plot.style_area, histbase = 6 , editable = false, display = display.pane)
- plot(8 , 'MA-16', heatmap_9, style = plot.style_area, histbase = 7 , editable = false, display = display.pane)
- plot(9 , 'MA-18', heatmap_10, style = plot.style_area, histbase = 8 , editable = false, display = display.pane)
- plot(10, 'MA-20', heatmap_11, style = plot.style_area, histbase = 9 , editable = false, display = display.pane)
- plot(11, 'MA-22', heatmap_12, style = plot.style_area, histbase = 10, editable = false, display = display.pane)
- plot(12, 'MA-24', heatmap_13, style = plot.style_area, histbase = 11, editable = false, display = display.pane)
- plot(13, 'MA-26', heatmap_14, style = plot.style_area, histbase = 12, editable = false, display = display.pane)
- plot(14, 'MA-28', heatmap_15, style = plot.style_area, histbase = 13, editable = false, display = display.pane)
- plot(15, 'MA-30', heatmap_16, style = plot.style_area, histbase = 14, editable = false, display = display.pane)
- plot(16, 'MA-32', heatmap_17, style = plot.style_area, histbase = 15, editable = false, display = display.pane)
- plot(17, 'MA-34', heatmap_18, style = plot.style_area, histbase = 16, editable = false, display = display.pane)
- plot(18, 'MA-36', heatmap_19, style = plot.style_area, histbase = 17, editable = false, display = display.pane)
- plot(19, 'MA-38', heatmap_20, style = plot.style_area, histbase = 18, editable = false, display = display.pane)
- plot(20, 'MA-40', heatmap_21, style = plot.style_area, histbase = 19, editable = false, display = display.pane)
- plot(21, 'MA-40', heatmap_22, style = plot.style_area, histbase = 20, editable = false, display = display.pane)
- plot(22, 'MA-40', heatmap_23, style = plot.style_area, histbase = 21, editable = false, display = display.pane)
- plot(23, 'MA-40', heatmap_24, style = plot.style_area, histbase = 22, editable = false, display = display.pane)
- plot(24, 'MA-40', heatmap_25, style = plot.style_area, histbase = 23, editable = false, display = display.pane)
- plot(25, 'MA-40', heatmap_26, style = plot.style_area, histbase = 24, editable = false, display = display.pane)
- plot(26, 'MA-40', heatmap_27, style = plot.style_area, histbase = 25, editable = false, display = display.pane)
- alpha = color.new(color.black, 100)
- bullish_top = plot(max_top, "Bullish Region Top", color.new(preset.top, preset.max_top_alpha), max_line_size, plot.style_linebr, display = display.pane)
- bullish_bottom = plot(max_bottom, "Bullish Region Bottom", color.new(preset.top, preset.max_bottom_alpha), max_line_size, plot.style_linebr, display = display.pane)
- bearish_top = plot(min_top, "Bearish Region Top", color.new(preset.bottom, preset.min_top_alpha), min_line_size, plot.style_linebr, display = display.pane)
- bearish_bottom = plot(min_bottom, "Bearish Region Bottom", color.new(preset.bottom, preset.min_bottom_alpha), min_line_size, plot.style_linebr, display = display.pane)
- fill(bullish_top, bullish_bottom, fill_max ? color.new(preset.top, preset.fill_alpha_max) : alpha, "Bullish Region Fill")
- fill(bearish_top, bearish_bottom, fill_min ? color.new(preset.bottom, preset.fill_alpha_min) : alpha, "Bearish Region Fill")
- if not na(max_bottom) and na(max_bottom[1])
- if max_region_start == "Top" or max_region_start == "Both"
- label.new(bar_index, max_top, "⬤", style = label.style_text_outline, textcolor = preset.top, color = alpha, size = size.normal)
- if max_region_start == "Bottom" or max_region_start == "Both"
- label.new(bar_index, max_bottom, "⬤", style = label.style_text_outline, textcolor = preset.top, color = alpha, size = size.normal)
- if not na(min_bottom) and na(min_bottom[1])
- if min_region_start == "Top" or min_region_start == "Both"
- label.new(bar_index, min_top, "⬤", style = label.style_text_outline, textcolor = preset.bottom, color = alpha, size = size.normal)
- if min_region_start == "Bottom" or min_region_start == "Both"
- label.new(bar_index, min_bottom, "⬤", style = label.style_text_outline, textcolor = preset.bottom, color = alpha, size = size.normal)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement