//@version=4
// Copyright (c) 2021-present, Alex Orekhov (everget)
// Gaps % Size Distribution script may be freely distributed under the terms of GPL-3.0 license.
var int MAX_OBJECTS_COUNT = 500
study("Gaps % Size Distribution", max_lines_count=MAX_OBJECTS_COUNT, max_labels_count=MAX_OBJECTS_COUNT)
var bool reboot = input(title="Reboot (Click in case of any error)", defval=false)
// var bool useDate = input(title="", defval=false, inline=dateInline)
// int startDate = input(title="Start Aggregation from", type=input.time, defval=timestamp("01 Jan 2019 00:00"), inline=dateInline)
var float binningStep = input(title="Binning Step", type=input.float, minval=0.0001, defval=0.25, step=0.005)
var int maxColumns = input(title="Columns Number (Max: 500)", minval=2, maxval=500, defval=300)
var int columnWidth = input(title="Columns Width", defval=12)
var bool showLabels = input(title="Show Labels", defval=true)
var int nthLabel = input(title="Show Each Nth Label", minval=1, defval=5)
//------------------------------------------------------------------------------
// var int firstTime = time
// startCondition = useDate ? time(timeframe.period) >= min(firstTime, startDate) : true
var color columnColor = #ffb74d
var color labelColor = #1e90ff
var color labelTextColor = color.white
var int sizeLimit = floor(maxColumns / 2)
var int[] posValues = array.new_int(sizeLimit, 0)
var label[] posLabels = array.new_label(sizeLimit, na)
var int[] negValues = array.new_int(sizeLimit, 0)
var label[] negLabels = array.new_label(sizeLimit, na)
//------------------------------------------------------------------------------
_roc(current, basis) =>
out = 100 * (current / basis - 1)
out
_str(value, decimals) =>
out = tostring(value, "#")
out :=
decimals == 1 ? tostring(value, "#.#") :
decimals == 2 ? tostring(value, "#.##") :
decimals == 3 ? tostring(value, "#.###") :
decimals == 4 ? tostring(value, "#.####") :
decimals == 5 ? tostring(value, "#.#####") :
decimals == 6 ? tostring(value, "#.######") :
decimals == 7 ? tostring(value, "#.#######") :
decimals == 8 ? tostring(value, "#.########") :
decimals == 9 ? tostring(value, "#.#########") :
decimals == 10 ? tostring(value, "#.##########") :
decimals == 11 ? tostring(value, "#.###########") :
decimals == 12 ? tostring(value, "#.############") :
decimals == 13 ? tostring(value, "#.#############") :
decimals == 14 ? tostring(value, "#.##############") :
decimals == 15 ? tostring(value, "#.###############") :
decimals == 16 ? tostring(value, "#.################") :
out
out
_format(value1, value2, decimals) =>
out = _str(value1, decimals) + "%" + "\n-\n" + _str(value2, decimals) + "%"
out
_labelText(value1, value2) =>
out =
binningStep < 0.001 ? _format(value1, value2, 4) :
binningStep < 0.01 ? _format(value1, value2, 3) :
_format(value1, value2, 2)
out
_line(x, y) =>
barTime = time[x]
line l = line.new(
x1=barTime,
y1=0,
x2=barTime,
y2=y,
xloc=xloc.bar_time,
width=columnWidth,
color=columnColor
)
line.delete(l[1])
out = l
out
_label(x, y, side, labelText, tooltipText) =>
barTime = time[x]
labelStyle = side == -1 ? label.style_label_up : label.style_label_down
label l = label.new(
x=barTime,
y=y,
xloc=xloc.bar_time,
tooltip=tooltipText,
text=labelText,
textcolor=labelTextColor,
color=labelColor,
style=labelStyle,
size=size.small
)
label.delete(l[1])
out = l
out
//------------------------------------------------------------------------------
isGapUp = close[1] < open
isGapDown = close[1] > open
size = _roc(open, close[1])
if isGapUp// and startCondition
for i = 0 to sizeLimit - 1
if i * binningStep <= size and size < (i + 1) * binningStep
array.set(posValues, i, array.get(posValues, i) + 1)
if isGapDown// and startCondition
for i = 0 to sizeLimit - 1
if -(i + 1) * binningStep < size and size <= -i * binningStep
array.set(negValues, i, array.get(negValues, i) + 1)
if barstate.islast
for i = 0 to array.size(posValues) - 1
posStart = sizeLimit - i
negStart = sizeLimit + 1 + i
posValue = array.get(posValues, i)
negValue = array.get(negValues, i)
_line(posStart, posValue)
_line(negStart, negValue)
if showLabels
posLabel = array.get(posLabels, i)
posText = _labelText(i * binningStep, (i + 1) * binningStep)
posTooltip = tostring(posValue, "#")
negLabel = array.get(negLabels, i)
negText = _labelText(-i * binningStep, -(i + 1) * binningStep)
negTooltip = tostring(negValue, "#")
if i % nthLabel == 0
if na(negLabel)
negLabel := _label(negStart, 0, -1, negText, negTooltip)
array.set(negLabels, i, negLabel)
else
label.set_x(negLabel, time[negStart])
label.set_text(negLabel, negText)
label.set_tooltip(negLabel, negTooltip)
if na(posLabel)
posLabel := _label(posStart, 0, -1, posText, posTooltip)
array.set(posLabels, i, posLabel)
else
label.set_x(posLabel, time[posStart])
label.set_text(posLabel, posText)
label.set_tooltip(posLabel, posTooltip)
Overview
Gaps % Size Distribution measures each gap as a percentage change, then counts how often those sizes fall into positive and negative bins. Columns show the count in each bin, and optional labels mark the bin ranges. The binning step sets each range width, while column count, width, and label spacing control the display. A reboot input resets the calculation if an error occurs. It does not generate trade signals.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Reboot (Click in case of any error)
bool
false
reboot
Binning Step
float
0.25
binningStep
Columns Number (Max: 500)
int
300
maxColumns
Columns Width
int
12
columnWidth
Show Labels
bool
true
showLabels
Show Each Nth Label
int
5
nthLabel
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.
This indicator calculates momentum setups based on the Relative Strength Index (RSI) and plots in a separate pane. It offers multiple scanning modes such as Continuous Break, Continuous Retracement, Flip Break, Flip Retracement, and both regular and hidden div
Range Volume Change compares volume inside a chosen session window with the same window on the previous day and plots that change as a percentage. It accumulates volume during the window and, when enabled, volume outside it, drawing growing columns in a separa
This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome
This indicator plots the Average Directional Index in a separate pane and colors the line teal or maroon according to whether plus DI is above minus DI. A horizontal key level and a silver background mark periods when ADX exceeds that threshold. With labels en
The Mojito v3 Strategy indicator evaluates volatility term structure by calculating the ratio between front-month and second-month VIX futures contracts. It smooths this ratio using a configurable median filter and compares the result against user-defined uppe
This script defines a helper function to generate colors via triangular interpolation using TradingView's color.from_gradient. The function blends between minimum, mid, and maximum color points based on an input value. It applies the function to the RSI indica