Indicator · Pine Script v4 · On the chart

BBI HPI RSI

by blackcat1402

This indicator combines Bollinger Band Indicator, High Price Indicator and Relative Strength Index on the price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv4older, still runs
Lines of code221
Settings6inputs
LicenceMIT
Last update5 years ago19 Dec 2020

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

221 lines of Pine Script v4 from indicator/multi/bbi_hpi_rsi.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

bbi_hpi_rsi.pine
//@version=4



// -------------------------------------------------------------------------- //



study(title="BBI, HPI, RSI", shorttitle="BBI, HPI, RSI", overlay=true)



// -------------------------------------------------------------------------- //



var OS = "OS" // Open Short. The signal to start a short trade.
var CS = "CS" // Close Short. The signal to end a short trade.
var OL = "OL" // Open Long. The signal to start a long trade.
var CL = "CL" // Close Long. The signal to end a long trade.

// Current Cycle. The cycle of the current trade. Either OS, CS, OL or CL.
var CC = array.new_string(1, CL)
get_ccc() =>
    array.get(CC, 0)
set_ccc(v) =>
    array.set(CC, 0, v)

var FP = array.new_float(1, 0.0) // First Price. The entry price of our current trade.
var LP = array.new_float(1, 0.0) // Last Price. The latest price of our current trade.



// -------------------------------------------------------------------------- //



tsl = input(title="Trailing Stop Loss",  type=input.float, defval=0.2, minval=0.01, step=0.01)
mtp = input(title="Minimum Take Profit", type=input.float, defval=0.2, minval=0.01, step=0.01)



// -------------------------------------------------------------------------- //



// new_cor returns true if the series given by ser results in true for at least
// the minimal required amount of time defined by min over a period of recent
// bars given by rec. Note that ser must be of type series[bool].
//
//     - - | | -     new_cor(ser, 2, 2) => true
//     | - - | -     new_cor(ser, 2, 5) => true
//
new_cor(ser, min, rec) =>
    cou = 0

    for i = 0 to rec
        cou := ser[i] ? cou + 1 : cou

    cou >= min

// new_crb returns true if the current bar is red, that is, the current open
// price is higher than the current close price. This signals a local downward
// movement. Here crb means current red bar.
new_crb() =>
    open > close

// new_per calculates the percentage of a fraction based on the given absolute
// value.
//
//     new_per(500, 5) => 1
//
new_per(abs, fra) =>
    fra * 100 / abs



// -------------------------------------------------------------------------- //



bbl = input(title="BBI Length", type=input.integer, defval=70,   minval=1,    step=1  )
bbs = input(title="BBI Stddev", type=input.float,   defval=2.65, minval=0.1,  step=0.1)
bbp = input(title="BBI Pivot",  type=input.float,   defval=20,   minval=0.01, step=1  )



// new_bbu returns the upper bollinger band based on the length given by bbl and
// the standard deviation given by bbs. Here bbu means bollinger band upper.
new_bbu(src, bbl, bbs) =>
    sma(src, bbl) + bbs * stdev(src, bbl)

new_bbi(src, bbl, bbs) =>
    bbu = new_bbu(src, bbl, bbs)

    cou = 0
    bac = 8

    for i = 0 to bac
        cou := high[i] > bbu[i] and bbu[i] > low[i] ? cou + 1 : cou

    new_per(bac, cou) > bbp and not (high[0] > bbu[0] and bbu[0] > low[0])



// -------------------------------------------------------------------------- //



hrb = input(title="HPI Recent Bar", type=input.integer, defval=175, minval=1, step=1)



// new_hpi returns a high price indicator for the most recent bars since hrb.
// Here hpi means high price indicator.
new_hpi(hrb) =>
    highest(open, hrb) == open and new_crb()



// -------------------------------------------------------------------------- //



// new_rsb returns the relative strength indicator for the current bar, based on
// the running moving average. Here rsb means relative strength bar.
new_rsb(src, rsl) =>
    upw = rma( max(change(src), 0), rsl)
    dow = rma(-min(change(src), 0), rsl)

    dow == 0 ? 100 : upw == 0 ? 0 : 100 - (100 / (1 + upw / dow))

// new_rsi returns the relative strength indicator for overbought price peaks.
new_rsi(src) =>
    one = new_rsb(src, 120)[1] < 57 and new_rsb(src, 120)[0] > 57
    two = new_rsb(src, 50 )[1] < 65 and new_rsb(src, 50 )[0] > 65
    thr = new_rsb(src, 30 )[1] < 70 and new_rsb(src, 30 )[0] > 70
    fou = new_rsb(src, 17 )[1] < 63 and new_rsb(src, 17 )[0] > 63

    one or two or thr or fou



// -------------------------------------------------------------------------- //



// new_cos returns a signal to open a short position. This signals the beginning
// of a trade aiming to profit from downward trends. After opening a short
// position we wait for the close short signal. Here cos means cycle open short.
new_cos() =>
    src = close

    crb = new_crb()
    bbi = new_bbi(src, bbl, bbs)
    hpi = new_hpi(hrb)
    rsi = new_rsi(src)

    bhi = (bbi[0] and hpi[0]) or (bbi[0] and hpi[1]) or (bbi[1] and hpi[0])
    bri = (bbi[0] and rsi[0]) or (bbi[0] and rsi[1]) or (bbi[1] and rsi[0])
    hri = (hpi[0] and rsi[0]) or (hpi[0] and rsi[1]) or (hpi[1] and rsi[0])

    crb and (bhi or bri or hri)

// new_ccs returns a signal to close a short position. This signals the end of a
// trade aiming to profit from downward trends. After closing a short position
// we wait for the open long signal. Here ccs means cycle close short.
new_ccs() =>
    win = 100 - new_per(array.get(FP, 0), close) >= mtp

    win

// new_col returns a signal to open a long position. This signals the beginning
// of a trade aiming to profit from upward trends. After opening a long position
// we wait for the close long signal. Here col means cycle open long.
new_col() =>
    false

// new_ccl returns a signal to close a long position. This signals the end of a
// trade aiming to profit from upward trends. After closing a long position we
// wait for the open short signal. Here clo means cycle close long.
new_ccl() =>
    false



// -------------------------------------------------------------------------- //



cos = (get_ccc() == CL or get_ccc() == CS) and new_cos() == true ? true : false
ccs = get_ccc() == OS and new_ccs() == true ? true : false



// -------------------------------------------------------------------------- //



// On any given cycle change we track the current cycle globally so that we
// always know in which cycle the current trade is in, if any. Note there might
// be no active trades for some time.
set_ccc((get_ccc() == CL or get_ccc() == CS) and cos == true ? OS : get_ccc())
set_ccc(get_ccc() == OS and ccs == true ? CS : get_ccc())

// One bar after the signal switch our bots get instructed to enter a different
// trade cycle. At this point we track the open price because this is the most
// likely price we get when the bots open their deals against the exchanges.
// Note there will always be slippage.
array.set(FP, 0, (cos[1] == true ? open[0] : array.get(FP, 0)))



// -------------------------------------------------------------------------- //



plotshape(cos, text=OS, location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.red,   textcolor=color.white, transp=0)
plotshape(ccs, text=CS, location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.red,   textcolor=color.white, transp=0)
// plotshape(col, text=OL, location=location.belowbar, style=shape.labelup,   size=size.tiny, color=color.green, textcolor=color.white, transp=0)
// plotshape(ccl, text=CL, location=location.belowbar, style=shape.labelup,   size=size.tiny, color=color.green, textcolor=color.white, transp=0)

Overview

BBI HPI RSI calculates BBI using length, standard deviation and pivot settings, detects HPI based on recent bars when current bar is red, and includes RSI. Inputs control trailing stop loss, minimum take profit, BBI parameters and HPI recent bar count. Functions help build conditions for signals on long and short trades.

Details

Published by

blackcat1402 on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Oscillators & momentum, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Trailing Stop Lossfloat0.2tsl
Minimum Take Profitfloat0.2mtp
BBI Lengthint70bbl
BBI Stddevfloat2.65bbs
BBI Pivotfloat20bbp
HPI Recent Barint175hrb
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

The Adaptive RSI Moving Average (ARSIMA) is an overlay indicator that dynamically adjusts its smoothing factor based on the Relative Strength Index (RSI). When the RSI moves toward extreme overbought or oversold conditions, the smoothing factor increases to ma

Indicator v4 Moving averagesOscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive RSI Moving Average

This overlay indicator plots a Supertrend from an ATR length and factor, four exponential moving averages, and a selectable VWAP or TWAP taken from a chosen timeframe on the price chart. It also shows MACD and stochastic with adjustable lengths, smoothing, ver

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup: Vijay Thakare Option Buying Scalping Setup

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]
318 stars

This indicator plots three moving averages on the price chart alongside colored fills between the lines to visualize trend structure. Internally, it calculates a Stochastic RSI oscillator to detect oversold reversals. When the Stochastic %K line rises above 10

Indicator v5 Moving averagesOscillators & momentum
Updated 2 months ago · MIT GitHub repository of TVT 3X Scale In Out
285 stars

Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a

Indicator v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Study

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers