namile

Untitled

Mar 10th, 2020
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © yereter
  3.  
  4. //@version=4
  5. strategy("squzestrategyMYLONG", overlay=false,pyramiding=100, default_qty_type=strategy.percent_of_equity ,default_qty_value=10)
  6. // strategy("My Strategy Squeeze Momentum Indicator", overlay=false,pyramiding=10)
  7. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  8. // © yereter
  9.  
  10. //@version=4
  11.  
  12. //
  13. // @author LazyBear
  14. // List of all my indicators: https://www.tradingview.com/v/4IneGo8h/
  15. //
  16. // study(shorttitle = "SQZMOM_LB", title="Squeeze Momentum Indicator [LazyBear]", overlay=true)
  17. // strategy("My Strategy Squeeze Momentum Indicator", overlay=false,pyramiding=10)
  18.  
  19. length = input(20, title="BB Length")
  20. mult = input(2.0,title="BB MultFactor")
  21. lengthKC=input(20, title="KC Length")
  22. multKC = input(1.5, title="KC MultFactor")
  23.  
  24. useTrueRange = input(true, title="Use TrueRange (KC)", type=input.bool)
  25.  
  26. // Calculate BB
  27. source = close
  28. basis = sma(source, length)
  29. dev = multKC * stdev(source, length)
  30. upperBB = basis + dev
  31. lowerBB = basis - dev
  32.  
  33. // Calculate KC
  34. ma = sma(source, lengthKC)
  35. range = useTrueRange ? tr : (high - low)
  36. rangema = sma(range, lengthKC)
  37. upperKC = ma + rangema * multKC
  38. lowerKC = ma - rangema * multKC
  39.  
  40. sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
  41. sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
  42. noSqz = (sqzOn == false) and (sqzOff == false)
  43.  
  44. val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), lengthKC,0)
  45. // val:=1000*val
  46.  
  47. bcolor = iff( val > 0, iff( val > nz(val[1]), color.lime, color.green),iff( val < nz(val[1]), color.red, color.maroon))
  48. scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray
  49. plot(val, color=bcolor, style=plot.style_histogram, linewidth=4)
  50. plot(0, color=scolor, style=plot.style_cross, linewidth=2)
  51. ///// Backtest Start Date /////
  52. startDate = input(title="Start Date", type=input.integer, defval=2, minval=1, maxval=31)
  53. startMonth = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12)
  54. startYear = input(title="Start Year", type=input.integer, defval=2019, minval=1800, maxval=2100)
  55.  
  56. startDateEnd = input(title="Start Date", type=input.integer, defval=25, minval=1, maxval=31)
  57. startMonthEnd = input(title="Start Month", type=input.integer, defval=11, minval=1, maxval=12)
  58. startYearEnd = input(title="Start Year", type=input.integer, defval=2021, minval=1800, maxval=2100)
  59. afterStartDate = (time <= timestamp(syminfo.timezone, startYearEnd, startMonthEnd, startDateEnd, 0, 0) and time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))
  60.  
  61. // slope
  62. rad2degree=180/3.14159265359 //pi
  63. iSMA = input(defval=50,title="Period SMA",type=input.integer)
  64. iBarsBack=input(defval=1,title="Bars Back",type=input.integer)
  65. // hline(7000)
  66. sma2sample=sma(close,iSMA)
  67. // slopeD=ema(rad2degree*atan(((wma(close, 20)[0]*21-21*nz(wma(close, 20)[iBarsBack]))*1)/1),5)
  68. slopeD=rad2degree*atan(((wma(close, 20)[0]*0.1-0.1*nz(wma(close, 20)[iBarsBack]))*1)/1)
  69. slopeD200=rad2degree*atan(((wma(hlc3, 200)[0]*1-1*nz(wma(hlc3, 200)[iBarsBack]))*1)/1)
  70.  
  71. // longCondition = crossover(sma(close, 14), sma(close, 28))and atr(14)[1]<atr(14)[0] val[1]<val[0]and
  72. longCondition = val[1]<val[0] and afterStartDate and atr(14)[1]<atr(14)[0] and slopeD200>30
  73. shortCondition = val>378 and afterStartDate and atr(14)[1]<atr(14)[0]
  74. if (longCondition)
  75. // strategy.close_all()
  76. strategy.entry("My Long Entry Id", strategy.long)
  77. // strategy.entry("My Long Entry Id", strategy.long)
  78. // strategy.entry("My Short Entry Id", strategy.short)
  79.  
  80. if (shortCondition)
  81. strategy.close_all()
  82. // strategy.entry("My Short Entry Id", strategy.short)
  83. // shortCondition = crossunder(sma(close, 14), sma(close, 28))and atr(14)[1]<atr(14)[0]
  84.  
  85. // alertcondition(longCondition, title="buy alarm", message="BUY signal!!! {{close}}")
  86. // alertcondition(shortCondition, title="sell alarm ", message="SELL signal!!! {{close}}")
  87.  
  88. // plotshape(longCondition, style=shape.labelup,
  89. // location=location.belowbar, color=color.green,size=size.tiny,title="buy label",text="BUY",textcolor=color.white)
  90. // alertcondition(longCondition, title="buy alarm ATMA", message="BUY signal!!! {{close}}")
  91.  
  92. // shortCondition = crossunder(close, wma(close, 20)) and atr(14)[1]<atr(14)
  93. // if (shortCondition)
  94. // plotshape(shortCondition, style=shape.labeldown,
  95. // 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