# 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

```javascript
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

```javascript
out = ta.sma(src, len)
```

* Calculates the SMA over the specified period (`len`). This SMA will serve as a reference line within the CBRC.

```javascript
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.

```javascript
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

```javascript
channel2 = input(false, title='Bar Channel On/Off')
```

* An input option to toggle the visibility of the channel lines on/off.

```javascript
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

```javascript
//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:


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bondingblock.gitbook.io/quant/candle-body-resistance-channel.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
