Advertisement
JustUncleL

Ichimoku and RSI Alert R1 by JustUncleL

Jan 27th, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. //@version=3
  2.  
  3. study(title="Ichimoku and RSI Alert R1 by JustUncleL", shorttitle="ICHIRSI", overlay=true)
  4.  
  5. //
  6. // Author: JustUncleL
  7. // Date : 4 Mar 2017
  8. // Revision: R1
  9. //
  10. // Description:
  11. // Implementation of the Ichimoku Cloud with alerts and alarms conditions for
  12. // the major signals:
  13. // - Aqua/Purple Arrows = TS/KS or TK cross
  14. // - Green/Red Triangles (top/bottom) = RSI OB/OS Alerts
  15. //
  16. // References:
  17. // - Based on "CM_Enhanced_Ichimoku Cloud V#" by Chris Moody
  18. //
  19.  
  20. conversionPeriods = input(20, minval=1, title="Tenkan-Sen (Conversion line)")
  21. basePeriods = input(60, minval=1, title="Kinjun-Sen (Base Line)")
  22. leadingSpan2Periods= input(120, minval=1, title="Senkou SpanB (Leading SpanB)")
  23. displacement = input(30, minval=1, title="ChinkouSpan (Lagging Line)/ SenkouSpanA (Leading SpanA)")
  24. length = input( 14 ,minval=1,title="RSI Length")
  25. overSold = input( 30 ,minval=0,maxval=50,title="RSI OverSold Limit")
  26. overBought = input( 70 ,minval=50,maxval=100,title="RSI OverBought Limit")
  27. price = input(close,"RSI Source")
  28. showCS = input(false,title="Show ChinkouSpan (Lagging Line)")
  29. showKUMO = input(false,title="Show KUMO Cloud")
  30. cr1 = input(false, title="Show TS/KS cross Alerts")
  31. showRSI = input(false, title="Show RSI OB/OS Alerts")
  32. // Get MACD for Alert Filtering
  33. showMACD = input(false,title="Show MACD Alerts")
  34. macdFast = input(title="MACD Fast MA Length", type = integer, defval = 12, minval = 2)
  35. macdSlow = input(title="MACD Slow MA Length", type = integer, defval = 26, minval = 7)
  36. macdSignal = input(title="MACD Signal Length",type=integer,defval=9,minval=1)
  37.  
  38. // Constants colours that include fully non-transparent option.
  39. green100 = #008000FF
  40. lime100 = #00FF00FF
  41. red100 = #FF0000FF
  42. blue100 = #0000FFFF
  43. aqua100 = #00FFFFFF
  44. darkred100 = #8B0000FF
  45. gray100 = #808080FF
  46.  
  47. //Definitions for Tenkan-Sen (9 Period), Kinjun-Sen (26 Period), Chinkou Span (Lagging Line)
  48. donchian(len) => avg(lowest(len), highest(len))
  49. //
  50. conversion = donchian(conversionPeriods)
  51. base = donchian(basePeriods)
  52. leadingSpanA = avg(conversion, base)
  53. leadingSpanB = donchian(leadingSpan2Periods)
  54.  
  55. // Calculate RSI
  56. vrsi = rsi(price, length)
  57.  
  58. // Calculate MACD
  59. [macdLine,signalLine,histLine] = macd(price[0], macdFast, macdSlow, macdSignal)
  60.  
  61.  
  62. //First Definition for Ability to Color Cloud based on Trend.
  63. leadingSpanAAbove = leadingSpanA >= leadingSpanB ? 1 : 0
  64. leadingSpanABelow = leadingSpanA <= leadingSpanB ? 1 : 0
  65.  
  66. // plots for 3 lines other than cloud: Comversion, Base and Lagging Lines.
  67. plot(conversion, title = 'TS', linewidth=2, transp=0, color= conversion==base? black:blue)
  68. plot(base, title = 'KS', linewidth=2, transp=0, color= conversion==base? black : red)
  69. plot(showCS?close:na, title='CS', linewidth=1, offset =-displacement, transp=0, color=fuchsia)
  70.  
  71. // Cloud Span Lines
  72. p1=plot(showKUMO?leadingSpanB:na , title = 'SSB', transp=15, linewidth=3, offset = displacement, color=orange)
  73. p2=plot(showKUMO?leadingSpanA:na , title = 'SSA', transp=15, linewidth=1, offset = displacement, color=green)
  74. //Fills that color cloud based on Trend.
  75. col = leadingSpanA >= leadingSpanB ? green : red
  76. fill(p1, p2, color=col, transp=90, title='Kumo')
  77.  
  78. // TS/KS Cross up/down: Tenkan-Sen (9 Period) and Kinjun-Sen (26 Period) crosses
  79. crossUpTenkanKinjun = conversion>base and conversion[1] <= base[1] ? 1 : 0
  80. crossDnTenkanKinjun = conversion<base and conversion[1] >= base[1] ? 1 : 0
  81. cupA = cr1? crossUpTenkanKinjun == 1 ? crossUpTenkanKinjun : 0 : 0
  82. cdnB = cr1? crossDnTenkanKinjun == 1 ? crossDnTenkanKinjun : 0 : 0
  83. plotarrow(cr1 ? cupA==1? 1 : cdnB==1? -1 : na : na, title="Cross TS/KS Entry", colorup=aqua, colordown=fuchsia, transp=0, maxheight=50,minheight=10)
  84.  
  85. // Find RSI OB or OS condition.
  86. OBRSI = showRSI?crossunder(vrsi, overBought):na
  87. OSRSI = showRSI?crossover(vrsi, overSold):na
  88. plotshape(showRSI and OSRSI? vrsi : na, title="RSI OS", style=shape.triangleup,location=location.belowbar, color=green, transp=0, size=size.small)
  89. plotshape(showRSI and OBRSI? vrsi : na, title="RSI OB", style=shape.triangledown,location=location.abovebar, color=maroon, transp=0, size=size.small)
  90.  
  91. // Find MACD condition.
  92. UPMACD = showMACD?crossunder(signalLine,macdLine):na
  93. DNMACD = showMACD?crossover(signalLine,macdLine):na
  94. plotshape(showMACD and UPMACD? macdLine : na, title="MACD UP", style=shape.arrowup,location=location.belowbar, color=lime, transp=0, size=size.normal)
  95. plotshape(showMACD and DNMACD? macdLine : na, title="MACD DN", style=shape.arrowdown,location=location.abovebar, color=red, transp=0, size=size.normal)
  96.  
  97. // Generate alerts for Alarm Subsystem.
  98. alert = (cupA==1 or cdnB==1) or (OBRSI or OSRSI) or (UPMACD or DNMACD)
  99. alertcondition(alert,message="ICHIRSI Alert", title="Alert")
  100.  
  101. // EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement