LazyBear’s Squeeze Momentum command script extended.
It now provides input parameters for source and indicator settings. The returned value is an array of SQZMOM values instead of a signal.
Usage:
local close = ClosePrices()
local sqzmom = CC_SQZMOM_LB_Ext(close, 20, 2, 20, 1.5, SmaType, EmaType, EmaType)
PlotHistogram(Plot(1, 'SQZMOM', sqzmom, Green), Red)
This topic was modified 3 months, 2 weeks ago by pshai . Reason: Extended even further, because i can
HaasScript Code
-- Author LazyBear
-- https://www.tradingview.com/script/nqQ1DT5a-Squeeze-Momentum-Indicator-LazyBear/
-- Define command
DefineCommand('SQZMOM_LB_Ext', 'Squeeze Momentum Indicator - LazyBear')
-- Input parameters for the indicator
local prices = DefineParameter(ListNumberType, 'source', 'Source prices for calculations', true, ClosePrices(), 'Price Data')
local length = DefineParameter(NumberType, 'length', 'BB Lenght', true, 20, 'Input, Number')
local mult = DefineParameter(NumberType, 'mult', 'BB MultFactor', true, 2.0, 'Input, Number')
local lengthKC = DefineParameter(NumberType, 'length_kc', 'KC Length', true, 20, 'Input, Number')
local multKC = DefineParameter(NumberType, 'mult_kc', 'KC MultFactor', true, 1.5, 'Input, Number')
local ma_type = DefineParameter(EnumType, 'ma_type', 'BB Moving Average Type', false, SmaType, 'InputMaTypes, Enumerations Moving Averages')
local ma_type_kc = DefineParameter(EnumType, 'ma_type_kc', 'KC Moving Average Type', false, EmaType, 'InputMaTypes, Enumerations Moving Averages')
local ma_type_r = DefineParameter(EnumType, 'ma_type_r', 'Range Moving Average Type', false, EmaType, 'InputMaTypes, Enumerations Moving Averages')
-- Calculate BB
local source = prices
local basis = MA(source, length, ma_type)
local dev = mult * STDDEV(source, length, 1)
local upperBB = basis + dev
local lowerBB = basis - dev
-- Calculate KC
local ma = MA(source, lengthKC, ma_type_kc)
local range = (HighPrices() - LowPrices())
local rangema = MA(range, lengthKC, ma_type_r)
local upperKC = ma + rangema * multKC
local lowerKC = ma - rangema * multKC
local sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
local sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
local noSqz = (sqzOn == false) and (sqzOff == false)
local sqzmom = LINEARREG(source - Average(Average(GetHigh(HighPrices(), lengthKC), GetLow(LowPrices(), lengthKC)), SMA(prices,lengthKC)),
lengthKC)
--Return the custom signal.
DefineOutput(ListNumberType, sqzmom, 'SQZMOM values', ', Signal Helpers, Plot')
Copy to Clipboard