Kalman Trend Levels [BigBeluga]
Kalman Trend Levels [BigBeluga]
//@version=5
indicator("Kalman Trend Levels [BigBeluga]", overlay = true, max_labels_count =
500, max_boxes_count = 500)
// INPUTS
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
――――――――――――――――――――――{
int short_len = input.int(50)
int long_len = input.int(150)
bool retest_sig = input.bool(false, "Retest Signals")
bool candle_color = input.bool(true, "Candle Color")
// }
// CALCULATION
S――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
――――――――――――{
float atr = ta.atr(200) *0.5
// Prediction step
prediction := estimate
estimate
float short_kalman = kalman_filter(close, short_len)
float long_kalman = kalman_filter(close, long_len)
// }
// PLOT
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
――――――――――――――――――――――――――{
if trend_up and not trend_up[1]
label.new(bar_index, short_kalman, "🡹\n" + str.tostring(math.round(close,1)),
color = color(na), textcolor = upper_col, style = label.style_label_up, size =
size.normal)
lower_box := box.new(bar_index, low+atr, bar_index, low, border_color = na,
bgcolor = color.new(upper_col, 60))
if not ta.change(trend_up)
lower_box.set_right(bar_index)
if not ta.change(trend_up)
upper_box.set_right(bar_index)
if retest_sig
if high < upper_box.get_bottom() and high[1]>= upper_box.get_bottom() //or high
< lower_box.get_bottom() and high[1]>= lower_box.get_bottom()
label.new(bar_index-1, high[1], "x", color = color(na), textcolor =
lower_col, style = label.style_label_down, size = size.normal)