Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © yereter
- //@version=4
- strategy("squzestrategyMY", overlay=false,pyramiding=100, default_qty_type=strategy.percent_of_equity ,default_qty_value=10)
- // strategy("My Strategy Squeeze Momentum Indicator", overlay=false,pyramiding=10)
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © yereter
- //@version=4
- //
- // @author LazyBear
- // List of all my indicators: https://www.tradingview.com/v/4IneGo8h/
- //
- // study(shorttitle = "SQZMOM_LB", title="Squeeze Momentum Indicator [LazyBear]", overlay=true)
- // strategy("My Strategy Squeeze Momentum Indicator", overlay=false,pyramiding=10)
- length = input(20, title="BB Length")
- mult = input(2.0,title="BB MultFactor")
- lengthKC=input(20, title="KC Length")
- multKC = input(1.5, title="KC MultFactor")
- useTrueRange = input(true, title="Use TrueRange (KC)", type=input.bool)
- // Calculate BB
- source = close
- basis = sma(source, length)
- dev = multKC * stdev(source, length)
- upperBB = basis + dev
- lowerBB = basis - dev
- // Calculate KC
- ma = sma(source, 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(source - 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.gray
- plot(val, color=bcolor, style=plot.style_histogram, linewidth=4)
- plot(0, color=scolor, style=plot.style_cross, linewidth=2)
- // longCondition = crossover(sma(close, 14), sma(close, 28))and atr(14)[1]<atr(14)[0]
- longCondition = crossover(val,0) and atr(14)[1]<atr(14)[0]
- shortCondition = val>313 and atr(14)[1]>atr(14)[0]
- if (longCondition)
- // strategy.close_all()
- strategy.entry("My Long Entry Id", strategy.long)
- // strategy.entry("My Long Entry Id", strategy.long)
- // strategy.entry("My Short Entry Id", strategy.short)
- // shortCondition = crossunder(sma(close, 14), sma(close, 28))and atr(14)[1]<atr(14)[0]
- // alertcondition(longCondition, title="buy alarm", message="BUY signal!!! {{close}}")
- // alertcondition(shortCondition, title="sell alarm ", message="SELL signal!!! {{close}}")
- // plotshape(longCondition, style=shape.labelup,
- // location=location.belowbar, color=color.green,size=size.tiny,title="buy label",text="BUY",textcolor=color.white)
- // alertcondition(longCondition, title="buy alarm ATMA", message="BUY signal!!! {{close}}")
- // shortCondition = crossunder(close, wma(close, 20)) and atr(14)[1]<atr(14)
- // if (shortCondition)
- // plotshape(shortCondition, style=shape.labeldown,
- // location=location.abovebar, color=color.red,size=size.tiny,title="sell label",text="SELL",textcolor=color.white)
- if (shortCondition)
- strategy.close_all()
- // strategy.entry("My Short Entry Id", strategy.short)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement