Candle Body Resistance Channel

Summary

The script calculates a Candle Body Resistance Channel based on the closing prices, using a simple moving average as a reference line and the highest and lowest values over the past 13 periods to define the channel's boundaries. It also provides options to identify bearish and bullish conditions based on the relationship between the closing price and the SMA. The plotting section allows for visualization of these channels, with an option to toggle their display.

Variables and Inputs

len = 34
src = input(close, title='Candle body resistance Channel')
  • len is set to 34, which represents the length of the Simple Moving Average (SMA) calculation period.

  • src is an input variable that takes the closing price (close) as its default value. This is the source data for the CBRC calculation.

Calculations

out = ta.sma(src, len)
  • Calculates the SMA over the specified period (len). This SMA will serve as a reference line within the CBRC.

last8h = ta.highest(close, 13)
lastl8 = ta.lowest(close, 13)
  • last8h finds the highest high over the past 13 periods.

  • lastl8 finds the lowest low over the past 13 periods.

bearish = ta.cross(close, out) == 1 and ta.falling(close, 1)
bullish = ta.cross(close, out) == 1 and ta.rising(close, 1)
  • Checks for bearish and bullish conditions:

    • bearish: True if the close crosses below the SMA (out) and the close is falling.

    • bullish: True if the close crosses above the SMA (out) and the close is rising.

Plotting

channel2 = input(false, title='Bar Channel On/Off')
  • An input option to toggle the visibility of the channel lines on/off.

ul2 = plot(channel2? last8h : last8h == nz(last8h[2])? 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[2])? lastl8 : na, color=color.new(color.black, 0), linewidth=1, style=plot.style_linebr, title='Candle body resistance level bottom', offset=0)
  • Plots the upper (ul2) and lower (ll2) levels of the CBRC:

    • Upper level (ul2): If channel2 is true, plots the highest high (last8h). Otherwise, checks if the current highest high is equal to the previous one; if so, it plots the current highest high; otherwise, it plots na (not a number).

    • Lower level (ll2): Similar logic applies but for the lowest low (lastl8).

Commented Out Fill

//fill(ul2, ll2, color=black, transp=95, title="Candle body resistance Channel")
  • This line is commented out, but if uncommented, it would fill the area between the upper and lower levels of the CBRC with a semi-transparent black color, providing visual representation of the channel.

Citations:

Last updated