HODL LINE [AstrideUnicorn]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AstrideUnicorn

// Asymmetrical Trend Filter aka HODL Line

//@version=5
indicator("HODL LINE", overlay=true)

// initialize indicator period parameter and the asymmetry paramter
length = 300
asymmetry =  0.05 //input.float(defval=0.05,step=0.01, minval=0.01, maxval=0.3)

// script inputs
sensitivity = input.string(defval="Hold Medium Term", title="Sensitivity", options=['Super Sensitive','Hold Short Term', 'Hold Medium Term', 'Hold Long Term'])
use_smoothing = input.bool(defval=false, title="Use Smoothing")


// Set the indicator period based on the choosen sensitivity 
if sensitivity == 'Super Sensitive'
    length:=50

if sensitivity == 'Hold Short Term'
    length:=100

if sensitivity == 'Hold Medium Term'
    length:=300
    
if sensitivity == 'Hold Long Term'
    length:=500    

// Calculate HODL Line - an assymetric trend filter
HODL_line = (ta.highest(close,length) + ta.lowest(close,length))/(2.0 + asymmetry)

// Calculate smoothed price time series
smoothed_price = ta.hma(close,50)

// Use closing price or smoothed price based on the choosen option for smoothing
price_model = use_smoothing ? smoothed_price : close

// Define conditional color for the HODL Line
hodl_line_color = price_model >= HODL_line ? color.green : color.red

// define the HODL Line crossing conditions
crossing_condition_bull = ta.crossover(price_model, HODL_line)
crossing_condition_bear = ta.crossunder(price_model, HODL_line)

// plotting
plot(HODL_line, color = hodl_line_color, linewidth = 2)

plot(crossing_condition_bull?HODL_line:na, color = color.new(color.green,40), style= plot.style_circles, linewidth = 20)
plot(crossing_condition_bear?HODL_line:na, color = color.new(color.red,40), style= plot.style_circles, linewidth = 20)

bgcolor(color.new(hodl_line_color,80))

plot(use_smoothing?price_model:na, color=color.purple, linewidth=2)
