Advertisement
namile

Untitled

Feb 20th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 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("squzestrategyMY", 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.  
  46. bcolor = iff( val > 0, iff( val > nz(val[1]), color.lime, color.green),iff( val < nz(val[1]), color.red, color.maroon))
  47. scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray
  48. plot(val, color=bcolor, style=plot.style_histogram, linewidth=4)
  49. plot(0, color=scolor, style=plot.style_cross, linewidth=2)
  50.  
  51.  
  52.  
  53. // longCondition = crossover(sma(close, 14), sma(close, 28))and atr(14)[1]<atr(14)[0]
  54. longCondition = crossover(val,0) and atr(14)[1]<atr(14)[0]
  55. shortCondition = val>313 and atr(14)[1]>atr(14)[0]
  56. if (longCondition)
  57. // strategy.close_all()
  58. strategy.entry("My Long Entry Id", strategy.long)
  59. // strategy.entry("My Long Entry Id", strategy.long)
  60. // strategy.entry("My Short Entry Id", strategy.short)
  61. // shortCondition = crossunder(sma(close, 14), sma(close, 28))and atr(14)[1]<atr(14)[0]
  62.  
  63. // alertcondition(longCondition, title="buy alarm", message="BUY signal!!! {{close}}")
  64. // alertcondition(shortCondition, title="sell alarm ", message="SELL signal!!! {{close}}")
  65.  
  66. // plotshape(longCondition, style=shape.labelup,
  67. // location=location.belowbar, color=color.green,size=size.tiny,title="buy label",text="BUY",textcolor=color.white)
  68. // alertcondition(longCondition, title="buy alarm ATMA", message="BUY signal!!! {{close}}")
  69.  
  70. // shortCondition = crossunder(close, wma(close, 20)) and atr(14)[1]<atr(14)
  71. // if (shortCondition)
  72. // plotshape(shortCondition, style=shape.labeldown,
  73. // location=location.abovebar, color=color.red,size=size.tiny,title="sell label",text="SELL",textcolor=color.white)
  74.  
  75. if (shortCondition)
  76. strategy.close_all()
  77. // strategy.entry("My Short Entry Id", strategy.short)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement