lazybeartv

Insync Index v02 [LazyBear] [TradingView Indicator]

Apr 2nd, 2015
1,613
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // @author LazyBear
  3. // List of all my indicators: http://bit.ly/1LQaPK8
  4. //
  5. // v02, April0215, Updated to have dynamic levels
  6. //
  7. study(title = "Insync Index [LazyBear]", shorttitle="II_LB")
  8. src=close
  9. Line95=input(95), Line75=input(75), Line25=input(25), Line5=input(5)
  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(Line5, color= green, title="Line5")
  85. ul=plot(Line95, color = red, title="Line95")
  86.  
  87. plot(Line25, color= green, style=3, title="Line25")
  88. plot(Line75, 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 >= Line95 ? #336600 : iidx >= Line75 ? #33CC00 : #00FF00) :
  97. (iidx <= Line5 ? #990000 : iidx <= Line25? #CC3300 : #CC9900)
  98.  
  99. ebc = input(false, title="Enable Barcolors")
  100. barcolor(ebc?bc:na)
RAW Paste Data