Gann HiLo Activator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © starbolt
//@version=5
indicator('Gann HiLo Activator', overlay=true)

len = input.int(3, 'Length', step=1, minval=1)
displace = input.int(1, 'Displace', step=1, minval=0)
ma_type = input.string('SMA', 'MA Type', options=['SMA', 'EMA', 'WMA', 'ALMA', 'VWMA', 'HMA', 'LSMA', 'SMMA', 'DEMA'])
alma_offset = input.float(0.85, 'ALMA Offset', step=0.01, minval=0, maxval=1)
alma_sigma = input.float(6, 'ALMA Sigma', step=0.01)
lsma_offset = input.int(0, 'LSMA Offset', step=1)

//Hilo Activator
float hilo = na
hi = ta.sma(high, len)
lo = ta.sma(low, len)

// Exponential Moving Average (EMA)
if ma_type == 'EMA'
    hi := ta.ema(high, len)
    lo := ta.ema(low, len)

// Weighted Moving Average (WMA)
if ma_type == 'WMA'
    hi := ta.wma(high, len)
    lo := ta.wma(low, len)

// Arnaud Legoux Moving Average (ALMA)
if ma_type == 'ALMA'
    hi := ta.alma(high, len, alma_offset, alma_sigma)
    lo := ta.alma(low, len, alma_offset, alma_sigma)

// Hull Moving Average (HMA)
if ma_type == 'HMA'
    hi := ta.wma(2 * ta.wma(high, len / 2) - ta.wma(high, len), math.round(math.sqrt(len)))
    lo := ta.wma(2 * ta.wma(low, len / 2) - ta.wma(low, len), math.round(math.sqrt(len)))

// Volume-weighted Moving Average (VWMA)
if ma_type == 'VWMA'
    hi := ta.vwma(high, len)
    lo := ta.vwma(low, len)

// Least Square Moving Average (LSMA)
if ma_type == 'LSMA'
    hi := ta.linreg(high, len, lsma_offset)
    lo := ta.linreg(low, len, lsma_offset)

// Smoothed Moving Average (SMMA)    
if ma_type == 'SMMA'
    hi := (hi[1] * (len - 1) + high) / len
    lo := (lo[1] * (len - 1) + low) / len

// Double Exponential Moving Average (DEMA)
if ma_type == 'DEMA'
    e1_high = ta.ema(high, len)
    e1_low = ta.ema(low, len)
    hi := 2 * e1_high - ta.ema(e1_high, len)
    lo := 2 * e1_low - ta.ema(e1_low, len)

hilo := close > hi[displace] ? 1 : close < lo[displace] ? -1 : hilo[1]
ghla = hilo == -1 ? hi[displace] : lo[displace]
color = hilo == -1 ? color.red : color.green

//Alerts
buyCondition = hilo == 1 and hilo[1] == -1
sellCondition = hilo == -1 and hilo[1] == 1

if buyCondition
    alert('Long', alert.freq_once_per_bar)

if sellCondition
    alert('Short', alert.freq_once_per_bar)

//Plots 
plot(ghla, color=color, style=plot.style_cross)  

