SHARE
TWEET

Insync Index With BB V2 [LazyBear]

lazybeartv May 7th, 2015 992 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. // v2 - Histo mode added
  8. //
  9. study(title = "Insync Index With BB v2 [LazyBear]", shorttitle="IIBBV2_LB")
  10. src=close
  11. shh=input(false, title="Show Index as Histo")
  12. div = input(10000, title="EMO Divisor", minval=1)
  13. emoLength = input(14, minval=1, title="EMO length")
  14. fastLength = input(12, minval=1, title="MACD Fast EMA Length")
  15. slowLength=input(26,minval=1, title="MACD Slow EMA Length")
  16. signalLength=input(9,minval=1, title="MACD Signal Length")
  17. mfiLength = input(20, minval=1, title="MFI Length")
  18.  
  19. calc_emo() => sma(div * change(hl2) * (high - low) / volume, emoLength)
  20. calc_macd(source) =>
  21.     fastMA = ema(source, fastLength)
  22.     slowMA = ema(source, slowLength)
  23.     fastMA - slowMA
  24.  
  25. calc_mfi(length) =>
  26.     src = hlc3
  27.     upper = sum(volume * (change(src) <= 0 ? 0 : src), length)
  28.     lower = sum(volume * (change(src) >= 0 ? 0 : src), length)
  29.     mf = rsi(upper, lower)
  30.     mf
  31.  
  32. calc_dpo(period_) =>  
  33.     isCentered = false
  34.     barsback = period_/2 + 1
  35.     ma = sma(close, period_)
  36.     dpo = isCentered ? close[barsback] - ma : close - ma[barsback]
  37.     dpo
  38.  
  39. calc_roc(source, length) =>
  40.     roc = 100 * (source - source[length])/source[length]
  41.     roc
  42.  
  43. calc_stochD(length, smoothD, smoothK) =>
  44.     k = sma(stoch(close, high, low, length), smoothK)
  45.     d = sma(k, smoothD)
  46.     d
  47.  
  48. calc_stochK(length, smoothD, smoothK) =>
  49.     k = sma(stoch(close, high, low, length), smoothK)
  50.     //d = sma(k, smoothD)
  51.     k
  52.  
  53. lengthBB=input(20, title="BB Length"), multBB=input(2.0, title="BB Multiplier")    
  54. lengthCCI=input(14, title="CCI Length")
  55. dpoLength=input(18, title="DPO Length")
  56. lengthROC=input(10, title="ROC Length")
  57. lengthRSI=input(14, title="RSI Length")
  58. lengthStoch=input(14, title="Stoch Length"),lengthD=input(3, title="Stoch D Length"), lengthK=input(1, title="Stoch K Length")
  59. lengthSMA=input(10, title="MA Length")
  60.  
  61. bolinslb=sma( src,lengthBB ) - multBB * ( stdev( src,lengthBB ) )
  62. bolinsub=sma( src,lengthBB ) + multBB * ( stdev( src,lengthBB ) )
  63. bolins2= (src- bolinslb ) / ( bolinsub - bolinslb )
  64. bolinsll=( bolins2 < 0.05 ? -5 : ( bolins2 > 0.95 ? 5 : 0 ) )
  65. cciins= ( cci(src, lengthCCI) > 100 ? 5 :  ( cci(src, lengthCCI ) < -100 ? -5 : 0 ) )
  66. emvins2= calc_emo() - sma( calc_emo(),lengthSMA)
  67. emvinsb= ( emvins2 < 0 ? ( sma( calc_emo() ,lengthSMA ) < 0 ? -5 : 0 ) : 0 )
  68. emvinss= ( emvins2 > 0 ? ( sma( calc_emo() ,lengthSMA ) > 0 ? 5  : 0 ) : 0 )
  69. macdins2= calc_macd( src) - sma( calc_macd( src) ,lengthSMA )
  70. macdinsb= ( macdins2 < 0 ? ( sma( calc_macd( src),lengthSMA ) < 0 ? -5 : 0 ) : 0 )
  71. macdinss=( macdins2 > 0 ? ( sma( calc_macd( src),lengthSMA) > 0 ? 5 : 0 ) : 0 )
  72. mfiins=( calc_mfi( mfiLength ) > 80 ? 5 : ( calc_mfi( mfiLength ) < 20 ? -5 : 0 ) )
  73. pdoins2=calc_dpo( dpoLength ) - sma( calc_dpo( dpoLength ),lengthSMA )
  74. pdoinsb=( pdoins2 < 0 ? ( sma( calc_dpo( dpoLength ),lengthSMA) < 0 ? -5 : 0 ) :0 )
  75. pdoinss=( pdoins2 > 0 ? ( sma( calc_dpo( dpoLength ),lengthSMA) > 0 ? 5 : 0 ) :0 )
  76. rocins2=calc_roc( src,lengthROC  ) - sma( calc_roc( src,lengthROC ),lengthSMA  )
  77. rocinsb=( rocins2 < 0 ? ( sma( calc_roc( src,lengthROC ),lengthSMA  ) < 0 ? -5 : 0 ) : 0 )
  78. rocinss = ( rocins2 > 0 ? ( sma( calc_roc( src,lengthROC ),lengthSMA ) > 0 ? 5 : 0 ) : 0 )
  79. rsiins= ( rsi(src, lengthRSI ) > 70 ? 5  : ( rsi(src, lengthRSI )  < 30 ? -5 : 0 ) )
  80.  
  81. stopdins=( calc_stochD(lengthStoch,lengthD,lengthK ) > 80 ? 5 : ( calc_stochD(lengthStoch,lengthD, lengthK ) < 20 ? -5 : 0 ) )
  82. stopkins=( calc_stochK(lengthStoch,lengthD,lengthK) > 80 ? 5 : ( calc_stochK(lengthStoch,lengthD, lengthK ) < 20 ? -5 : 0 ) )
  83.  
  84. iidx = 50 + cciins + bolinsll + rsiins + stopkins + stopdins + mfiins + emvinsb + emvinss + rocinss + rocinsb + nz(pdoinss[10]) + nz(pdoinsb [10]) + macdinss + macdinsb
  85. ml=plot(50, color=gray, title="Line50")
  86. ll=plot(5, color= green, title="Line5")
  87. ul=plot(95, color = red, title="Line95")
  88.  
  89. plot(25, color= green, style=3, title="Line25")
  90. plot(75, color = red, style=3, title="Line75")
  91.  
  92. fill(ml, ll, color=red)
  93. fill(ml, ul, color=green)
  94.  
  95. il=plot(shh?na:iidx, color=maroon, linewidth=2, title="InsyncIndex", style=linebr)
  96. fill(ml,il,black)
  97.  
  98. bc = iidx >= 50 ? (iidx >= 95 ? #336600 : iidx >= 75 ? #33CC00 : #00FF00) :
  99.     (iidx <= 5 ? #990000 : iidx <= 25? #CC3300 :  #CC9900)
  100.  
  101. ilh=plot(shh?iidx:na, color=bc, linewidth=3, title="InsyncIndexHisto", histbase=50,  style=histogram)
  102. ebc = input(false, title="Enable Barcolors")
  103. barcolor(ebc?bc:na)
  104.  
  105. ShowEnclosingBB=input(false)
  106. // Draw BB on indices
  107. lengthBB1=input(20, title="Encosing BB Length"), multBB1=input(2.0, title="Encosing BB Multiplier")
  108. bb_s = iidx
  109. basis = ShowEnclosingBB?sma(bb_s, lengthBB1):na
  110. dev = ShowEnclosingBB?multBB1 * stdev(bb_s, lengthBB1):na
  111. upper = ShowEnclosingBB?basis + dev:na
  112. lower = ShowEnclosingBB?basis - dev:na
  113. plot(basis, color=#0066CC, title="Enclosing BB Mid")
  114. p1 = plot(ShowEnclosingBB?upper:na, color=blue, title="Enclosing BB Upper")
  115. p2 = plot(ShowEnclosingBB?lower:na, color=blue, title="Enclosing BB lOWER")
  116. fill(p1,p2, gray, title="Enclosing BB Fill")
  117.  
  118. HighlightBreaches=input(false)
  119. b_color = (bb_s > upper) ? red : (bb_s < lower) ? green : na
  120. 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