Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- study(title="Ichimoku and RSI Alert R1 by JustUncleL", shorttitle="ICHIRSI", overlay=true)
- //
- // Author: JustUncleL
- // Date : 4 Mar 2017
- // Revision: R1
- //
- // Description:
- // Implementation of the Ichimoku Cloud with alerts and alarms conditions for
- // the major signals:
- // - Aqua/Purple Arrows = TS/KS or TK cross
- // - Green/Red Triangles (top/bottom) = RSI OB/OS Alerts
- //
- // References:
- // - Based on "CM_Enhanced_Ichimoku Cloud V#" by Chris Moody
- //
- conversionPeriods = input(20, minval=1, title="Tenkan-Sen (Conversion line)")
- basePeriods = input(60, minval=1, title="Kinjun-Sen (Base Line)")
- leadingSpan2Periods= input(120, minval=1, title="Senkou SpanB (Leading SpanB)")
- displacement = input(30, minval=1, title="ChinkouSpan (Lagging Line)/ SenkouSpanA (Leading SpanA)")
- length = input( 14 ,minval=1,title="RSI Length")
- overSold = input( 30 ,minval=0,maxval=50,title="RSI OverSold Limit")
- overBought = input( 70 ,minval=50,maxval=100,title="RSI OverBought Limit")
- price = input(close,"RSI Source")
- showCS = input(false,title="Show ChinkouSpan (Lagging Line)")
- showKUMO = input(false,title="Show KUMO Cloud")
- cr1 = input(false, title="Show TS/KS cross Alerts")
- showRSI = input(false, title="Show RSI OB/OS Alerts")
- // Get MACD for Alert Filtering
- showMACD = input(false,title="Show MACD Alerts")
- macdFast = input(title="MACD Fast MA Length", type = integer, defval = 12, minval = 2)
- macdSlow = input(title="MACD Slow MA Length", type = integer, defval = 26, minval = 7)
- macdSignal = input(title="MACD Signal Length",type=integer,defval=9,minval=1)
- // Constants colours that include fully non-transparent option.
- green100 = #008000FF
- lime100 = #00FF00FF
- red100 = #FF0000FF
- blue100 = #0000FFFF
- aqua100 = #00FFFFFF
- darkred100 = #8B0000FF
- gray100 = #808080FF
- //Definitions for Tenkan-Sen (9 Period), Kinjun-Sen (26 Period), Chinkou Span (Lagging Line)
- donchian(len) => avg(lowest(len), highest(len))
- //
- conversion = donchian(conversionPeriods)
- base = donchian(basePeriods)
- leadingSpanA = avg(conversion, base)
- leadingSpanB = donchian(leadingSpan2Periods)
- // Calculate RSI
- vrsi = rsi(price, length)
- // Calculate MACD
- [macdLine,signalLine,histLine] = macd(price[0], macdFast, macdSlow, macdSignal)
- //First Definition for Ability to Color Cloud based on Trend.
- leadingSpanAAbove = leadingSpanA >= leadingSpanB ? 1 : 0
- leadingSpanABelow = leadingSpanA <= leadingSpanB ? 1 : 0
- // plots for 3 lines other than cloud: Comversion, Base and Lagging Lines.
- plot(conversion, title = 'TS', linewidth=2, transp=0, color= conversion==base? black:blue)
- plot(base, title = 'KS', linewidth=2, transp=0, color= conversion==base? black : red)
- plot(showCS?close:na, title='CS', linewidth=1, offset =-displacement, transp=0, color=fuchsia)
- // Cloud Span Lines
- p1=plot(showKUMO?leadingSpanB:na , title = 'SSB', transp=15, linewidth=3, offset = displacement, color=orange)
- p2=plot(showKUMO?leadingSpanA:na , title = 'SSA', transp=15, linewidth=1, offset = displacement, color=green)
- //Fills that color cloud based on Trend.
- col = leadingSpanA >= leadingSpanB ? green : red
- fill(p1, p2, color=col, transp=90, title='Kumo')
- // TS/KS Cross up/down: Tenkan-Sen (9 Period) and Kinjun-Sen (26 Period) crosses
- crossUpTenkanKinjun = conversion>base and conversion[1] <= base[1] ? 1 : 0
- crossDnTenkanKinjun = conversion<base and conversion[1] >= base[1] ? 1 : 0
- cupA = cr1? crossUpTenkanKinjun == 1 ? crossUpTenkanKinjun : 0 : 0
- cdnB = cr1? crossDnTenkanKinjun == 1 ? crossDnTenkanKinjun : 0 : 0
- 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)
- // Find RSI OB or OS condition.
- OBRSI = showRSI?crossunder(vrsi, overBought):na
- OSRSI = showRSI?crossover(vrsi, overSold):na
- plotshape(showRSI and OSRSI? vrsi : na, title="RSI OS", style=shape.triangleup,location=location.belowbar, color=green, transp=0, size=size.small)
- plotshape(showRSI and OBRSI? vrsi : na, title="RSI OB", style=shape.triangledown,location=location.abovebar, color=maroon, transp=0, size=size.small)
- // Find MACD condition.
- UPMACD = showMACD?crossunder(signalLine,macdLine):na
- DNMACD = showMACD?crossover(signalLine,macdLine):na
- plotshape(showMACD and UPMACD? macdLine : na, title="MACD UP", style=shape.arrowup,location=location.belowbar, color=lime, transp=0, size=size.normal)
- plotshape(showMACD and DNMACD? macdLine : na, title="MACD DN", style=shape.arrowdown,location=location.abovebar, color=red, transp=0, size=size.normal)
- // Generate alerts for Alarm Subsystem.
- alert = (cupA==1 or cdnB==1) or (OBRSI or OSRSI) or (UPMACD or DNMACD)
- alertcondition(alert,message="ICHIRSI Alert", title="Alert")
- // EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement