Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- //Arranged by @ClassicScott
- //Essentially, my line of thinking is that on impulsive candles down, the origin of the impulse is more important than the close (not always of course, as there
- //are no unbreakable rules in what markets can do), and with impulsive candles up, the same theory applies.
- //So, for upward impulsive candles I've marked out the zone from the open to the low as a support (until broken, in which case it may become resistance).
- //For downward impulsive candles the zone encompasses the open to the high.
- //I've given the option to plot a line from the close for all of these. It's turned off by default as it's just less stuff on the chart, but you may like it.
- //The line length is customizable in a menu. It does funny things on low timeframes on forex and stock charts (long lines that result in chart compression),
- //but, for some reason, very rarely on crypto charts. If someone who is smart (not me) and has much experience with pinescript could perhaps help me out with a fix
- //for this, that would be great. I suspect it has something to do with my "bar_index_duration" that I defined using the time function, but I'm not sure how or why.
- //Line length on time frames of one hour and up it is typically fine.
- //Use the ATR multiple to change the sensitivity of the indicator. This is basically the determination of when a candle is beyond the ATR.
- //A multiple of two is two times the ATR. With lower volatile pairs you can maybe make this lower. On lower time frames or with more volatile pairs (illiquid alts
- //in particular) a higher multiple might serve better. I find the defaul 1.75 is good balance.
- //As I started this I also thought adding some sort of volume information to the candles might be useful as well, so I added a simple candle coloring feature
- //referencing the OBV and a 21 period EMA. Candles are colored based on the OBV's relation to its moving average.
- //I added some plot shapes and candle coloring utilizing the RSI as well. Options to turn on or off shapes plotted for overbought and oversold across the top of
- //the chart. The most interesting feature that I implemented here is a support/resistance zone around the centerline of the RSI. If the RSI is between 49 and 51
- //then you can have optional candle coloring, shapes plotted above the candles, and s/r zones drawn on the chart. In trending markets the centerline of the RSI will
- //frequetly act as support or resistance, so by being alerted of this condition on the chart you can use that with actual levels marked off in order to help make a
- //judgement on a trade. I think it's a nice addition, and an oft overlooked aspect of the usefulness of the RSI.
- //I've also included a calculation, with candle coloring and/or plot shapes, for something like a stop run on high volume (high volume being the measure of the
- //volume in a candle versus a 21 period EMA of volume). The calculation for that is in its section below, and should be pretty self explanatory.
- study(title="+ ATR Support and Resistance", shorttitle="+ ATR S/R", overlay=true)
- ////ATR CANDLES
- period = input(title="ATR Period", defval=14, minval=1, group="ATR Inputs")
- mult = input(type=input.float, title="ATR Multiple", defval=1.75, step=0.05, group="ATR Inputs")
- atr = sma(tr(true), period)
- atr_mult = atr * mult
- imp = tr >= atr_mult
- imp_up = tr >= atr_mult and close > open
- imp_down = tr >= atr_mult and close < open
- barcolor(imp_up ? color.blue : imp_down ? color.red : na, title="ATR Candles")
- plotshape(imp_up, title="Impulse Up", style=shape.circle, location=location.belowbar, color=color.blue)
- plotshape(imp_down, title="Impulse Down", style=shape.circle, location=location.abovebar, color=color.red)
- ////////////////////////////////////////////////////
- ////ATR HORIZONTAL LINES
- line_term = input(defval=20, title="Horizontal Line Length", group="ATR Inputs")
- bar_index_duration = time - time[1]
- ////////////////////////////////////////////////////
- ////CALCULATIONS AND INPUTS FOR S&R ZONES
- //IMPULSE DOWN
- i_imp_down = input(defval=true, title="Bearish Impulse?", group="Support & Resistance Zones")
- d_style = input(type=input.string, defval="Dotted", options=["Dotted", "Dashed", "Solid"], title="Line Style", group="Support & Resistance Zones")
- d_width = input(defval=1, maxval=4, title="Line Width", group="Support & Resistance Zones")
- d_color = input(color.new(color.red, 25), title="Border Color", group="Support & Resistance Zones")
- i_d_bgcolor = input(color.new(color.red, 90), title="Background Color", group="Support & Resistance Zones")
- d_left = imp_down ? time : na
- d_top = imp_down ? high : na
- d_right = imp_down ? time + (line_term * bar_index_duration) : na
- d_bottom = imp_down ? open : na
- d_box_xloc = xloc.bar_time
- d_border_color = d_color
- d_border_width = d_width
- d_border_style = d_style
- d_bgcolor = i_d_bgcolor
- d_box_style = d_style == "Dotted" ? line.style_dotted : d_style == "Dashed" ? line.style_dashed : d_style == "Solid" ? line.style_solid : na
- var box box_down = na
- if i_imp_down
- box_down := box.new(d_left, d_top, d_right, d_bottom, xloc=d_box_xloc, border_color=d_border_color, border_style=d_box_style, border_width=d_border_width, bgcolor=d_bgcolor)
- //IMPULSE UP
- i_imp_up = input(defval=true, title="Bullish Impulse?", group="Support & Resistance Zones")
- u_style = input(type=input.string, defval="Dotted", options=["Dotted", "Dashed", "Solid"], title="Line Style", group="Support & Resistance Zones")
- u_width = input(defval=1, maxval=4, title="Line Width", group="Support & Resistance Zones")
- u_color = input(color.new(color.blue, 25), title="Border Color", group="Support & Resistance Zones")
- i_u_bgcolor = input(color.new(color.blue, 90), title="Background Color", group="Support & Resistance Zones")
- u_left = imp_up ? time : na
- u_top = imp_up ? low : na
- u_right = imp_up ? time + (line_term * bar_index_duration) : na
- u_bottom = imp_up ? open : na
- u_box_xloc = xloc.bar_time
- u_border_color = u_color
- u_border_width = u_width
- u_border_style = u_style
- u_bgcolor = i_u_bgcolor
- u_box_style = u_style == "Dotted" ? line.style_dotted : u_style == "Dashed" ? line.style_dashed : u_style == "Solid" ? line.style_solid : na
- var box box_up = na
- if i_imp_up
- box_up := box.new(u_left, u_top, u_right, u_bottom, xloc=u_box_xloc, border_color=u_border_color, border_style=u_box_style, border_width=u_border_width, bgcolor=u_bgcolor)
- //CLOSE LINES
- i_closes = input(defval=false, title="Closes?", group="Close Lines")
- line_style_c = input(type=input.string, defval="Dotted", options=["Dotted", "Dashed", "Solid"], title="Line Style", group="Close Lines")
- line_width_c = input(defval=1, maxval=4, title="Line Width", group="Close Lines")
- line_color_c = input(color.silver, title="Line Color | Closes", group="Close Lines")
- x1_c = imp ? time : na
- y1_c = imp ? close : na
- x2_c = imp ? time + (line_term * bar_index_duration) : na
- y2_c = imp ? y1_c : na
- xloc_c = xloc.bar_time
- color_c = line_color_c
- style_c = line_style_c == "Dotted" ? line.style_dotted : line_style_c == "Dashed" ? line.style_dashed : line_style_c == "Solid" ? line.style_solid : na
- closes = i_closes ? line.new(x1_c, y1_c, x2_c, y2_c, xloc=xloc_c, color=color_c, style=style_c, width=line_width_c) : na
- ////////////////////////////////////////////////////
- ////RSI VALUES
- rsi_len = input(defval=13, title="Lookback", group="RSI")
- up = rma(max(change(close), 0), rsi_len)
- down = rma(-min(change(close), 0), rsi_len)
- rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
- rsi_sr = rsi >= 49 and rsi <= 51
- barcolor(rsi <= 51 and rsi >=49 ? color.aqua : na, title="RSI Candles")
- plotshape(rsi >= 70, title="RSI Oversold", style=shape.triangledown, location=location.top, color=color.yellow)
- plotshape(rsi <= 30, title="RSI Overbought", style=shape.triangleup, location=location.top, color=color.purple)
- plotshape(rsi_sr, title="RSI Mid Line", style=shape.square, location=location.abovebar, color=color.aqua)
- ////RSI SUPPORT & RESISTANCE
- rsi_support = open > close and rsi_sr
- rsi_resistance = open < close and rsi_sr
- //RSI SUPPORT ZONES
- i_rsi_s = input(defval=true, title="RSI Support Zones?", group="RSI Zones")
- rsi_s_style = input(type=input.string, defval="Dotted", options=["Dotted", "Dashed", "Solid"], title="Line Style", group="RSI Zones")
- rsi_s_width = input(defval=1, maxval=4, title="Line Width", group="RSI Zones")
- rsi_s_color = input(color.new(color.aqua, 25), title="Border Color", group="RSI Zones")
- i_rsi_s_bgcolor = input(color.new(color.aqua, 90), title="Background Color", group="RSI Zones")
- rsi_s_left = rsi_support ? time : na
- rsi_s_top = rsi_support ? close : na
- rsi_s_right = rsi_support ? time + (line_term * bar_index_duration) : na
- rsi_s_bottom = rsi_support ? low : na
- rsi_s_box_xloc = xloc.bar_time
- rsi_s_border_color = rsi_s_color
- rsi_s_border_width = rsi_s_width
- rsi_s_border_style = rsi_s_style
- rsi_s_bgcolor = i_rsi_s_bgcolor
- rsi_s_box_style = rsi_s_style == "Dotted" ? line.style_dotted : d_style == "Dashed" ? line.style_dashed : d_style == "Solid" ? line.style_solid : na
- var box rsi_s_box = na
- if i_rsi_s and not rsi_sr[1]
- rsi_s_box := box.new(rsi_s_left, rsi_s_top, rsi_s_right, rsi_s_bottom, xloc=rsi_s_box_xloc, border_color=rsi_s_border_color, border_style=rsi_s_box_style, border_width=rsi_s_border_width, bgcolor=rsi_s_bgcolor)
- //RSI RESISTANCE ZONES
- i_rsi_r = input(defval=true, title="RSI Resistance Zones?", group="RSI Zones")
- rsi_r_style = input(type=input.string, defval="Dotted", options=["Dotted", "Dashed", "Solid"], title="Line Style", group="RSI Zones")
- rsi_r_width = input(defval=1, maxval=4, title="Line Width", group="RSI Zones")
- rsi_r_color = input(color.new(color.aqua, 25), title="Border Color", group="RSI Zones")
- i_rsi_r_bgcolor = input(color.new(color.aqua, 90), title="Background Color", group="RSI Zones")
- rsi_r_left = rsi_resistance ? time : na
- rsi_r_top = rsi_resistance ? high : na
- rsi_r_right = rsi_resistance ? time + (line_term * bar_index_duration) : na
- rsi_r_bottom = rsi_resistance ? close : na
- rsi_r_box_xloc = xloc.bar_time
- rsi_r_border_color = rsi_s_color
- rsi_r_border_width = rsi_s_width
- rsi_r_border_style = rsi_s_style
- rsi_r_bgcolor = i_rsi_s_bgcolor
- rsi_r_box_style = rsi_s_style == "Dotted" ? line.style_dotted : d_style == "Dashed" ? line.style_dashed : d_style == "Solid" ? line.style_solid : na
- var box rsi_r_box = na
- if i_rsi_r and not rsi_sr[1]
- rsi_r_box := box.new(rsi_r_left, rsi_r_top, rsi_r_right, rsi_r_bottom, xloc=rsi_r_box_xloc, border_color=rsi_r_border_color, border_style=rsi_r_box_style, border_width=rsi_r_border_width, bgcolor=rsi_r_bgcolor)
- ////////////////////////////////////////////////////
- ////HIGH VOLUME CANDLES & STOP RUNNING CANDLES
- i_volume_ma = input(title="EMA Period", defval=21, group="Volume")
- volume_ma = ema(volume, i_volume_ma)
- high_volume = volume > volume_ma
- barcolor(high_volume and close < close[1] and high > high[1] ? #ef9a9a : high_volume and close > close[1] and low < low[1] ? #90bff9 : na, title="High Volume Candles")
- plotshape(high_volume and close < close[1] and high > high[1], title="Ran the Highs?", style=shape.circle, location=location.abovebar, color=#ef9a9a)
- plotshape(high_volume and close > close[1] and low < low[1], title="Ran the Lows?", style=shape.circle, location=location.belowbar, color=#90bff9)
- ////////////////////////////////////////////////////
- ////OBV CANDLES
- obv_prd = input(title="EMA Period", defval=21, minval=2, group="OBV")
- obv_ema = ema(obv, obv_prd)
- barcolor(obv > obv_ema ? color.yellow : obv < obv_ema ? color.purple : na, title="OBV Candles")
- ////////////////////////////////////////////////////
- ////200 PERIOD EMA/SMA/KIJUN AVERAGE
- show_ma = input(type=input.bool, title="Yes or No?", defval=true, group="200 MA AVG")
- ma_lw = input(title="Linewidth", defval=2, minval=1, group="200 MA AVG")
- ma_pos = input(color.blue, title="Up", group="200 MA AVG")
- ma_neg = input(color.red, title="Down", group="200 MA AVG")
- kijun_200 = avg(lowest(200), highest(200))
- ma_avgs = (ema(close, 200) + sma(close, 200) + kijun_200) / 3
- ma_color = close > ma_avgs ? ma_pos : ma_neg
- plot(show_ma ? ma_avgs : na, color=ma_color, linewidth=ma_lw, title="200 AVG")
Advertisement
Add Comment
Please, Sign In to add comment