Volume SuperTrend AI Indicator Guide
Volume SuperTrend AI Indicator Guide
0
International (CC BY-NC-SA 4.0) [Link]
// © Zeiierman
//@version=5
//indicator("Volume SuperTrend AI (Expo)", overlay=true)
// ~~ ToolTips {
t1="Number of nearest neighbors in KNN algorithm (k): Increase to consider more
neighbors, providing a more balanced view but possibly smoothing out local
patterns. Decrease for fewer neighbors to make the algorithm more responsive to
recent changes. \n\nNumber of data points to consider (n): Increase for more
historical data, providing a broader context but possibly diluting recent trends.
Decrease for less historical data to focus more on recent behavior."
t2="Length of weighted moving average for price (KNN_PriceLen): Higher values
create a smoother price line, influencing the KNN algorithm to be more stable but
less sensitive to short-term price movements. Lower values enhance responsiveness
in KNN predictions to recent price changes but may lead to more noise. \n\nLength
of weighted moving average for SuperTrend (KNN_STLen): Higher values lead to a
smoother SuperTrend line, affecting the KNN algorithm to emphasize long-term
trends. Lower values make KNN predictions more sensitive to recent SuperTrend
changes but may result in more volatility."
t3="Length of the SuperTrend (len): Increase for a smoother trend line, ideal for
identifying long-term trends but possibly ignoring short-term fluctuations.
Decrease for more responsiveness to recent changes but risk of more false
signals. \n\nMultiplier for ATR in SuperTrend calculation (factor): Increase for
wider bands, capturing larger price movements but possibly missing subtle changes.
Decrease for narrower bands, more sensitive to small shifts but risk of more
noise."
t4="Type of moving average for SuperTrend calculation (maSrc): Choose based on
desired characteristics. SMA is simple and clear, EMA emphasizes recent prices, WMA
gives more weight to recent data, RMA is less sensitive to recent changes, and VWMA
considers volume."
t5="Color for bullish trend (upCol): Select to visually identify upward trends. \n\
nColor for bearish trend (dnCol): Select to visually identify downward trends.\n\
nColor for neutral trend (neCol): Select to visually identify neutral trends."
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
atr = [Link](len)
upperBand = vwma + factor * atr
lowerBand = vwma - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
// ~~ Plot
col = label_ == 1?upCol:label_ == 0?dnCol:neCol
plot(current_superTrend, color=col, title="Volume Super Trend AI")
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Alerts {
alertcondition(Start_TrendUp, title ="1 Bullish Trend Start", message = "AI Bullish
Trend Start")
alertcondition(Start_TrendDn, title ="2 Bearish Trend Start", message = "AI
Bearish Trend Start")
alertcondition((Start_TrendUp or Start_TrendDn), title ="3 Any Trend Start",
message="Any AI Trend Start")
alertcondition(TrendUp, title = "4 Bullish Trend Signal", message = "AI Bullish
Trend Signal")
alertcondition(TrendDn, title = "5 Bearish Trend Signal", message = "AI Bearish
Trend Signal")
alertcondition((TrendUp or TrendDn),title = "6 Any Trend Signal", message ="Any AI
Trend Signal")
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// This source code is subject to the terms of the Mozilla Public License 2.0 at
[Link]
// © LonesomeTheBlue
//@version=5
//indicator('Trend Lines v2', overlay=true, max_bars_back=4000)
startyear = input(defval=2020, title='Start Year')
startmonth = input(defval=1, title='Start Month')
startday = input(defval=1, title='Start day')
prd = [Link](defval=20, title='Pivot Period', minval=10, maxval=50)
PPnum = [Link](defval=3, title='Number of Pivot Points to check', minval=2,
maxval=6)
utcol = [Link](defval=[Link], title='Colors', inline='tcol')
dtcol = [Link](defval=[Link], title='', inline='tcol')
if ph
add_to_array(tval, tpos, ph)
if pl
add_to_array(bval, bpos, pl)
// line definitions
maxline = 3
var bln = array.new_line(maxline, na)
var tln = array.new_line(maxline, na)
if valid
uv1 := hline - diff
uv2 := val2
up1 := lloc
up2 := pos2
break
dv1 = 0.0
dv2 = 0.0
dp1 = 0
dp2 = 0
if countlinehi <= maxline
for p2 = PPnum - 1 to p1 + 1 by 1
val1 = [Link](tval, p1)
val2 = [Link](tval, p2)
pos1 = [Link](tpos, p1)
pos2 = [Link](tpos, p2)
if val1 < val2
diff = (val2 - val1) / float(pos1 - pos2)
hline = val2 - diff
lloc = bar_index
lval = high
valid = true
for x = pos2 + 1 - prd to bar_index by 1
if close[bar_index - x] > hline
valid := false
break
lloc := x
lval := hline
hline -= diff
hline
if valid
dv1 := hline + diff
dv2 := val2
dp1 := lloc
dp2 := pos2
break
//@version=5
//@author=Daveatt
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//////////////////////// Support & Resistances ////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////// ZIGZAG ///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// |--------------------------------------------------------------------------||
// | ZigZag: ||
// |--------------------------------------------------------------------------||
// |{
string percent_description = 'Percent of last pivot price for zigzag reversal:'
string zzrealpivot_description = 'Show real zigzag pivots:'
if _is_direction_up
_htrack := [Link]([Link](high, high[1]), nz(_htrack[1], high))
if [Link](_htrack) > 0 //or na(_htrack[1])
_real_pivot_time := time
_real_pivot_time
_ltrack := na
_reverse_line := _htrack[1] - _reverse_range
if close < _reverse_line
_pivot := _htrack
_is_direction_up := false
_is_direction_up
if not _is_direction_up
_ltrack := [Link]([Link](low, low[1]), nz(_ltrack[1], low))
if [Link](_ltrack) < 0 //or na(_ltrack[1])
_real_pivot_time := time
_real_pivot_time
_htrack := na
_reverse_line := _ltrack[1] + _reverse_range
if close > _reverse_line
_pivot := _ltrack
_is_direction_up := true
_is_direction_up
// || |}---------------------------------------------------------------------<•
// ||-------------------------------------------------------------------------||
// || zigzag data:
// ||-------------------------------------------------------------------------||
// |{
[pivot, is_up, reverse, _rl_time] = f_zz(percent)
zz_color = is_up ? [Link] : [Link]
zz = [Link](pivot) != 0 ? pivot : na
tt = show_real_pivots_zz ? _rl_time : time
//
//plot(zz, title="Z", color=zz_color, linewidth=1, transp=80)
//plot(reverse, title="R", color=[Link], style=plot.style_circles,
linewidth=4, transp=40, offset=1, show_last=1)
// ||-------------------------------------------------------------------------||
// || Pseudo Array Generic code: ID: (__x_)
// |{-------------------------------------------------------------------------<•
// || variable initialization:
var int __x_A00 = na
var int __x_A01 = na
var int __x_A02 = na
var int __x_A03 = na
var int __x_A04 = na
var int __x_A05 = na
var int __x_A06 = na
var int __x_A07 = na
var int __x_A08 = na
var int __x_A09 = na
var int __x_A10 = na
// || |}---------------------------------------------------------------------<•
// ||-------------------------------------------------------------------------||
// || Pseudo Array Generic code: ID: (__y_)
// |{-------------------------------------------------------------------------<•
// || variable initialization:
var float __y_A00 = na
var float __y_A01 = na
var float __y_A02 = na
var float __y_A03 = na
var float __y_A04 = na
var float __y_A05 = na
var float __y_A06 = na
var float __y_A07 = na
var float __y_A08 = na
var float __y_A09 = na
var float __y_A10 = na
// || |}---------------------------------------------------------------------<•
// | Get Extremes:
// float a_y = valuewhen(zz, zz, show_previous + 0)
// int a_x = round(valuewhen(zz, tt, show_previous + 0))
// float b_y = valuewhen(zz, zz, show_previous + 1)
// int b_x = round(valuewhen(zz, tt, show_previous + 1))
f_y(_i) =>
[Link](zz, zz, _i)
f_x(_i) =>
[Link](zz, tt, _i)
if zz
if na(f__y_AGET(1))
__x_AMODE := 'push'
__y_AMODE := 'push'
__x_ASET := tt
__y_ASET := zz
__y_ASET
else
//higher high
if f_y(0) > f_y(1) and f_y(0) > f_y(2)
if f__y_AGET(0) < f__y_AGET(1)
__x_AMODE := 'push'
__y_AMODE := 'push'
__x_ASET := tt
__y_ASET := zz
__y_ASET
else
__x_AMODE := 'replace'
__y_AMODE := 'replace'
__x_ASET := tt
__y_ASET := zz
__y_ASET
//higher low
if f_y(0) < f_y(1) and f_y(0) < f_y(2)
if f__y_AGET(0) > f__y_AGET(1)
__x_AMODE := 'push'
__y_AMODE := 'push'
__x_ASET := tt
__y_ASET := zz
__y_ASET
else
__x_AMODE := 'replace'
__y_AMODE := 'replace'
__x_ASET := tt
__y_ASET := zz
__y_ASET
// |{-------------------------------------------------------------------------<•
// || update array: (ID´: _x)
// || • this must/should be right after event.
// || • if theres more than one event per bar the code bellow must be
// || repeated to update the array. its possible to change f___x_ASET()
// || so that you can update multiple positions if they dont interact
if not na(__x_ASET)
__x_A10 := f__x_ASET(__x_ASET, 10, __x_ALEN, __x_AMODE)
__x_A09 := f__x_ASET(__x_ASET, 09, __x_ALEN, __x_AMODE)
__x_A08 := f__x_ASET(__x_ASET, 08, __x_ALEN, __x_AMODE)
__x_A07 := f__x_ASET(__x_ASET, 07, __x_ALEN, __x_AMODE)
__x_A06 := f__x_ASET(__x_ASET, 06, __x_ALEN, __x_AMODE)
__x_A05 := f__x_ASET(__x_ASET, 05, __x_ALEN, __x_AMODE)
__x_A04 := f__x_ASET(__x_ASET, 04, __x_ALEN, __x_AMODE)
__x_A03 := f__x_ASET(__x_ASET, 03, __x_ALEN, __x_AMODE)
__x_A02 := f__x_ASET(__x_ASET, 02, __x_ALEN, __x_AMODE)
__x_A01 := f__x_ASET(__x_ASET, 01, __x_ALEN, __x_AMODE)
__x_A00 := f__x_ASET(__x_ASET, 00, __x_ALEN, __x_AMODE)
__x_A00
// || |}---------------------------------------------------------------------<•
// |{-------------------------------------------------------------------------<•
// || update array: (ID´: _x)
// || • this must/should be right after event.
// || • if theres more than one event per bar the code bellow must be
// || repeated to update the array. its possible to change f___y_ASET()
// || so that you can update multiple positions if they dont interact
if not na(__y_ASET)
__y_A10 := f__y_ASET(__y_ASET, 10, __y_ALEN, __y_AMODE)
__y_A09 := f__y_ASET(__y_ASET, 09, __y_ALEN, __y_AMODE)
__y_A08 := f__y_ASET(__y_ASET, 08, __y_ALEN, __y_AMODE)
__y_A07 := f__y_ASET(__y_ASET, 07, __y_ALEN, __y_AMODE)
__y_A06 := f__y_ASET(__y_ASET, 06, __y_ALEN, __y_AMODE)
__y_A05 := f__y_ASET(__y_ASET, 05, __y_ALEN, __y_AMODE)
__y_A04 := f__y_ASET(__y_ASET, 04, __y_ALEN, __y_AMODE)
__y_A03 := f__y_ASET(__y_ASET, 03, __y_ALEN, __y_AMODE)
__y_A02 := f__y_ASET(__y_ASET, 02, __y_ALEN, __y_AMODE)
__y_A01 := f__y_ASET(__y_ASET, 01, __y_ALEN, __y_AMODE)
__y_A00 := f__y_ASET(__y_ASET, 00, __y_ALEN, __y_AMODE)
__y_A00
// || |}---------------------------------------------------------------------<•
// || |}---------------------------------------------------------------------<•
// ||-------------------------------------------------------------------------||
// || Draw the zigzag (abcdefg) lines:
// ||-------------------------------------------------------------------------||
// |{
color col1 = [Link](13, 139, 51, 28) //[Link]
color col2 = [Link](241, 23, 23, 44) //[Link]
line_width = 2
var line _li = na
_li_color = f__y_AGET(0) > f__y_AGET(1) ? col1 : col2
if showZZ
[Link](_li)
_li := [Link](x1=f__x_AGET(0), y1=f__y_AGET(0), x2=f__x_AGET(1),
y2=f__y_AGET(1), xloc=xloc.bar_time, extend=[Link], color=_li_color,
style=line.style_solid, width=line_width)