SHARE
TWEET

Insync Index With BB [LazyBear]

lazybeartv May 3rd, 2015 660 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // @author LazyBear
  3. //
  4. // List of my public indicators: http://bit.ly/1LQaPK8
  5. // List of my app-store indicators: http://blog.tradingview.com/?p=970
  6. //
  7. //
  8. study(title = "Insync Index With BB [LazyBear]", shorttitle="IIBB_LB")
  9. src=close
  10. div = input(10000, title="EMO Divisor", minval=1)
  11. emoLength = input(14, minval=1, title="EMO length")
  12. fastLength = input(12, minval=1, title="MACD Fast EMA Length")
  13. slowLength=input(26,minval=1, title="MACD Slow EMA Length")
  14. signalLength=input(9,minval=1, title="MACD Signal Length")
  15. mfiLength = input(20, minval=1, title="MFI Length")
  16.  
  17. calc_emo() => sma(div * change(hl2) * (high - low) / volume, emoLength)
  18. calc_macd(source) =>
  19.     fastMA = ema(source, fastLength)
  20.     slowMA = ema(source, slowLength)
  21.     fastMA - slowMA
  22.  
  23. calc_mfi(length) =>
  24.     src = hlc3
  25.     upper = sum(volume * (change(src) <= 0 ? 0 : src), length)
  26.     lower = sum(volume * (change(src) >= 0 ? 0 : src), length)
  27.     mf = rsi(upper, lower)
  28.     mf
  29.  
  30. calc_dpo(period_) =>  
  31.     isCentered = false
  32.     barsback = period_/2 + 1
  33.     ma = sma(close, period_)
  34.     dpo = isCentered ? close[barsback] - ma : close - ma[barsback]
  35.     dpo
  36.  
  37. calc_roc(source, length) =>
  38.     roc = 100 * (source - source[length])/source[length]
  39.     roc
  40.  
  41. calc_stochD(length, smoothD, smoothK) =>
  42.     k = sma(stoch(close, high, low, length), smoothK)
  43.     d = sma(k, smoothD)
  44.     d
  45.  
  46. calc_stochK(length, smoothD, smoothK) =>
  47.     k = sma(stoch(close, high, low, length), smoothK)
  48.     //d = sma(k, smoothD)
  49.     k
  50.  
  51. lengthBB=input(20, title="BB Length"), multBB=input(2.0, title="BB Multiplier")    
  52. lengthCCI=input(14, title="CCI Length")
  53. dpoLength=input(18, title="DPO Length")
  54. lengthROC=input(10, title="ROC Length")
  55. lengthRSI=input(14, title="RSI Length")
  56. lengthStoch=input(14, title="Stoch Length"),lengthD=input(3, title="Stoch D Length"), lengthK=input(1, title="Stoch K Length")
  57. lengthSMA=input(10, title="MA Length")
  58.  
  59. bolinslb=sma( src,lengthBB ) - multBB * ( stdev( src,lengthBB ) )
  60. bolinsub=sma( src,lengthBB ) + multBB * ( stdev( src,lengthBB ) )
  61. bolins2= (src- bolinslb ) / ( bolinsub - bolinslb )
  62. bolinsll=( bolins2 < 0.05 ? -5 : ( bolins2 > 0.95 ? 5 : 0 ) )
  63. cciins= ( cci(src, lengthCCI) > 100 ? 5 :  ( cci(src, lengthCCI ) < -100 ? -5 : 0 ) )
  64. emvins2= calc_emo() - sma( calc_emo(),lengthSMA)
  65. emvinsb= ( emvins2 < 0 ? ( sma( calc_emo() ,lengthSMA ) < 0 ? -5 : 0 ) : 0 )
  66. emvinss= ( emvins2 > 0 ? ( sma( calc_emo() ,lengthSMA ) > 0 ? 5  : 0 ) : 0 )
  67. macdins2= calc_macd( src) - sma( calc_macd( src) ,lengthSMA )
  68. macdinsb= ( macdins2 < 0 ? ( sma( calc_macd( src),lengthSMA ) < 0 ? -5 : 0 ) : 0 )
  69. macdinss=( macdins2 > 0 ? ( sma( calc_macd( src),lengthSMA) > 0 ? 5 : 0 ) : 0 )
  70. mfiins=( calc_mfi( mfiLength ) > 80 ? 5 : ( calc_mfi( mfiLength ) < 20 ? -5 : 0 ) )
  71. pdoins2=calc_dpo( dpoLength ) - sma( calc_dpo( dpoLength ),lengthSMA )
  72. pdoinsb=( pdoins2 < 0 ? ( sma( calc_dpo( dpoLength ),lengthSMA) < 0 ? -5 : 0 ) :0 )
  73. pdoinss=( pdoins2 > 0 ? ( sma( calc_dpo( dpoLength ),lengthSMA) > 0 ? 5 : 0 ) :0 )
  74. rocins2=calc_roc( src,lengthROC  ) - sma( calc_roc( src,lengthROC ),lengthSMA  )
  75. rocinsb=( rocins2 < 0 ? ( sma( calc_roc( src,lengthROC ),lengthSMA  ) < 0 ? -5 : 0 ) : 0 )
  76. rocinss = ( rocins2 > 0 ? ( sma( calc_roc( src,lengthROC ),lengthSMA ) > 0 ? 5 : 0 ) : 0 )
  77. rsiins= ( rsi(src, lengthRSI ) > 70 ? 5  : ( rsi(src, lengthRSI )  < 30 ? -5 : 0 ) )
  78.  
  79. stopdins=( calc_stochD(lengthStoch,lengthD,lengthK ) > 80 ? 5 : ( calc_stochD(lengthStoch,lengthD, lengthK ) < 20 ? -5 : 0 ) )
  80. stopkins=( calc_stochK(lengthStoch,lengthD,lengthK) > 80 ? 5 : ( calc_stochK(lengthStoch,lengthD, lengthK ) < 20 ? -5 : 0 ) )
  81.  
  82. iidx = 50 + cciins + bolinsll + rsiins + stopkins + stopdins + mfiins + emvinsb + emvinss + rocinss + rocinsb + nz(pdoinss[10]) + nz(pdoinsb [10]) + macdinss + macdinsb
  83. ml=plot(50, color=gray, title="Line50")
  84. ll=plot(5, color= green, title="Line5")
  85. ul=plot(95, color = red, title="Line95")
  86.  
  87. plot(25, color= green, style=3, title="Line25")
  88. plot(75, color = red, style=3, title="Line75")
  89.  
  90. fill(ml, ll, color=red)
  91. fill(ml, ul, color=green)
  92.  
  93. il=plot(iidx, color=maroon, linewidth=2, title="InsyncIndex")
  94. fill(ml,il,black)
  95.  
  96. bc = iidx >= 50 ? (iidx >= 95 ? #336600 : iidx >= 75 ? #33CC00 : #00FF00) :
  97.     (iidx <= 5 ? #990000 : iidx <= 25? #CC3300 :  #CC9900)
  98.  
  99. ebc = input(false, title="Enable Barcolors")
  100. barcolor(ebc?bc:na)
  101.  
  102. ShowEnclosingBB=input(false)
  103. // Draw BB on indices
  104. lengthBB1=input(20, title="Encosing BB Length"), multBB1=input(2.0, title="Encosing BB Multiplier")
  105. bb_s = iidx
  106. basis = ShowEnclosingBB?sma(bb_s, lengthBB1):na
  107. dev = ShowEnclosingBB?multBB1 * stdev(bb_s, lengthBB1):na
  108. upper = ShowEnclosingBB?basis + dev:na
  109. lower = ShowEnclosingBB?basis - dev:na
  110. plot(basis, color=#0066CC, title="Enclosing BB Mid")
  111. p1 = plot(ShowEnclosingBB?upper:na, color=blue, title="Enclosing BB Upper")
  112. p2 = plot(ShowEnclosingBB?lower:na, color=blue, title="Enclosing BB lOWER")
  113. fill(p1,p2, gray, title="Enclosing BB Fill")
  114.  
  115. HighlightBreaches=input(false)
  116. b_color = (bb_s > upper) ? red : (bb_s < lower) ? green : na
  117. bgcolor(HighlightBreaches ? b_color : na)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top