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("squzestrategyMYLONG", 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)
- // val:=1000*val
- 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)
- ///// Backtest Start Date /////
- startDate = input(title="Start Date", type=input.integer, defval=2, minval=1, maxval=31)
- startMonth = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12)
- startYear = input(title="Start Year", type=input.integer, defval=2019, minval=1800, maxval=2100)
- startDateEnd = input(title="Start Date", type=input.integer, defval=25, minval=1, maxval=31)
- startMonthEnd = input(title="Start Month", type=input.integer, defval=11, minval=1, maxval=12)
- startYearEnd = input(title="Start Year", type=input.integer, defval=2021, minval=1800, maxval=2100)
- afterStartDate = (time <= timestamp(syminfo.timezone, startYearEnd, startMonthEnd, startDateEnd, 0, 0) and time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))
- // slope
- rad2degree=180/3.14159265359 //pi
- iSMA = input(defval=50,title="Period SMA",type=input.integer)
- iBarsBack=input(defval=1,title="Bars Back",type=input.integer)
- // hline(7000)
- sma2sample=sma(close,iSMA)
- // slopeD=ema(rad2degree*atan(((wma(close, 20)[0]*21-21*nz(wma(close, 20)[iBarsBack]))*1)/1),5)
- slopeD=rad2degree*atan(((wma(close, 20)[0]*0.1-0.1*nz(wma(close, 20)[iBarsBack]))*1)/1)
- slopeD200=rad2degree*atan(((wma(hlc3, 200)[0]*1-1*nz(wma(hlc3, 200)[iBarsBack]))*1)/1)
- // longCondition = crossover(sma(close, 14), sma(close, 28))and atr(14)[1]<atr(14)[0] val[1]<val[0]and
- longCondition = val[1]<val[0] and afterStartDate and atr(14)[1]<atr(14)[0] and slopeD200>30
- shortCondition = val>378 and afterStartDate 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)
- if (shortCondition)
- strategy.close_all()
- // 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)
Advertisement
Add Comment
Please, Sign In to add comment