Study for Squeeze Momentum Indicator [LazyBear] TradingView Script Strategy

0

 


This study is based on LazyBear Squeeze Momentum Indicator and my strategy developed using it.
I added some custom feature and filters.
Main improvements are:
1- study is updated to version 4 of pine script;
2- I added alerts for entry rules and exit rules.
3- Alert syntax can be customized for webhooks: I added one example only for long entry.

You can customize a lot of features to get a profitable strategy.

Here is a link to original study.

Please use comment section for any feedback.


//@version=4
//Strategy and Study based on LazyBear Squeeze Momentum Indicator
//I added some custom feature and filters
//
// @author LazyBear
// List of all my indicators:
// https://docs.google.com/document/d/15AGCufJZ8CIUvwFJ9W-IKns88gkWOKBCvByMEvm5MLo/edit?usp=sharing
// v2 - fixed a typo, where BB multipler was always stuck at 1.5. [Thanks @ucsgears]
//
study(shorttitle="SQZMOM_LB", title="Study for Squeeze Momentum Indicator [LazyBear]", overlay=true)

length = input(14, title="BB Length")
mult = input(2.0, title="BB MultFactor")
lengthKC = input(16, title="KC Length")
multKC = input(1.5, title="KC MultFactor")

useTrueRange = input(true, title="Use TrueRange (KC)", type=input.bool)

//FILTERS
useExtremeOrders = input(false, title="Early entry on momentum change", type=input.bool)
useMomAverage = input(false, title="Filter for Momenutum value", type=input.bool)
MomentumMin = input(20, title="Min for momentum")

// Calculate BB
src = close
basis = sma(src, length)
dev = mult * stdev(src, length)
upperBB = basis + dev
lowerBB = basis - dev

// Calculate KC
ma = sma(src, lengthKC)
range = useTrueRange ? tr : high - low
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC

sqzOn = lowerBB > lowerKC and upperBB < upperKC
sqzOff = lowerBB < lowerKC and upperBB > upperKC
noSqz = sqzOn == false and sqzOff == false

val = linreg(src - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)), sma(close, lengthKC)), lengthKC, 0)

bcolor = iff(val > 0, iff(val > nz(val[1]), color.lime, color.green), iff(val < nz(val[1]), color.red, color.maroon))
scolor = noSqz ? color.blue : sqzOn ? color.black : color.aqua
//plot(val, color=bcolor, style=histogram, linewidth=4)
//plot(0, color=scolor, style=cross, linewidth=2)

//LOGIC
//momentum filter
filterMom = useMomAverage ? abs(val) > MomentumMin / 100000 ? true : false : true

//standard condition
longCondition = scolor[1] != color.aqua and scolor == color.aqua and bcolor == color.lime and 
   filterMom
exitLongCondition = bcolor == color.green and not useExtremeOrders and bcolor[1]!=color.green
shortCondition = scolor[1] != color.aqua and scolor == color.aqua and bcolor == color.red and 
   filterMom
exitShortCondition = bcolor == color.maroon and not useExtremeOrders and bcolor[1]!=color.maroon

//early entry
extremeLong = useExtremeOrders and scolor == color.aqua and bcolor == color.maroon and 
   bcolor[1] != bcolor[0] and filterMom
exitExtLong = (scolor == color.black or bcolor == color.red) and (scolor[1] != color.black or bcolor[1] != color.red)
extremeShort = useExtremeOrders and scolor == color.aqua and bcolor == color.green and 
   bcolor[1] != bcolor[0] and filterMom
exitExtShort = (scolor == color.black or bcolor == color.lime) and (scolor[1] != color.black or bcolor[1] != color.lime)

//Example of webhooks:
//alert sintax from https://www.tradingconnector.com/alerts-syntax
//long lot=0.1 tradesymbol=ticker

//ALERTS____________________________
alertcondition(longCondition, title='Alert for long', message='long lot=0.1 tradesymbol={{ticker}}')
alertcondition(exitLongCondition, title='Alert for exit long', message='Exit Long!')
alertcondition(shortCondition, title='Alert for short', message='Go Short!')
alertcondition(exitShortCondition, title='Alert for exit short', message='Exit Short!')
//Extreme conditions
alertcondition(extremeLong, title='Alert for extreme long', message='Extreme Long!')  //extreme
alertcondition(exitExtLong, title='Alert for exit extreme long', message='Exit Long!')  //extreme
alertcondition(extremeShort, title='Alert for extreme short', message='Extreme Short!')  //extreme
alertcondition(exitExtShort, title='Alert for exit extreme short', message='Exit Short!')  //extreme
//General alerts
alertcondition(longCondition or shortCondition or extremeLong or extremeShort, title='Alert for enter', message='Check the strategy for long or short!')
alertcondition(exitLongCondition or exitShortCondition or exitExtLong or exitExtShort, title='Alert for exit', message='Check the strategy: is time to exit!')
alertcondition(longCondition or shortCondition or exitLongCondition or exitShortCondition or extremeLong or extremeShort or exitExtLong or exitExtShort, title='General alert', message='Check the strategy!')
//_______________________________________
//PLOT_____________________________________
plotshape(longCondition, title="Long arrow", color=color.green, style=shape.arrowup, location=location.belowbar, text="Long signal")
plotshape(shortCondition, title="Short arrow", color=color.red, style=shape.arrowdown, location=location.abovebar, text="Short signal")
plotshape(exitLongCondition, title="Exit Long arrow", color=color.maroon, style=shape.arrowdown, location=location.belowbar, text="Exit Long signal")
plotshape(exitShortCondition, title="Exit Short arrow", color=color.lime, style=shape.arrowup, location=location.abovebar, text="Exit Short signal")
//extreme  conditions
plotshape(useExtremeOrders ? extremeLong : na, title="Extreme Long arrow", color=color.green, style=shape.arrowup, location=location.belowbar, text="Ext Long signal")
plotshape(useExtremeOrders ? extremeShort : na, title="Extreme Short arrow", color=color.red, style=shape.arrowdown, location=location.abovebar, text="Ext Short signal")
plotshape(useExtremeOrders ? exitExtLong : na, title="Exit ext Long arrow", color=color.maroon, style=shape.arrowdown, location=location.belowbar, text="Exit Ext Long signal")
plotshape(useExtremeOrders ? exitExtShort : na, title="Exit ext Short arrow", color=color.lime, style=shape.arrowup, location=location.abovebar, text="Exit Ext Short signal")

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)

buttons=(Accept !) days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top