Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- //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.
- indicator(title='+ ATR Support and Resistance', shorttitle='+ ATR S/R', overlay=true)
- ////ATR CANDLES
- period = input.int(title='ATR Period', defval=14, minval=1, group='ATR Inputs')
- mult = input.float(title='ATR Multiple', defval=1.75, step=0.05, group='ATR Inputs')
- atr = ta.sma(ta.tr(true), period)
- atr_mult = atr * mult
- imp = ta.tr >= atr_mult
- imp_up = ta.tr >= atr_mult and close > open
- imp_down = ta.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.new(color.blue, 0))
- plotshape(imp_down, title='Impulse Down', style=shape.circle, location=location.abovebar, color=color.new(color.red, 0))
- ////////////////////////////////////////////////////
- ////ATR HORIZONTAL LINES
- line_term = input.int(defval=20, title='Horizontal Line Length', group='ATR Inputs')
- bar_index_duration = time - time[1]
- ////////////////////////////////////////////////////
- ////CALCULATIONS AND INPUTS FOR S&D ZONES
- ////IMPULSE DOWN
- i_imp_down = input.bool(defval=true, title='Bearish Impulse?', group='Support & Resistance Zones')
- d_style = input.string(defval='Dotted', options=['Dotted', 'Dashed', 'Solid'], title='Line Style', group='Support & Resistance Zones')
- d_width = input.int(defval=1, maxval=4, title='Line Width', group='Support & Resistance Zones')
- d_color = input.color(color.new(color.red, 25), title='Border Color', group='Support & Resistance Zones')
- i_d_bgcolor = input.color(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)
- box_down
- ////IMPULSE UP
- i_imp_up = input.bool(defval=true, title='Bullish Impulse?', group='Support & Resistance Zones')
- u_style = input.string(defval='Dotted', options=['Dotted', 'Dashed', 'Solid'], title='Line Style', group='Support & Resistance Zones')
- u_width = input.int(defval=1, maxval=4, title='Line Width', group='Support & Resistance Zones')
- u_color = input.color(color.new(color.blue, 25), title='Border Color', group='Support & Resistance Zones')
- i_u_bgcolor = input.color(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)
- box_up
- ////CLOSE LINES
- i_closes = input.bool(defval=false, title='Closes?', group='Close Lines')
- line_style_c = input.string(defval='Dotted', options=['Dotted', 'Dashed', 'Solid'], title='Line Style', group='Close Lines')
- line_width_c = input.int(defval=1, maxval=4, title='Line Width', group='Close Lines')
- line_color_c = input.color(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.int(defval=13, title='Lookback', group='RSI')
- up = ta.rma(math.max(ta.change(close), 0), rsi_len)
- down = ta.rma(-math.min(ta.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 Overbought', style=shape.triangledown, location=location.top, color=color.new(color.yellow, 0))
- plotshape(rsi <= 30, title='RSI Oversold', style=shape.triangleup, location=location.top, color=color.new(color.purple, 0))
- plotshape(rsi_sr and close < open, title='RSI Centerline Support', style=shape.square, location=location.belowbar, color=color.new(color.aqua, 0))
- plotshape(rsi_sr and close > open, title='RSI Centerline Resistance', style=shape.square, location=location.abovebar, color=color.new(color.aqua, 0))
- ////RSI SUPPORT & RESISTANCE ZONES
- rsi_support = close < open and rsi_sr
- rsi_resistance = close > open and rsi_sr
- ////SUPPORT ZONES
- i_rsi_s = input.bool(defval=true, title='RSI Support Zones?', group='RSI Zones')
- rsi_s_style = input.string(defval='Dotted', options=['Dotted', 'Dashed', 'Solid'], title='Line Style', group='RSI Zones')
- rsi_s_width = input.int(defval=1, maxval=4, title='Line Width', group='RSI Zones')
- rsi_s_color = input.color(color.new(color.aqua, 25), title='Border Color', group='RSI Zones')
- i_rsi_s_bgcolor = input.color(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_s_box
- ////RESISTANCE ZONES
- i_rsi_r = input.bool(defval=true, title='RSI Resistance Zones?', group='RSI Zones')
- rsi_r_style = input.string(defval='Dotted', options=['Dotted', 'Dashed', 'Solid'], title='Line Style', group='RSI Zones')
- rsi_r_width = input.int(defval=1, maxval=4, title='Line Width', group='RSI Zones')
- rsi_r_color = input.color(color.new(color.aqua, 25), title='Border Color', group='RSI Zones')
- i_rsi_r_bgcolor = input.color(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_r_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)
- rsi_r_box
- ////////////////////////////////////////////////////
- ////HIGH VOLUME CANDLES & STOP RUNNING CANDLES
- i_volume_ma = input.int(title='EMA Period', defval=21, group='Volume')
- volume_ma = ta.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=color.new(#ef9a9a, 0))
- plotshape(high_volume and close > close[1] and low < low[1], title='Ran the Lows?', style=shape.circle, location=location.belowbar, color=color.new(#90bff9, 0))
- ////////////////////////////////////////////////////
- ////OBV CANDLES
- obv_prd = input.int(title='EMA Period', defval=21, minval=2, group='OBV')
- obv_ema = ta.ema(ta.obv, obv_prd)
- barcolor(ta.obv > obv_ema ? color.yellow : ta.obv < obv_ema ? color.purple : na, title='OBV Candles')
- ////////////////////////////////////////////////////
- ////200 PERIOD EMA/SMA/KIJUN AVERAGE
- show_ma = input.bool(title='Yes or No?', defval=true, group='200 MA AVG')
- ma_lw = input.int(title='Linewidth', defval=2, minval=1, group='200 MA AVG')
- ma_pos = input.color(color.blue, title='Up', group='200 MA AVG')
- ma_neg = input.color(color.red, title='Down', group='200 MA AVG')
- kijun_200 = math.avg(ta.lowest(200), ta.highest(200))
- ma_avgs = (ta.ema(close, 200) + ta.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')
- //end of this part
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © adjmali7912
- //@version=5
- //indicator(title="Above50",shorttitle="Above 50",overlay=true)
- //Creating input controlls
- len1=input.int(defval=50,title='len1',minval=50,maxval=1000,step=1 )
- len2=input.int(defval=100,title='len1',minval=50,maxval=1000,step=1 )
- len3=input.int(defval=200,title='len1',minval=50,maxval=1000,step=1 )
- len4=input.int(defval=1000,title='len1',minval=50,maxval=1000,step=1 )
- //Indicator
- ema1=ta.ema(close,len1)
- ema2=ta.ema(close,len2)
- ema3=ta.ema(close,len3)
- ema4=ta.ema(close,len4)
- //Plot the indicator
- plot(ema1,color=color.red,linewidth=2)
- plot(ema2,color=color.green,linewidth=2)
- plot(ema3,color=color.yellow,linewidth=2)
- plot(ema4,color=color.red,linewidth=2)
Advertisement
Add Comment
Please, Sign In to add comment