Indicator · Pine Script v5 · On the chart

Barbwire v1.0.0

by itmakesyousick· code credited to boitoki

Looks for barbwire zones, runs of bars with unusually small ranges, and boxes them on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code128
Settings12inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago9 Jul 2022

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

128 lines of Pine Script v5 from 1.0.0.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

1.0.0.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © boitoki

//@version=5
indicator("Barbwire", overlay=true, precision=2, max_boxes_count=200, max_lines_count=200)

import boitoki/VolatilityChecker/2 as v

//////////////
// FUNCTION //

f_renderBox (_show, _start, _processing, _end, _mode, _min, _show_extend, _extend, _border_width, _border_color, _bgcolor) =>
    var box barb_box = na
    var line top = na
    var line bot = na
    var float y1 = na
    var float y2 = na
    line_style = line.style_dotted

    if _mode == 'osc'
        y1 := 100.0
        y2 := 0.0

    if _start
        y1 := _mode == 'chart' ? high : y1
        y2 := _mode == 'chart' ? low  : y2
        barb_box := box.new(bar_index, y1, bar_index, y2, _border_color, _border_width, line.style_solid, bgcolor=_bgcolor)
    
    if _processing
        y1 := _mode == 'chart' ? math.max(y1, high) : y1
        y2 := _mode == 'chart' ? math.min(y2, low)  : y2
        box.set_top(barb_box, y1)
        box.set_bottom(barb_box, y2)
        box.set_right(barb_box, bar_index)
    
    if _end
        box.set_right(barb_box, bar_index)
        
        width = math.abs(box.get_right(barb_box) - box.get_left(barb_box))

        if width < _min
            box.delete(barb_box)
        
        if _show_extend and width >= _min
            x1 = bar_index 
            x2 = bar_index + math.round(width * _extend)
            //p  = syminfo.mintick * 10 * 2
            //line.new(x1, y1 + p, x2, y1 + p, color=_border_color, width=1, style=line_style)
            //line.new(x1, y2 - p, x2, y2 - p, color=_border_color, width=1, style=line_style)
            box.new(x1, y1, x2, y2, _border_color, 1, line_style, bgcolor=color.new(_bgcolor, 96))

        y1 := na, y2 := na


barb_func (_len) =>
    [v_open, v_close] = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, [open, close])

    oc_width = math.abs(v_open - hlc3)
    hl_width = math.abs(high - low)

    oc = ta.sma(ta.stoch(oc_width, oc_width, oc_width, _len), 1)
    hl = ta.sma(ta.stoch(hl_width, hl_width, hl_width, math.round(_len * 0.3)), 1)

    [oc, hl]

////////////
// INPUTS //

i_len = input.int(50, 'Period')
i_lv = input.int(20, 'Level', minval=1)
i_min = input.int(3, 'Min period', minval=0)
i_calc_by_option1 = 'Open/Close'
i_calc_by_option2 = 'with High/Low'
i_calc_by = str.lower(input.string(i_calc_by_option2, 'Calculated by', options=[i_calc_by_option1, i_calc_by_option2], inline='calc'))
i_use_voc = input.bool(false, 'VolatilityChecker', inline='calc')
i_mode = 'chart' //input.string('chart', 'Mode', options=['osc', 'chart'])
i_show_extend = input.bool(false, 'Box extend', inline='extend')
i_extend = input.float(1.6, '', minval=1.0, step=0.1, inline='extend')

i_border_width = input.int(2, 'Border width', minval=0, group='style')
i_boxcolor = input.color(color.new(color.orange, 20), 'Box color', group='style')
i_bgcolor = input.color(color.new(color.orange, 80), 'Box bg color', group='style')

i_show_barcolor = input.bool(false, 'Bar color', group='options', inline='barcolor')
i_barcolor = input.color(color.white, '', group='options', inline='barcolor')

//////////
// CALC //
[oc_barb, hl_barb] = barb_func(i_len)
avg_barb = math.avg(oc_barb, oc_barb, oc_barb, oc_barb, hl_barb)
v_is_low_volatility = v.is_low(7, 3, 20, 2)

////////////////
// CONDITIONS //

is_barb = oc_barb <= i_lv

if i_calc_by == str.lower(i_calc_by_option2)
    is_barb := is_barb and hl_barb <= i_lv

if i_use_voc
    is_barb := is_barb and v_is_low_volatility

barb_start  = is_barb and (not is_barb[1])
barb_end    = (not is_barb) and is_barb[1]

alertcondition(barb_start, "Barb wire start", "Barb wire start")
alertcondition(barb_end, "Barb wire end", "Barb wire end")

///////////////
// RENDERING //

f_renderBox(true, barb_start, is_barb, barb_end, i_mode, i_min, i_show_extend, i_extend, i_border_width, i_boxcolor, i_bgcolor)

barcolor(i_show_barcolor and is_barb ? i_barcolor : na)

//////////////
// PLOTTING //

col = is_barb ? color.gray : color.aqua
plot_display = display.none

plot(hl_barb, 'HL', style=plot.style_columns, color=color.new(col, 80), display=plot_display)
plot(oc_barb, 'OC', style=plot.style_columns, color=col, display=plot_display)
plot(ta.wma(ta.ema(avg_barb, 5), 3), color=color.maroon, linewidth=2, display=plot_display)

hline(i_lv, linestyle=hline.style_dotted, display=plot_display)
hline( 0, linestyle=hline.style_solid, display=plot_display)

Overview

Barbwire v1.0.0 measures how small recent bars are using Heikin-Ashi data, scaled over a period with a level threshold and a minimum number of bars. Settings choose open and close or high and low measurement, an optional volatility checker library, box extension, colours and bar colouring. It describes a quiet market, not a direction.

Details

Published by

itmakesyousick on GitHub

Code credit

boitoki, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Candlestick patterns, Volatility & bands

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.

Topics

pinescript

Settings

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

SettingTypeDefaultVariable
Periodint50i_len
Levelint20i_lv
Min periodint3i_min
Calculated bystringi_calc_by_option2Calculated by
VolatilityCheckerboolfalsei_use_voc
Box extendboolfalsei_show_extend
i_extendfloat1.6i_extend
Border widthint2i_border_width
Box colorcolorcolor.new(color.orange, 20)i_boxcolor
Box bg colorcolorcolor.new(color.orange, 80)i_bgcolor
Bar colorboolfalsei_show_barcolor
i_barcolorcolorcolor.whitei_barcolor
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

Body Mass Indicator

by harryguiacorn
219 stars

The Body Mass Indicator highlights candles with exceptionally large body ranges relative to recent price movement. It calculates the absolute distance between open and close prices. When enabled, it identifies bars where the body range achieves a new high over

Indicator v5 Volatility & bandsCandlestick patterns
Updated 1 year ago · None stated GitHub repository of Body Mass Indicator

Raschke Patterns

by TradersPost
218 stars

This overlay indicator marks Linda Raschke short-term bar setups on the price chart. It flags Turtle Soup and Turtle Soup plus one false breakouts of a prior extreme, 80-20 bars, inside bars, failed inside-bar breakouts, outside up and down bars, NR4 and NR7 c

Indicator v6 Candlestick patternsBreakout Repaints
Updated 3 months ago · None stated GitHub repository of Raschke Patterns

Five-in-one Strategy

by capissimo
114 stars

Five-in-one Strategy combines five analytical tools into a single price chart overlay: the Dual Thrust Trading Algorithm (DTTA), Semafore, HalfTrend, Nick Rypock Trailing Reverse, and Tweezer or Kangaroo Tail candlestick patterns. It generates trade signals us

Indicator v4 TrendBreakout Repaints
Updated 1 year ago · None stated GitHub repository of Five-in-one Strategy

Force Bar

by milocaetano
48 stars

Force Bar highlights candlesticks directly on the price chart using three distinct body and range criteria: widest range (Biggest), extreme body relative to historical average (Exhaustion), and moderate body relative to historical average (Force). Colors apply

Indicator v5 Candlestick patternsVolatility & bands
Updated 2 days ago · MIT GitHub repository of Force Bar

Zen Z Bars V1

by Zen-Tim
29 stars

Zen Z Bars V1 analyzes bar-by-bar price action, candle range expansion, and internal bar strength (IBS). It identifies breakouts, inside and outside bars, climax candles based on range expansion factors, and tiered range multiple bars. The indicator draws brea

Indicator v5 Candlestick patternsBreakout
Updated 2 weeks ago · MIT GitHub repository of Zen Z Bars V1
15 stars

This indicator plots Bollinger Bands and smoothed HAMA candles on the price chart. It builds each candle from separate moving averages of open, high, low and close, using selectable EMA, SMA or WMA lengths. A simple moving average forms the band basis, and an

Indicator v5 Candlestick patternsMoving averages
Updated 4 months ago · Apache-2.0 GitHub repository of NSDT HAMA Candles with Bollinger Bands

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