0% found this document useful (0 votes)
76 views14 pages

Volume SuperTrend AI Indicator Guide

Uploaded by

borsa240411
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views14 pages

Volume SuperTrend AI Indicator Guide

Uploaded by

borsa240411
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.

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."
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Input settings for K and N values


k = [Link](3, title = "Neighbors", minval=1, maxval=100,inline="AI", group="AI
Settings")
n_ = [Link](10, title ="Data", minval=1, maxval=100,inline="AI", group="AI
Settings", tooltip=t1)
n = [Link](k,n_)
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Input settings for prediction values


KNN_PriceLen = [Link](20, title="Price Trend", minval=2, maxval=500,
step=10,inline="AITrend", group="AI Trend")
KNN_STLen = [Link](100, title="Prediction Trend", minval=2, maxval=500,
step=10, inline="AITrend", group="AI Trend", tooltip=t2)
aisignals = [Link](true,title="AI Trend Signals",inline="signal", group="AI
Trend")
Bullish_col = [Link]([Link],"",inline="signal", group="AI Trend")
Bearish_col = [Link]([Link],"",inline="signal", group="AI Trend")
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Define SuperTrend parameters


len = [Link](10, "Length", minval=1,inline="SuperTrend", group="Super Trend
Settings")
factor = [Link](3.0,step=.1,inline="SuperTrend", group="Super Trend Settings",
tooltip=t3)
maSrc = [Link]("WMA","Moving Average Source",
["SMA","EMA","WMA","RMA","VWMA"],inline="", group="Super Trend Settings",
tooltip=t4)
upCol = [Link](#00e67700,"Bullish Color",inline="col", group="Super Trend
Coloring")
dnCol = [Link]([Link],"Bearish Color",inline="col", group="Super Trend
Coloring")
neCol = [Link](#0167bb,"Neutral Color",inline="col", group="Super Trend
Coloring", tooltip=t5)
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Calculate the SuperTrend based on the user's choice


vwma = switch maSrc
"SMA" => [Link](close*volume, len) / [Link](volume, len)
"EMA" => [Link](close*volume, len) / [Link](volume, len)
"WMA" => [Link](close*volume, len) / [Link](volume, len)
"RMA" => [Link](close*volume, len) / [Link](volume, len)
"VWMA" => [Link](close*volume, len) / [Link](volume, len)

atr = [Link](len)
upperBand = vwma + factor * atr
lowerBand = vwma - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])

lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand :


prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand :
prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Collect data points and their corresponding labels


price = [Link](close,KNN_PriceLen)
sT = [Link](superTrend,KNN_STLen)
data = array.new_float(n)
labels = array.new_int(n)
for i = 0 to n - 1
[Link](i, superTrend[i])
label_i = price[i] > sT[i] ? 1 : 0
[Link](i, label_i)
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Define a function to compute distance between two data points


distance(x1, x2) =>
[Link](x1 - x2)
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Define the weighted k-nearest neighbors (KNN) function


knn_weighted(data, labels, k, x) =>
n1 = [Link]()
distances = array.new_float(n1)
indices = array.new_int(n1)
// Compute distances from the current point to all other points
for i = 0 to n1 - 1
x_i = [Link](i)
dist = distance(x, x_i)
[Link](i, dist)
[Link](i, i)
// Sort distances and corresponding indices in ascending order
// Bubble sort method
for i = 0 to n1 - 2
for j = 0 to n1 - i - 2
if [Link](j) > [Link](j + 1)
tempDist = [Link](j)
[Link](j, [Link](j + 1))
[Link](j + 1, tempDist)
tempIndex = [Link](j)
[Link](j, [Link](j + 1))
[Link](j + 1, tempIndex)
// Compute weighted sum of labels of the k nearest neighbors
weighted_sum = 0.
total_weight = 0.
for i = 0 to k - 1
index = [Link](i)
label_i = [Link](index)
weight_i = 1 / ([Link](i) + 1e-6)
weighted_sum += weight_i * label_i
total_weight += weight_i
weighted_sum / total_weight
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Classify the current data point


current_superTrend = superTrend
label_ = knn_weighted(data, labels, k, current_superTrend)
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Plot
col = label_ == 1?upCol:label_ == 0?dnCol:neCol
plot(current_superTrend, color=col, title="Volume Super Trend AI")

upTrend = plot(superTrend==lowerBand?current_superTrend:na, title="Up Volume


Super Trend AI", color=col, style=plot.style_linebr)
Middle = plot((open + close) / 2, display=[Link], editable=false)
downTrend = plot(superTrend==upperBand?current_superTrend:na, title="Down Volume
Super Trend AI", color=col, style=plot.style_linebr)

//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Ai Super Trend Signals


Start_TrendUp = col==upCol and (col[1]!=upCol or col[1]==neCol) and aisignals
Start_TrendDn = col==dnCol and (col[1]!=dnCol or col[1]==neCol) and aisignals
TrendUp = direction == -1 and direction[1] == 1 and label_ == 1 and
aisignals
TrendDn = direction == 1 and direction[1] ==-1 and label_ == 0 and
aisignals

plotshape(Start_TrendUp?superTrend:na, location=[Link], style=


[Link], size=[Link], color=Bullish_col, title="AI Bullish Trend Start")
plotshape(Start_TrendDn?superTrend:na, location=[Link], style=
[Link],size=[Link], color=Bearish_col, title="AI Bearish Trend Start")
plotshape(TrendUp?superTrend:na, location=[Link], style= [Link],
size=[Link], color=Bullish_col, title="AI Bullish Trend Signal")
plotshape(TrendDn?superTrend:na, location=[Link], style=
[Link],size=[Link], color=Bearish_col, title="AI Bearish Trend
Signal")
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ 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')

float ph = [Link](prd, prd)


float pl = [Link](prd, prd)

var tval = array.new_float(PPnum)


var tpos = array.new_int(PPnum)
var bval = array.new_float(PPnum)
var bpos = array.new_int(PPnum)

add_to_array(apointer1, apointer2, val) =>


[Link](apointer1, val)
[Link](apointer2, bar_index)
[Link](apointer1)
[Link](apointer2)

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)

// loop for pivot points to check if there is possible trend line


countlinelo = 0
countlinehi = 0

starttime = timestamp(startyear, startmonth, startday, 0, 0, 0)

if time >= starttime


for x = 0 to maxline - 1 by 1
[Link]([Link](bln, x))
[Link]([Link](tln, x))
for p1 = 0 to PPnum - 2 by 1
uv1 = 0.0
uv2 = 0.0
up1 = 0
up2 = 0
if countlinelo <= maxline
for p2 = PPnum - 1 to p1 + 1 by 1
val1 = [Link](bval, p1)
val2 = [Link](bval, p2)
pos1 = [Link](bpos, p1)
pos2 = [Link](bpos, p2)
if val1 > val2
diff = (val1 - val2) / (pos1 - pos2)
hline = val2 + diff
lloc = bar_index
lval = low
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
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

// if there is continues uptrend line then draw it


if up1 != 0 and up2 != 0 and countlinelo < maxline
countlinelo += 1
[Link](bln, countlinelo - 1, [Link](up2 - prd, uv2, up1, uv1,
color=utcol))

// if there is continues downtrend line then draw it


if dp1 != 0 and dp2 != 0 and countlinehi < maxline
countlinehi += 1
[Link](tln, countlinehi - 1, [Link](dp2 - prd, dv2, dp1, dv1,
color=dtcol))

//@version=5
//@author=Daveatt

// zigzag part entirely take from Ricardo Santos :


[Link]
// horizontal pivtos coming from Backtest Rookies website : [Link]
[Link]/2018/10/05/tradingview-support-and-resistance-indicator/

//indicator('Trend Direction Helper', shorttitle='TDH', overlay=true,


max_bars_back=3000)

//SHIFT = input(title="SHIFT", type=[Link], defval=50)/100

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//////////////////////// Support & Resistances ////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

showSR = input(title='Show Supports & Resistances', defval=true)


left = input(50, title='Left Pivot')
right = input(25, title='Right Pivot')
quick_right = input(5, title='Quick Right Pivot') // Used to try and detect a more
recent significant swing.

pivot_high = [Link](high, left, right)


pivot_lows = [Link](low, left, right)

quick_pivot_high = [Link](high, left, quick_right)


quick_pivot_lows = [Link](low, left, quick_right)

level1 = [Link](quick_pivot_high, high[quick_right], 0)


level2 = [Link](quick_pivot_lows, low[quick_right], 0)
level3 = [Link](pivot_high, high[right], 0)
level4 = [Link](pivot_lows, low[right], 0)
level5 = [Link](pivot_high, high[right], 1)
level6 = [Link](pivot_lows, low[right], 1)
level7 = [Link](pivot_high, high[right], 2)
level8 = [Link](pivot_lows, low[right], 2)

level1_col = close >= level1 ? [Link] : [Link]


level2_col = close >= level2 ? [Link] : [Link]
level3_col = close >= level3 ? [Link] : [Link]
level4_col = close >= level4 ? [Link] : [Link]
level5_col = close >= level5 ? [Link] : [Link]
level6_col = close >= level6 ? [Link] : [Link]
level7_col = close >= level7 ? [Link] : [Link]
level8_col = close >= level8 ? [Link] : [Link]

event = close >= level6


since_event = [Link](event)
first_event = since_event == 1
second_event = close < level6
since_second_event = [Link](second_event)
sec_event = since_second_event == 1

plot(showSR ? level1 : na, style=plot.style_circles, color=level1_col, show_last=1,


linewidth=2, trackprice=true)
plot(showSR ? level2 : na, style=plot.style_circles, color=level2_col, show_last=2,
linewidth=2, trackprice=true)
plot(showSR ? level3 : na, style=plot.style_circles, color=level3_col, show_last=3,
linewidth=2, trackprice=true)
plot(showSR ? level4 : na, style=plot.style_circles, color=level4_col, show_last=4,
linewidth=2, trackprice=true)
plot(showSR ? level5 : na, style=plot.style_circles, color=level5_col, show_last=5,
linewidth=2, trackprice=true)
plot(showSR ? level6 : na, style=plot.style_circles, color=level6_col, show_last=6,
linewidth=2, trackprice=true)
plot(showSR ? level7 : na, style=plot.style_circles, color=level7_col, show_last=7,
linewidth=2, trackprice=true)
plot(showSR ? level8 : na, style=plot.style_circles, color=level8_col, show_last=8,
linewidth=2, trackprice=true)

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////// ZIGZAG ///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

showZZ = input(title='Show ZIG ZAG Lines', defval=true)

// |--------------------------------------------------------------------------||
// | ZigZag: ||
// |--------------------------------------------------------------------------||
// |{
string percent_description = 'Percent of last pivot price for zigzag reversal:'
string zzrealpivot_description = 'Show real zigzag pivots:'

percent = [Link](defval=1.75, title=percent_description, minval=0.0,


maxval=99.0, step=0.25) / 100
bool show_real_pivots_zz = true
// ||-------------------------------------------------------------------------||
// || zigzag function:
// ||-------------------------------------------------------------------------||
// |{
f_zz(_percent) =>

// direction after last pivot


var bool _is_direction_up = na
// track highest price since last lower pivot
var float _htrack = na
// track lowest price since last higher pivot
var float _ltrack = na
// zigzag variable for ploting
var float _pivot = na
// range needed for reaching reversal threshold
var float _reverse_range = 0.0
// real pivot time
var int _real_pivot_time = na
// reverse line
var float _reverse_line = 0.0
if bar_index >= 1
_reverse_range := nz(_pivot[1]) * _percent
_is_direction_up := nz(_is_direction_up[1], true)

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

[_pivot, _is_direction_up, _reverse_line, _real_pivot_time]

// || |}---------------------------------------------------------------------<•

// ||-------------------------------------------------------------------------||
// || 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

var int __x_ALEN = 10


string __x_AMODE = na
int __x_ASET = na
// |{-------------------------------------------------------------------------<•
// || Utility Functions: (ID:__x_)
f__x_AGET(_i) =>
_i == 0 ? __x_A00 : _i == 1 ? __x_A01 : _i == 2 ? __x_A02 : _i == 3 ? __x_A03 :
_i == 4 ? __x_A04 : _i == 5 ? __x_A05 : _i == 6 ? __x_A06 : _i == 7 ? __x_A07 : _i
== 8 ? __x_A08 : _i == 9 ? __x_A09 : _i == 10 ? __x_A10 : na
f__x_ASET(_value, _index, _length, _mode) =>
int _return = na
if _index > _length
_return := na
_return
else
if _index == 0
_return := _value
_return
else
if _mode == 'push' or _mode == 'PUSH' or _mode == 'p' or _mode == 'P'
_return := f__x_AGET(_index - 1)
_return
if _mode == 'replace' or _mode == 'REPLACE' or _mode == 'r' or _mode ==
'R'
_return := f__x_AGET(_index)
_return
_return
// || |}---------------------------------------------------------------------<•

// || |}---------------------------------------------------------------------<•
// ||-------------------------------------------------------------------------||
// || 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

var int __y_ALEN = 10


string __y_AMODE = na
float __y_ASET = na
// |{-------------------------------------------------------------------------<•
// || Utility Functions: (ID:__y_)
f__y_AGET(_i) =>
_i == 0 ? __y_A00 : _i == 1 ? __y_A01 : _i == 2 ? __y_A02 : _i == 3 ? __y_A03 :
_i == 4 ? __y_A04 : _i == 5 ? __y_A05 : _i == 6 ? __y_A06 : _i == 7 ? __y_A07 : _i
== 8 ? __y_A08 : _i == 9 ? __y_A09 : _i == 10 ? __y_A10 : na
f__y_ASET(_value, _index, _length, _mode) =>
float _return = na
if _index > _length
_return := na
_return
else
if _index == 0
_return := _value
_return
else
if _mode == 'push' or _mode == 'PUSH' or _mode == 'p' or _mode == 'P'
_return := f__y_AGET(_index - 1)
_return
if _mode == 'replace' or _mode == 'REPLACE' or _mode == 'r' or _mode ==
'R'
_return := f__y_AGET(_index)
_return
_return
// || |}---------------------------------------------------------------------<•

// || |}---------------------------------------------------------------------<•

// | 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)

var line _li1 = na


_li_color1 = f__y_AGET(1) > f__y_AGET(2) ? col1 : col2
[Link](_li1)
_li1 := [Link](x1=f__x_AGET(1), y1=f__y_AGET(1), x2=f__x_AGET(2),
y2=f__y_AGET(2), xloc=xloc.bar_time, extend=[Link], color=_li_color1,
style=line.style_solid, width=line_width)

var line _li2 = na


_li_color2 = f__y_AGET(2) > f__y_AGET(3) ? col1 : col2
[Link](_li2)
_li2 := [Link](x1=f__x_AGET(2), y1=f__y_AGET(2), x2=f__x_AGET(3),
y2=f__y_AGET(3), xloc=xloc.bar_time, extend=[Link], color=_li_color2,
style=line.style_solid, width=line_width)

var line _li3 = na


_li_color3 = f__y_AGET(3) > f__y_AGET(4) ? col1 : col2
[Link](_li3)
_li3 := [Link](x1=f__x_AGET(3), y1=f__y_AGET(3), x2=f__x_AGET(4),
y2=f__y_AGET(4), xloc=xloc.bar_time, extend=[Link], color=_li_color3,
style=line.style_solid, width=line_width)

var line _li4 = na


_li_color4 = f__y_AGET(4) > f__y_AGET(5) ? col1 : col2
[Link](_li4)
_li4 := [Link](x1=f__x_AGET(4), y1=f__y_AGET(4), x2=f__x_AGET(5),
y2=f__y_AGET(5), xloc=xloc.bar_time, extend=[Link], color=_li_color4,
style=line.style_solid, width=line_width)

var line _li5 = na


_li_color5 = f__y_AGET(5) > f__y_AGET(6) ? col1 : col2
[Link](_li5)
_li5 := [Link](x1=f__x_AGET(5), y1=f__y_AGET(5), x2=f__x_AGET(6),
y2=f__y_AGET(6), xloc=xloc.bar_time, extend=[Link], color=_li_color5,
style=line.style_solid, width=line_width)

var line _li6 = na


_li_color6 = f__y_AGET(6) > f__y_AGET(7) ? col1 : col2
[Link](_li6)
_li6 := [Link](x1=f__x_AGET(6), y1=f__y_AGET(6), x2=f__x_AGET(7),
y2=f__y_AGET(7), xloc=xloc.bar_time, extend=[Link], color=_li_color6,
style=line.style_solid, width=line_width)

var line _li7 = na


_li_color7 = f__y_AGET(7) > f__y_AGET(8) ? col1 : col2
[Link](_li7)
_li7 := [Link](x1=f__x_AGET(7), y1=f__y_AGET(7), x2=f__x_AGET(8),
y2=f__y_AGET(8), xloc=xloc.bar_time, extend=[Link], color=_li_color7,
style=line.style_solid, width=line_width)
_li7

You might also like