Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator('RHS - Final Chapter', overlay=true, shorttitle='RHS - Final Chapter', max_bars_back=1000)
- //
- //====================channel======================
- len = input.int(8, minval=1)
- src = input(close, title='Source')
- out = ta.sma(src, len)
- last8h = ta.highest(close, 13)
- lastl8 = ta.lowest(close, 13)
- bearish = ta.cross(close, out) == 1 and close[1] > close
- bullish = ta.cross(close, out) == 1 and close[1] < close
- channel2 = input(false, title='Bar Channel On/Off')
- ul2 = plot(channel2 ? last8h : last8h == nz(last8h[1]) ? last8h : na, color=color.new(color.black, 0), linewidth=1, style=plot.style_linebr, title='Candle body resistance level top', offset=0)
- ll2 = plot(channel2 ? lastl8 : lastl8 == nz(lastl8[1]) ? lastl8 : na, color=color.new(color.black, 0), linewidth=1, style=plot.style_linebr, title='Candle body resistance level bottom', offset=0)
- //
- //--------------------Trend colour ema------------------------------------------------// ema trend direction trigger For Singals 1 & 2
- src0 = close
- len0 = input.int(13, minval=1, title='Trend Change EMA')
- ema0 = ta.ema(src0, len0)
- plot_color = ema0 >= ema0[2] ? color.lime : ema0 < ema0[2] ? color.red : na
- plot(ema0, title='EMA', style=plot.style_line, linewidth=1, color=plot_color)
- //
- // Create non-repainting security function
- //rp_security(_symbol, _res, _src) => security(_symbol, _res, _src[barstate.isrealtime ? 1 : 0])
- //f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
- f_security(_symbol, _res, _src, _repaint) =>
- request.security(_symbol, _res, _src[_repaint ? 0 : barstate.isrealtime ? 1 : 0])[_repaint ? 0 : barstate.isrealtime ? 0 : 1]
- //
- //
- //--Modified vyacheslav.shindin-------------------------------------------------// Signal 1
- //Configured ema signal output
- slow = 8
- fast = 5
- vh1 = ta.ema(ta.highest(math.avg(low, close), fast), 5)
- vl1 = ta.ema(ta.lowest(math.avg(high, close), slow), 8)
- //
- e_ema1 = ta.ema(close, 1)
- e_ema2 = ta.ema(e_ema1, 1)
- e_ema3 = ta.ema(e_ema2, 1)
- tema = 1 * (e_ema1 - e_ema2) + e_ema3
- //
- e_e1 = ta.ema(close, 8)
- e_e2 = ta.ema(e_e1, 5)
- dema = 2 * e_e1 - e_e2
- signal = tema > dema ? math.max(vh1, vl1) : math.min(vh1, vl1)
- is_call = tema > dema and signal > low and signal - signal[1] > signal[1] - signal[2]
- is_put = tema < dema and signal < high and signal[1] - signal > signal[2] - signal[1]
- plotshape(is_call ? 1 : na, title='BUY ARROW', color=color.new(color.green, 0), text='BUY', textcolor=color.new(color.white, 0), size=size.auto, style=shape.labelup, location=location.belowbar)
- plotshape(is_put ? -1 : na, title='SELL ARROW', color=color.new(color.red, 0), text='SELL', textcolor=color.new(color.white, 0), size=size.auto, style=shape.labeldown)
- //
- //Modified - Rajandran R Supertrend----------------------------------------------------- // Signal 2
- Factor = input.int(1, minval=1, defval=2, maxval=1000, title='Trend Transition Signal')
- Pd = input.int(1, minval=1, maxval=100)
- Up = hl2 - Factor * ta.atr(Pd)
- Dn = hl2 + Factor * ta.atr(Pd)
- TrendUp = Up
- TrendUp := close[1] > TrendUp[1] ? math.max(Up, TrendUp[1]) : Up
- TrendDown = Dn
- TrendDown := close[1] < TrendDown[1] ? math.min(Dn, TrendDown[1]) : Dn
- Trend = TrendUp
- Trend := close > TrendDown[1] ? 1 : close < TrendUp[1] ? -1 : nz(Trend[1], 0)
- plotshape(Trend == 1 and Trend[1] == -1 ? Trend : na, title='BUY ARROW', color=color.new(color.green, 0), text='BREAK THE LINE\n(BUY)', textcolor=color.new(color.white, 0), size=size.auto, style=shape.labelup, location=location.belowbar)
- plotshape(Trend == -1 and Trend[1] == 1 ? Trend : na, title='SELL ARROW', color=color.new(color.red, 0), text='BREAK THE LINE\n(SELL)', textcolor=color.new(color.white, 0), size=size.auto, style=shape.labeldown)
- //plotarrow(Trend == 1 and Trend[1] == -1 ? Trend : na, title="Strong Buy", colorup=lime, maxheight=1000, minheight=50, transp=80)
- //plotarrow(Trend == -1 and Trend[1] == 1 ? Trend : na, title="Strong Sell", colordown=red, maxheight=1000, minheight=50, transp=80)
- // Moddified [RS]Support and Resistance V0
- RST = input(title='Support / Resistance length:', defval=21)
- RSTT = ta.valuewhen(high >= ta.highest(high, RST), high, 0)
- RSTB = ta.valuewhen(low <= ta.lowest(low, RST), low, 0)
- RT2 = plot(RSTT, color=RSTT != RSTT[1] ? na : color.red, linewidth=1, offset=0)
- RB2 = plot(RSTB, color=RSTB != RSTB[1] ? na : color.green, linewidth=1, offset=0)
- //
- //===============================Directional Projection=======================================//
- tf2 = input('1', title='Trend Projection TF / Mins/D/W')
- M2 = input('ATR')
- P2 = input(13.00)
- W2 = input(1)
- pf2 = ticker.pointfigure(syminfo.tickerid, 'close', M2, P2, W2)
- spfc2 = request.security(pf2, tf2, close)
- channel3 = input(false, title='Connect Projection High/Low')
- p22 = plot(channel3 ? spfc2 : spfc2 == nz(spfc2[1]) ? spfc2 : na, color=color.new(color.white, 100), linewidth=1, style=plot.style_linebr, title='Directional Projection', offset=0)
- //----------------------------------------------------------------------//
- // ~~ Tooltips {
- t1 = "The space between the levels can be adjusted with a percentage step. 1% means that each level is located 1% above/under the previous one."
- t2 = "Set the number of levels you want to display."
- t3 = "If a level got 0 % likelihood of being hit, the level is not displayed as default. Enable the option if you want to see all levels regardless of their values."
- t4 = "Enable this option if you want to display the backtest statistics for that a new high or low is made."
- string [] tbl_tips = array.from("Number of times price has reached the first highest percentage level",
- "Number of times price failed to reach the first highest percentage level",
- "Win/Loss ratio")
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
- // ~~ Inputs {
- perc = input.float(1.0,title="Percentage Step",step=.1,minval=0,group="Settings",tooltip=t1)
- nbr = input.int(5, title="Number of Lines",maxval=5,minval=1,group="Settings",tooltip=t2)
- upCol = input.color(color.new(color.green,0),title=" ",inline="col"),dnCol=input.color(color.new(color.red,0),title="",inline="col"),fill=input.bool(true,title="BG Color",inline="col")
- var bool [] bools = array.from(input.bool(true,title="Disable 0.00%",group="Settings",tooltip=t3),input.bool(true, title="Show Statistic Panel",group="Settings",tooltip=t4))
- var bool [] alert_bool = array.from(
- input.bool(true,title="Ticker ID",group="Any alert() function call"),
- input.bool(true,title="High/Low Price",group="Any alert() function call"),
- input.bool(true,title="Bullish/Bearish Bias",group="Any alert() function call"),
- input.bool(true,title="Bullish/Bearish Percentage",group="Any alert() function call"))
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
- // ~~ Variables {
- b = bar_index
- o = open
- h = high
- l = low
- c = close
- step = c*(perc/100)
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
- // ~~ Save Values In Matrix {
- var total = matrix.new<int>(7,4,0)
- var vals = matrix.new<float>(5,4,0.0)
- var lines = matrix.new<line>(1,10,line(na))
- var labels = matrix.new<label>(1,10,label(na))
- var tbl = matrix.new<table>(1,1,table.new(position.top_right,2,3,
- frame_color=color.new(color.gray,50),frame_width=3,
- border_color=chart.bg_color,border_width=-2))
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
- // ~~ Save Number Of Green & Red Candles {
- green = c[1]>o[1]
- red = c[1]<o[1]
- if green
- prev = matrix.get(total,5,0)
- matrix.set(total,5,0,prev+1)
- if red
- prev = matrix.get(total,5,1)
- matrix.set(total,5,1,prev+1)
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
- // ~~ Functions {
- //Lines
- CreateLine(p,i,c)=>
- prevLine = matrix.get(lines,0,i)
- line.delete(prevLine)
- li = line.new(b[1],p,b,p,color=c,width=2)
- matrix.set(lines,0,i,li)
- //Labels
- CreateLabel(p,i,c,r,v)=>
- prevLabel = matrix.get(labels,0,i)
- label.delete(prevLabel)
- la = label.new(b+1,p,text=str.tostring(matrix.get(vals,r,v),format.percent),
- style=label.style_label_left,color=color.new(color.black,100),textcolor=c)
- matrix.set(labels,0,i,la)
- //Score Calculation
- Score(x,i)=>
- ghh = matrix.get(total,i,0)
- gll = matrix.get(total,i,1)
- rhh = matrix.get(total,i,2)
- rll = matrix.get(total,i,3)
- gtotal = matrix.get(total,5,0)
- rtotal = matrix.get(total,5,1)
- hh = h>=h[1] + x
- ll = l<=l[1] - x
- if green and hh
- matrix.set(total,i,0,ghh+1)
- matrix.set(vals,i,0,math.round(((ghh+1)/gtotal)*100,2))
- if green and ll
- matrix.set(total,i,1,gll+1)
- matrix.set(vals,i,1,math.round(((gll+1)/gtotal)*100,2))
- if red and hh
- matrix.set(total,i,2,rhh+1)
- matrix.set(vals,i,2,math.round(((rhh+1)/rtotal)*100,2))
- if red and ll
- matrix.set(total,i,3,rll+1)
- matrix.set(vals,i,3,math.round(((rll+1)/rtotal)*100,2))
- //Backtest
- Backtest(v)=>
- p1 = matrix.get(total,6,0)
- p2 = matrix.get(total,6,1)
- if v==h[1]
- if h>=v
- matrix.set(total,6,0,p1+1)
- else
- matrix.set(total,6,1,p2+1)
- else
- if l<=v
- matrix.set(total,6,0,p1+1)
- else
- matrix.set(total,6,1,p2+1)
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
- // ~~ Code {
- //Run Score Function
- Score(0,0)
- Score(step,1)
- Score(step*2,2)
- Score(step*3,3)
- Score(step*4,4)
- //Fetch Score Values
- a1 = matrix.get(vals,0,0)
- b1 = matrix.get(vals,0,1)
- a2 = matrix.get(vals,0,2)
- b2 = matrix.get(vals,0,3)
- //Lines & Labels & Alerts
- for i=0 to nbr-1
- hide = array.get(bools,0)
- if not hide or (hide and (green?math.min(matrix.get(vals,i,0),
- matrix.get(vals,i,1))>0:
- math.min(matrix.get(vals,i,2),
- matrix.get(vals,i,3))>0))
- hi = h[1]+(step*i)
- lo = l[1]-(step*i)
- //Plot Lines
- CreateLine(hi,i,upCol)
- CreateLine(lo,5+i,dnCol)
- //Plot Labels
- if green
- CreateLabel(hi,i,upCol,i,0)
- CreateLabel(lo,5+i,dnCol,i,1)
- else
- CreateLabel(hi,i,upCol,i,2)
- CreateLabel(lo,5+i,dnCol,i,3)
- //Create Alert
- if array.includes(alert_bool, true)
- s1 = str.tostring(syminfo.ticker)
- s2 = "High Price: "+str.tostring(math.round_to_mintick(h[1]))+
- " | Low Price: "+str.tostring(math.round_to_mintick(l[1]))
- s3 = green?(math.max(a1,b1)==a1?"BULLISH":"BEARISH"):
- (math.max(a2,b2)==a2?"BULLISH":"BEARISH")
- s4 = green?(math.max(a1,b1)==a1?a1:b1):(math.min(a2,b2)==a2?a2:b2)
- s5 = red ?(math.max(a2,b2)==a2?a2:b2):(math.min(a1,b1)==a1?a1:b1)
- string [] str_vals = array.from(s1,s2,"BIAS: "+s3,
- "Percentage: High: "+str.tostring(s4,format.percent)
- +" | Low: "+str.tostring(s5,format.percent))
- output = array.new_string()
- for x=0 to array.size(alert_bool)-1
- if array.get(alert_bool,x)
- array.push(output,array.get(str_vals,x))
- //Alert Is Triggered On Every Bar Open With Bias And Percentage Ratio
- alert(array.join(output,'\n'),alert.freq_once_per_bar)
- else
- //Delete Old Lines & Labels
- line.delete(matrix.get(lines,0,i))
- line.delete(matrix.get(lines,0,5+i))
- label.delete(matrix.get(labels,0,i))
- label.delete(matrix.get(labels,0,5+i))
- //Run Backtest Function
- Backtest(green?(math.max(a1,b1)==a1?h[1]:l[1]):(math.max(a2,b2)==a2?h[1]:l[1]))
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
- // ~~ Linefill {
- if fill
- var filler = linefill(na)
- for i=0 to 8
- get = matrix.get(lines,0,i)
- get1= matrix.get(lines,0,i+1)
- col = i>4?color.new(dnCol,80) : i==4?color.new(color.gray,100) : color.new(upCol,80)
- filler := linefill.new(get,get1,color=col)
- linefill.delete(filler[1])
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
Advertisement
Add Comment
Please, Sign In to add comment