// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pwb2008
//@version=6
indicator(shorttitle="BB with slow MA", title="Bollinger Bands with 2 MA", overlay=true, timeframe="", timeframe_gaps=true)
// ----- Bollinger Bands -----
// Parámetros de las Bandas de Bollinger
length = input.int(20, minval=1)
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
// Función para calcular MA
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
// Cálculo de las Bandas de Bollinger
basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500, display = display.data_window)
// Plot de las Bandas de Bollinger
plot(basis, "Basis", color=color.new(#2962FF, 100-10), offset=offset)
pl1 = plot(upper, "Upper", color=color.new(#00BCD4,100-20), offset=offset)
pl2 = plot(lower, "Lower", color=color.new(#00BCD4,100-20), offset=offset)
fill(pl1, pl2, title="Background", color=color.rgb(33, 150, 243, 98))
// ----------------- EMAs ------------------
// Parámetros de las Medias Móviles
p1 = input.int(52, minval=1, title="Anual 52")
p2 = input.int(104, minval=1, title="Bianual 104")
p4 = input.int(208, minval=1, title="Cuatrienal 208")
p6 = input.int(312, minval=1, title="Sextenial 312")
p8 = input.int(416, minval=1, title="Octorrenial 416")
p10 = input.int(520, minval=1, title="Decenal 520")
// Cálculo de EMAs
e1 = ta.ema(close, p1)
e2 = ta.ema(close, p2)
e4 = ta.ema(close, p4)
e6 = ta.ema(close, p6)
e8 = ta.ema(close, p8)
e10 = ta.ema(close, p10)
// Plot de las Medias Móviles
plot(e1, color=color.new(#E91E63, 10), linewidth=1, title="Anual")
plot(e2, color=color.new(#9C27B0, 10), linewidth=1, title="Bianual")
plot(e4, color=color.new(#673AB7, 10), linewidth=1, title="Cuatrienal")
plot(e6, color=color.new(#2962FF, 10), linewidth=1, title="Sextenial")
plot(e8, color=color.new(#089981, 10), linewidth=1, title="Octorrenial")
plot(e10, color=color.new(#FF9800, 10), linewidth=1, title="Decenal")
//
// @author PIERRE
//
study(title="Multi Indicators- MA 200",shorttitle="Multi Indicator Pierre", overlay=true)
slowPeriods = input(200, minval=1, title="Slow Periods")
sSlow = sma(close, slowPeriods)
eSlow = ema(close, slowPeriods)
plot(eSlow, color = blue, linewidth=2, title="Slow EMA")
//=========================================================================
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Violent
//@version=4
study("Stochastic Candles", shorttitle="SC", overlay=true)
_source = close
MA = input(title="MA", options=["SMA", "EMA", "WMA"], defval="EMA")
Theme = input(title="Theme", options=["Theme 1", "Theme 2", "Theme 3"], defval="Theme 3")
inc = input(title="Start", defval=10)
plotNumber= input(title="End", defval=28, minval=1, maxval=28, type=input.integer)
smooth = input(title="Smooth", defval=2, type=input.integer)
trans = 0
cp1 = color.new(#01ff00, trans)
cp2 = color.new(#05d904, trans)
cp3 = color.new(#04b504, trans)
cp4 = color.new(#039103, trans)
cp5 = color.new(#027502, trans)
cn1 = color.new(#ff0505, trans)
cn2 = color.new(#d60606, trans)
cn3 = color.new(#b80606, trans)
cn4 = color.new(#910303, trans)
cn5 = color.new(#750202, trans)
cp6 = color.new(#00ddff, trans)
cp7 = color.new(#04bcd9, trans)
cp8 = color.new(#049cb3, trans)
cp9 = color.new(#047f91, trans)
cp10 = color.new(#046775, trans)
cn6 = color.new(#d800ff, trans)
cn7 = color.new(#bb04db, trans)
cn8 = color.new(#9b05b5, trans)
cn9 = color.new(#7b038f, trans)
cn10 = color.new(#640275, trans)
cp11 = color.new(#cf0000, trans)
cp12 = color.new(#f25811, trans)
cp13 = color.new(#f29811, trans)
cp14 = color.new(#eef211, trans)
cp15 = color.new(#3af211, trans)
cn11 = color.new(#02269e, trans)
cn12 = color.new(#0f44f5, trans)
cn13 = color.new(#1176f2, trans)
cn14 = color.new(#0093c9, trans)
cn15 = color.new(#11e7f2, trans)
pColour1 = Theme == "Theme 1" ? cp1 : Theme == "Theme 2" ? cp6 : cp11
pColour2 = Theme == "Theme 1" ? cp2 : Theme == "Theme 2" ? cp7 : cp12
pColour3 = Theme == "Theme 1" ? cp3 : Theme == "Theme 2" ? cp8 : cp13
pColour4 = Theme == "Theme 1" ? cp4 : Theme == "Theme 2" ? cp9 : cp14
pColour5 = Theme == "Theme 1" ? cp5 : Theme == "Theme 2" ? cp10 : cp15
nColour1 = Theme == "Theme 1" ? cn1 : Theme == "Theme 2" ? cn6 : cn11
nColour2 = Theme == "Theme 1" ? cn2 : Theme == "Theme 2" ? cn7 : cn12
nColour3 = Theme == "Theme 1" ? cn3 : Theme == "Theme 2" ? cn8 : cn13
nColour4 = Theme == "Theme 1" ? cn4 : Theme == "Theme 2" ? cn9 : cn14
nColour5 = Theme == "Theme 1" ? cn5 : Theme == "Theme 2" ? cn10 : cn15
getColour(a) =>
if(a >= 90)
pColour1
else
if(a >= 80)
pColour2
else
if(a >= 70)
pColour3
else
if(a >= 60)
pColour4
else
if(a >= 50)
pColour5
else
if(a >= 40)
nColour5
else
if(a >= 30)
nColour4
else
if(a >= 20)
nColour3
else
if(a >= 10)
nColour2
else
if(a >= 0)
nColour1
getStoch(i) =>
c = (i * inc)
if MA == "SMA"
sma(stoch(_source, high, low, c), smooth)
else
if MA == "EMA"
ema(stoch(_source, high, low, c), smooth)
else
if MA == "WMA"
wma(stoch(_source, high, low, c), smooth)
stoch1 = plotNumber > 0 ? getStoch(1 ) : 0
stoch2 = plotNumber > 1 ? getStoch(2 ) : 0
stoch3 = plotNumber > 2 ? getStoch(3 ) : 0
stoch4 = plotNumber > 3 ? getStoch(4 ) : 0
stoch5 = plotNumber > 4 ? getStoch(5 ) : 0
stoch6 = plotNumber > 5 ? getStoch(6 ) : 0
stoch7 = plotNumber > 6 ? getStoch(7 ) : 0
stoch8 = plotNumber > 7 ? getStoch(8 ) : 0
stoch9 = plotNumber > 8 ? getStoch(9 ) : 0
stoch10 = plotNumber > 9 ? getStoch(10) : 0
stoch11 = plotNumber > 10 ? getStoch(11) : 0
stoch12 = plotNumber > 11 ? getStoch(12) : 0
stoch13 = plotNumber > 12 ? getStoch(13) : 0
stoch14 = plotNumber > 13 ? getStoch(14) : 0
stoch15 = plotNumber > 14 ? getStoch(15) : 0
stoch16 = plotNumber > 15 ? getStoch(16) : 0
stoch17 = plotNumber > 16 ? getStoch(17) : 0
stoch18 = plotNumber > 17 ? getStoch(18) : 0
stoch19 = plotNumber > 18 ? getStoch(19) : 0
stoch20 = plotNumber > 19 ? getStoch(20) : 0
stoch21 = plotNumber > 20 ? getStoch(21) : 0
stoch22 = plotNumber > 21 ? getStoch(22) : 0
stoch23 = plotNumber > 22 ? getStoch(23) : 0
stoch24 = plotNumber > 23 ? getStoch(24) : 0
stoch25 = plotNumber > 24 ? getStoch(25) : 0
stoch26 = plotNumber > 25 ? getStoch(26) : 0
stoch27 = plotNumber > 26 ? getStoch(27) : 0
stoch28 = plotNumber > 27 ? getStoch(28) : 0
getAverage = (stoch1 + stoch2 + stoch3 + stoch4 + stoch5 + stoch6 + stoch7 + stoch8 + stoch9 + stoch10 + stoch11 + stoch12 + stoch13 + stoch14 + stoch15 + stoch16 + stoch17 + stoch18 + stoch19 + stoch20 + stoch21 + stoch22 + stoch23 + stoch24 + stoch25 + stoch26 + stoch27 + stoch28) / plotNumber
barColour = getColour(getAverage)
barcolor(barColour)
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kv4coins
//@version=6
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// INDICATOR
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
indicator(title = 'Volume Profile', shorttitle = 'VP', overlay = true, max_bars_back = 5000, max_lines_count = 500)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// INPUTS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
vp_use_visible_range = input.bool(
defval = false,
title = 'Use Visible Range',
group = 'Lookback Period',
tooltip = 'Calculate Volume Profile using all visible bars in the current chart'
)
vp_lookback_depth = input.int(
defval = 200,
minval = 10,
maxval = 3000,
title = 'Fixed Range Lookback Depth [10-3000]',
group = 'Lookback Period',
tooltip = 'Number of historical bars to include in the calculation. Ignored if "Use Visible Range" is enabled'
)
vp_num_bars = input.int(
defval = 200,
minval = 10,
maxval = 490,
title = 'Number of Volume Bars [10-490]',
group = 'Volume Bars',
tooltip = 'Number of Volume Profile bars'
)
vp_bar_thickness = input.int(
defval = 1,
minval = 1,
maxval = 30,
title = 'Volume Bar Thickness [1-30]',
group = 'Volume Bars',
tooltip = 'Width of each volume bar in the Volume Profile'
)
vp_bar_len_mult = input.int(
defval = 20,
minval = 1,
maxval = 50,
title = 'Bar Length Multiplier [1-50]',
group = 'Volume Bars',
tooltip = 'Volume Profile Bar length multiplier'
)
vp_right_offset = input.int(
defval = 70,
minval = 0,
maxval = 400,
title = 'Right Offset [0-400]',
group = 'Volume Bars',
tooltip = 'Space between the right bar of the chart and the Volume Profile'
)
vp_volume_type = input.string(
defval = 'Both',
title = 'Volume Type',
options = ['Both', 'Bullish', 'Bearish'],
group = 'Volume Bars',
tooltip = 'Select the type of Volume to include'
)
vp_bar_color = input.color(
defval = color.new(color.gray, 50),
title = 'Volume Bar Color',
group = 'Volume Bars',
tooltip = 'Color of the volume bars in the Volume Profile'
)
vp_display_poc = input.bool(
defval = true,
title = 'Display Point of Control (PoC)',
group = 'Point of Control',
tooltip = 'Enable or disable the display of the Point of Control (PoC)'
)
vp_poc_line_thickness = input.int(
defval = 1,
minval = 1,
maxval = 30,
title = 'PoC Line Thickness [1-30]',
group = 'Point of Control',
tooltip = 'Width of the PoC line'
)
vp_poc_line_color = input.color(
defval = color.red,
title = 'PoC Line Color',
group = 'Point of Control',
tooltip = 'Color of the Point of Control (PoC) line'
)
vp_display_va = input.bool(
defval = true,
title = 'Display Value Area',
group = 'Value Area',
tooltip = 'Enable or disable the display of the Value Area'
)
vp_va_percent = input.int(
defval = 68,
minval = 5,
maxval = 95,
title = 'Value Area Percentage(%) [5-95]',
group = 'Value Area',
tooltip = 'Percentage of the Value Area'
)
vp_va_bar_color = input.color(
defval = color.blue,
title = 'Value Area Bar Color',
group = 'Value Area',
tooltip = 'Color of the volume bars in the Value Area'
)
vp_display_va_lines = input.bool(
defval = true,
title = 'Display Value Area Lines',
group = 'Value Area',
tooltip = 'Enable or disable the display of the Value Area lines. Ignored if "Display Value Area" is disabled'
)
vp_va_lines_thickness = input.int(
defval = 1,
minval = 1,
maxval = 20,
title = 'Value Area Lines Thickness [1-20]',
group = 'Value Area',
tooltip = 'Width of the Value Area lines'
)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// VARIABLES
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var int timeframe_minutes = 1000 * timeframe.in_seconds()
var int lookback_bars = vp_use_visible_range ? math.round((last_bar_time - chart.left_visible_bar_time) / timeframe_minutes) : vp_lookback_depth
var line poc = na
var line vah = na
var line val = na
var array<line> bars = array.new_line()
var array<float> volumes = array.new_float(vp_num_bars, 0)
float highest_price = ta.highest(lookback_bars)
float lowest_price = ta.lowest(lookback_bars)
float price_interval = (highest_price - lowest_price) / (vp_num_bars - 1)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
scale_volume(vol, max) =>
float d = max / lookback_bars / (vp_bar_len_mult / 100)
int scaled_vol = math.round(vol / d)
scaled_vol
calculate_vp() =>
array.fill(volumes, 0)
for i = 0 to (lookback_bars - 1)
for j = 0 to (vp_num_bars - 1)
float price_level = lowest_price + price_interval * j
bool is_bullish = close[i] >= open[i]
bool include_vol = vp_volume_type == 'Both' ? true : (vp_volume_type == 'Bullish' ? is_bullish : not is_bullish)
if (price_level >= low[i] and price_level < high[i] and include_vol)
array.set(volumes, j, volumes.get(j) + volume[i])
calculate_va(int max_idx, float max_vol) =>
float sum_vol = volumes.sum()
float va_vol = sum_vol * vp_va_percent / 100
int va_up = max_idx
int va_dn = max_idx
float va_sum = max_vol
while va_sum < va_vol
float v_up = (va_up < vp_num_bars - 1) ? volumes.get(va_up + 1) : 0.0
float v_dn = (va_dn > 0) ? volumes.get(va_dn - 1) : 0.0
if v_up == 0 and v_dn == 0
break
if v_up >= v_dn
va_sum += v_up
va_up += 1
else
va_sum += v_dn
va_dn -= 1
[va_dn, va_up]
draw() =>
float max_vol = volumes.max()
int max_idx = volumes.indexof(max_vol)
int x2 = bar_index + vp_right_offset
for i = 0 to (vp_num_bars - 1)
int vol = scale_volume(volumes.get(i), max_vol)
int x1 = x2 - vol
float y = lowest_price + price_interval * i
line.set_xy1(bars.get(i), x1, y)
line.set_xy2(bars.get(i), x2, y)
line.set_color(bars.get(i), max_idx == i ? vp_poc_line_color : vp_bar_color)
if vp_display_poc
int vol = scale_volume(max_vol, max_vol)
int poc_x1 = bar_index - lookback_bars
int poc_x2 = x2 - vol - 10
float y = lowest_price + price_interval * max_idx
line.set_xy1(poc, poc_x1, y)
line.set_xy2(poc, poc_x2, y)
if vp_display_va
[va_dn, va_up] = calculate_va(max_idx, max_vol)
for i = va_dn to va_up
if i != max_idx
line.set_color(bars.get(i), vp_va_bar_color)
if vp_display_va_lines
int vah_vol = scale_volume(volumes.get(va_up), max_vol)
int val_vol = scale_volume(volumes.get(va_dn), max_vol)
int va_x1 = bar_index - lookback_bars
int vah_x2 = x2 - vah_vol - 10
int val_x2 = x2 - val_vol - 10
float vah_y1 = lowest_price + price_interval * va_up
float val_y1 = lowest_price + price_interval * va_dn
line.set_xy1(vah, va_x1, vah_y1)
line.set_xy1(val, va_x1, val_y1)
line.set_xy2(vah, vah_x2, vah_y1)
line.set_xy2(val, val_x2, val_y1)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// CALCULATIONS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if barstate.isfirst
for i = 0 to (vp_num_bars - 1)
array.push(bars, line.new(x1 = bar_index, y1 = close, x2 = bar_index, y2 = close, width = vp_bar_thickness))
if vp_display_poc
poc := line.new(x1 = bar_index, y1 = close, x2 = bar_index, y2 = close, color = vp_poc_line_color, width = vp_poc_line_thickness)
if vp_display_va and vp_display_va_lines
vah := line.new(x1 = bar_index, y1 = close, x2 = bar_index, y2 = close, color = vp_va_bar_color, width = vp_va_lines_thickness)
val := line.new(x1 = bar_index, y1 = close, x2 = bar_index, y2 = close, color = vp_va_bar_color, width = vp_va_lines_thickness)
if barstate.islast
calculate_vp()
draw()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// END
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////