name
stringlengths 1
64
| url
stringlengths 44
135
| author
stringlengths 3
30
| author_url
stringlengths 34
61
| likes_count
int64 0
33.2k
| kind
stringclasses 3
values | pine_version
int64 1
5
| license
stringclasses 3
values | source
stringlengths 177
279k
|
---|---|---|---|---|---|---|---|---|
X | https://www.tradingview.com/script/SpLFamSD-X/ | fikira | https://www.tradingview.com/u/fikira/ | 25 | library | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © fikira
//@version=5
// @description a collection of 'special' methods/functions ('special' at the time of conception)
// Initial functions includes:
// • count of a given number in a given array
// • array.get() but option added to use negative index
// • sum of all digits until the output < 10
// • slope/angle calculation of lines
library("X", overlay=true)
n = bar_index
_ = "
----------------------------- ----------------------------- ----------------------------- ----------------------------
METHODS : FUNCTIONS
----------------------------- ----------------------------- ----------------------------- ---------------------------- "
_ = "
----------------------------- ----------------------------- ----------------------------- ----------------------------
Typically, we use loops for counting how many values an array contains. With count_num_in_array(), we don't
use a loop, but the build-in functions array.sort(), array.includes(), array.lastindexof() and array.indexof()
This should give us better performance due to using less loops
----------------------------- ----------------------------- ----------------------------- ---------------------------- "
// @function counts how many times a given number is present in a given array (0 when not present)
// @param arr array<int>
// @param num Number that needs to be counted (int, float)
// @returns count of number in array (0 when not present)
export method count_num_in_array(array< int > arr, int num) => arr.sort(), arr.includes(num) ? arr.lastindexof(num) - arr.indexof(num) + 1 : 0
// @function counts how many times a given number is present in a given array (0 when not present)
// @param arr array<float>
// @param num Number that needs to be counted (int, float)
// @returns count of number in array (0 when not present)
export method count_num_in_array(array<float> arr, float num) => arr.sort(), arr.includes(num) ? arr.lastindexof(num) - arr.indexof(num) + 1 : 0
_ = "
----------------------------- ----------------------------- ----------------------------- ----------------------------
array.get() can only be used with a positive index, indexes as -1, -2, ... are not allowed.
For the ones who want to, the get_() function is able to use negative indexes
----------------------------- ----------------------------- ----------------------------- ---------------------------- "
// @function array.get() but you can use negative index (-1 is last of array, -2 is second last,...)
// @param arr array<int>
// @param idx index
// @returns value/object at index, 'na' if index is outside array
export method get_(array<int> arr, int idx) => sz = arr.size(), sz == 0 or idx < -sz or idx > sz -1 ? na : arr.get(idx + (idx < 0 ? sz : 0))
// @function array.get() but you can use negative index (-1 is last of array, -2 is second last,...)
// @param arr array<float>
// @param idx index
// @returns value/object at index, 'na' if index is outside array
export method get_(array<float> arr, int idx) => sz = arr.size(), sz == 0 or idx < -sz or idx > sz -1 ? na : arr.get(idx + (idx < 0 ? sz : 0))
// @function array.get() but you can use negative index (-1 is last of array, -2 is second last,...)
// @param arr array<string>
// @param idx Index
// @returns value/object at index, 'na' if index is outside array
export method get_(array<string> arr, int idx) => sz = arr.size(), sz == 0 or idx < -sz or idx > sz -1 ? na : arr.get(idx + (idx < 0 ? sz : 0))
// @function array.get() but you can use negative index (-1 is last of array, -2 is second last,...)
// @param arr array<bool>
// @param idx Index
// @returns value/object at index, 'na' if index is outside array
export method get_(array<bool> arr, int idx) => sz = arr.size(), sz == 0 or idx < -sz or idx > sz -1 ? na : arr.get(idx + (idx < 0 ? sz : 0))
// @function array.get() but you can use negative index (-1 is last of array, -2 is second last,...)
// @param arr array<label>
// @param idx Index
// @returns value/object at index, 'na' if index is outside array
export method get_(array<label> arr, int idx) => sz = arr.size(), sz == 0 or idx < -sz or idx > sz -1 ? na : arr.get(idx + (idx < 0 ? sz : 0))
// @function array.get() but you can use negative index (-1 is last of array, -2 is second last,...)
// @param arr array<line>
// @param idx Index
// @returns value/object at index, 'na' if index is outside array
export method get_(array<line> arr, int idx) => sz = arr.size(), sz == 0 or idx < -sz or idx > sz -1 ? na : arr.get(idx + (idx < 0 ? sz : 0))
// @function array.get() but you can use negative index (-1 is last of array, -2 is second last,...)
// @param arr array<box>
// @param idx Index
// @returns value/object at index, 'na' if index is outside array
export method get_(array<box> arr, int idx) => sz = arr.size(), sz == 0 or idx < -sz or idx > sz -1 ? na : arr.get(idx + (idx < 0 ? sz : 0))
// @function array.get() but you can use negative index (-1 is last of array, -2 is second last,...)
// @param arr array<color>
// @param idx Index
// @returns value/object at index, 'na' if index is outside array
export method get_(array<color> arr, int idx) => sz = arr.size(), sz == 0 or idx < -sz or idx > sz -1 ? na : arr.get(idx + (idx < 0 ? sz : 0))
_ = "
----------------------------- ----------------------------- ----------------------------- ----------------------------
There are people who believe in the power of certain numbers between 0 and 9, they count every digit until they end up with a number between 0 and 9
For example -> count every digit of 123456 -> 1+2+3+4+5+6 = 21, if the sum is higher then 9, repeat -> 2+1 = 3
It was not so easy to create a function which uses as less string manipulation as possible (more string manupulation is greater risk for memory errors)
I finally ended up with sumAllNumbers_till_under_10()
----------------------------- ----------------------------- ----------------------------- ---------------------------- "
// @function sums all separate digit numbers, it repeats the process until sum < 10
// @param num Number (int)
// @returns value between 0 and 9
export method sumAllNumbers_till_under_10(int num) => calc = str.tonumber(str.replace(str.tostring(num), ".", "")) % 9, num == 0 ? 0 : calc == 0 ? 9 : calc
// @function sums all separate digit numbers, it repeats the process until sum < 10
// @param num Number (float)
// @returns value between 0 and 9
export method sumAllNumbers_till_under_10(float num) => calc = str.tonumber(str.replace(str.tostring(num), ".", "")) % 9, num == 0 ? 0 : calc == 0 ? 9 : calc
_ = "
----------------------------- ----------------------------- ----------------------------- ----------------------------
Angle / slope calculation is tricky due to different units in X and Y axis (bar_index vs. price)
Also, certain techniques give very different result when comparing historical data, due to price fluctuations.
With the techniques in XYaxis() and calculate_slope() I tried to create angles / slopes which are rather similar on all bars.
Importantly, XYaxis() always needs to be placed globally, calculate_slope() can be placed locally.
The XYratio can be useful for finetuning, since every user has other habits regarding zooming in on the chart. Zooming in/out doesn't
change bars/price, but it does change our angle perspective. Therefore XYratio can be very useful (for example as input.float(3, '', minval=0, maxval=10))
----------------------------- ----------------------------- ----------------------------- ---------------------------- "
// @function Global function to calculate Yaxis, which is used in calculate_slope() method
// @param width Amount of bars for reference X-axis
// @returns Yaxis
export method XYaxis(int width) => Xaxis = math.min(math.max(1, n), width), ta.highest(Xaxis) - ta.lowest(Xaxis)
// @function Returns a normalised slope
// @param width Amount of bars to calculate height
// @param XYratio Ratio to calculate height (from width) normalised_slope calculation
// @param Yaxis Y-axis from XYaxis() method
// @param x1 x1 of line
// @param y1 y1 of line
// @param x2 x2 of line
// @param y2 y2 of line
// @returns Tuple of [slope, angle] -> slope = price difference per bar
export method calculate_slope(int width, float XYratio, float Yaxis, int x1, float y1, int x2, float y2) =>
height = width / XYratio
diffX = x2 - x1
diffY = y2 - y1
diffY_to_Yaxis = Yaxis / diffY
normalised_slope = (height / diffY_to_Yaxis) / diffX
slope = diffY / diffX
angle = math.round(math.atan(normalised_slope) * 180 / math.pi, 2)
[slope, angle]
_ = "
----------------------------- ----------------------------- ----------------------------- ----------------------------
EXAMPLES
----------------------------- ----------------------------- ----------------------------- ---------------------------- "
import fikira/X/1 as X
// count_num_in_array(), get_() & sumAllNumbers_till_under_10()
// Typically, we use loops for counting how many values an array contains
// With count_num_in_array(), we don't use a loop, but the build-in functions array.sort(), array.includes(), array.lastindexof() and array.indexof()
// this should give us better performance due to using less loops
aF1 = array.from(3, 4, 3, 0, 1., 2, 3, 4) // array<float> -> becomes sorted by count_num_in_array()
aI1 = array.from(3, 4, 3, 0, 1 , 2, 3, 4) // array<int> -> becomes sorted by count_num_in_array()
aI2 = array.from(3, 4, 3, 0, 1 , 2, 3, 4) // array<int> -> not sorted
plot(X.count_num_in_array(aF1, 3) , color=color.red) // count_num_in_array() used as FUNCTION
plot(aF1.count_num_in_array(5) , color=color.blue) // count_num_in_array() used as METHOD
plot(aI1.count_num_in_array(0) , color=color.white)
plot(aI2.get_(-3) , color=color.yellow)
plot(close.sumAllNumbers_till_under_10(), color=color.fuchsia)
// XYaxis() & calculate_slope()
type p
int b
float p
var aPiv = array.new<p>(2, p.new(na, na))
len = 10
ph = ta.pivothigh(len, len)
bars = 500
Yaxis = bars.XYaxis()
if not na(ph)
[slope, angle] = bars.calculate_slope(
XYratio = 3
, Yaxis = Yaxis
, x1 = aPiv.first().b
, y1 = aPiv.first().p
, x2 = n -len
, y2 = ph
)
line.new (aPiv.first().b, aPiv.first().p, n -len, ph, color=color.fuchsia)
label.new( n -len, ph
, text = str.format("slope: {0} / bar\nangle: {1}°", slope, angle)
, style = label.style_none
, textcolor = color.yellow
)
aPiv.unshift(p.new(n - len, ph)), aPiv.pop()
var label lab = label.new(
na
, na
, color =color.new(color.blue, 100)
, style = label.style_label_left
, textcolor = chart.fg_color
, size = size.large
)
if barstate.islast
lab.set_xy (n + 1, hl2)
lab.set_text(
str.format(
"4 is x times in array: {0}\narray.get(-3): {1}\nSum digits 'close' till < 10: {2}"
, aF1.count_num_in_array(4)
, aI2.get_(-3)
, close.sumAllNumbers_till_under_10()
)
) |
TableUtils | https://www.tradingview.com/script/i1uOvZ27-TableUtils/ | pmarino84 | https://www.tradingview.com/u/pmarino84/ | 2 | library | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pmarino84
//@version=5
// @description TODO: add library description here
library("TableUtils", true)
const string TABLE_POSITION_TOP_LEFT = "Top left"
const string TABLE_POSITION_TOP_RIGHT = "Top right"
const string TABLE_POSITION_BOTTOM_LEFT = "Bottom left"
const string TABLE_POSITION_BOTTOM_RIGHT = "Bottom right"
const string TABLE_POSITION_MIDDLE_LEFT = "Middle left"
const string TABLE_POSITION_MIDDLE_RIGHT = "Middle right"
// @function Return the position for the table by given label. Useful if you want to control the position of the table with a pine script input selector that use a more human friendly labels
// @param tablePosition (string) Label of the table position. Possible values are: "Top left", "Top right", "Bottom left", "Bottom right", "Middle left", "Middle right"
// @returns the position for the table by given label. Useful if you want to control the position of the table with a pine script input selector that use a more human friendly labels
export getTablePositionByLabel(string tablePosition) =>
switch tablePosition
"Top left" => position.top_left
//"Top right" => position.top_right // default
"Bottom left" => position.bottom_left
"Bottom right" => position.bottom_right
"Middle left" => position.middle_left
"Middle right" => position.middle_right
=>
position.top_right
// EXAMPLE OF USAGE
trendToText(trend) => trend == 0 ? "Neutral" : (trend == 1 ? "Bullish" : "Bearish")
trendToColorBg(float trend, color bgColor = na) => trend == 1 ? color.green : (trend == -1 ? color.red : bgColor)
trendToColorTxt(trend) => trend == 1 or trend == -1 ? color.white : color.black
drawTestTable(float trend1D, float trend4H, float trend1H, float trend15, string position = position.top_right, color bgColor = color.gray, color textColor = color.white) =>
var tableId = table.new(position, 3, 10, border_width = 1)
// table header
table.cell(tableId, 0, 0, " ")
table.cell(tableId, 1, 0, "Trend", bgcolor = bgColor, text_color = textColor)
// timeframes info
table.cell(tableId, 0, 1, "1D", text_color = textColor, bgcolor = bgColor)
table.cell(tableId, 1, 1, trendToText(trend1D), text_color = trendToColorTxt(trend1D), bgcolor = trendToColorBg(trend1D, bgColor))
table.cell(tableId, 0, 2, "4H", text_color = textColor, bgcolor = bgColor)
table.cell(tableId, 1, 2, trendToText(trend4H), text_color = trendToColorTxt(trend4H), bgcolor = trendToColorBg(trend4H, bgColor))
table.cell(tableId, 0, 3, "1H", text_color = textColor, bgcolor = bgColor)
table.cell(tableId, 1, 3, trendToText(trend1H), text_color = trendToColorTxt(trend1H), bgcolor = trendToColorBg(trend1H, bgColor))
table.cell(tableId, 0, 4, "15m", text_color = textColor, bgcolor = bgColor)
table.cell(tableId, 1, 4, trendToText(trend15), text_color = trendToColorTxt(trend15), bgcolor = trendToColorBg(trend15, bgColor))
tableId
trendTablePosition = input.string(TABLE_POSITION_TOP_RIGHT, "Table position", options = [TABLE_POSITION_TOP_LEFT, TABLE_POSITION_TOP_RIGHT, TABLE_POSITION_BOTTOM_LEFT, TABLE_POSITION_BOTTOM_RIGHT, TABLE_POSITION_MIDDLE_LEFT, TABLE_POSITION_MIDDLE_RIGHT])
fastMA = ta.ema(close, 8)
slowMA = ta.ema(close, 21)
[fastMa1D, slowMa1D] = request.security(syminfo.tickerid, "1D", [fastMA, slowMA], barmerge.gaps_off)
[fastMa4H, slowMa4H] = request.security(syminfo.tickerid, "240", [fastMA, slowMA], barmerge.gaps_off)
[fastMa1H, slowMa1H] = request.security(syminfo.tickerid, "60", [fastMA, slowMA], barmerge.gaps_off)
[fastMa15, slowMa15] = request.security(syminfo.tickerid, "15", [fastMA, slowMA], barmerge.gaps_off)
trend1D = math.sign(fastMa1D - slowMa1D)
trend4H = math.sign(fastMa4H - slowMa4H)
trend1H = math.sign(fastMa1H - slowMa1H)
trend15 = math.sign(fastMa15 - slowMa15)
if barstate.islast
drawTestTable(trend1D, trend4H, trend1H, trend15, getTablePositionByLabel(trendTablePosition))
|
[Library] VAcc | https://www.tradingview.com/script/RpRjfuvX-Library-VAcc/ | algotraderdev | https://www.tradingview.com/u/algotraderdev/ | 5 | library | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © algotraderdev & Scott Cong
// Based on "Stocks & Commodities V. 41:09 (8–15): VAcc: A Momentum Indicator Based On Velocity And Acceleration by Scott Cong, PhD"
//@version=5
library('vacc')
// @function Caculates the velocity and acceleration with the given length and smoothness.
// @param source Series of values to process.
// @param length Number of periods to process.
// @param smoothness The smoothing period.
// @returns A tuple containing the velocity and acceleration.
export get(series float source, simple int length, simple int smoothness) =>
float sumVel = 0
for i = 1 to length
sumVel += (source - source[i]) / i
vel = ta.ema(sumVel / length, smoothness)
float sumAcc = 0
for i = 1 to length
sumAcc += (vel - vel[i]) / i
acc = sumAcc / length
[vel, acc]
float SOURCE = input.source(close, 'Source')
int LENGTH = input.int(26, 'Length', minval = 2, step = 1)
int SMOOTH = input.int(9, 'Smooth', minval = 1, step = 1)
color VELOCITY_COLOR = input.color(color.blue, 'Velocity', group = 'Colors')
color ABOVE_GROW_COLOR = input.color(#26a69a, 'Above Zero Grow', inline = 'Above', group = 'Colors')
color ABOVE_FALL_COLOR = input.color(#b2dfdb, 'Fall', inline = 'Above', group = 'Colors')
color BELOW_GROW_COLOR = input.color(#ffcdd2, 'Below Zero Grow', inline = 'Below', group = 'Colors')
color BELOW_FALL_COLOR = input.color(#ff5252, 'Fall', inline = 'Below', group = 'Colors')
[vel, acc] = get(SOURCE, LENGTH, SMOOTH)
color accColor = if acc >= 0
acc[1] < acc ? ABOVE_GROW_COLOR : ABOVE_FALL_COLOR
else
acc[1] < acc ? BELOW_GROW_COLOR : BELOW_FALL_COLOR
plot(acc * 100, 'Acc', color = accColor, style = plot.style_columns)
plot(vel / LENGTH * 200, 'Vel', VELOCITY_COLOR) |
MyVolatilityBandss | https://www.tradingview.com/script/YQjJuMNE-MyVolatilityBandss/ | cryptorepos | https://www.tradingview.com/u/cryptorepos/ | 7 | library | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ClassicScott
//@version=5
// @description Just a lil' library of volatility bands that I use in some scripts
library("MyVolatilityBandss")
// @function Bollinger Bands
// @param src float
// @param lkbk int
// @param mult float
// @param basis float
// @param band_width float
// @returns Bollinger Bands with an outer band of varying thickness adjustable by the band_width input
export bollingerbands(float src, int lkbk, float mult, float basis, float band_width) =>
dev = mult * ta.stdev(src, lkbk)
upper = basis + dev
lower = basis - dev
width = (upper - lower) / band_width
inner_upper = upper - width
inner_lower = lower + width
[basis, upper, lower, inner_upper, inner_lower]
// @function Donchian Channels
// @param src float
// @param lkbk int
// @param band_width float
// @returns Donchian Channels with an outer band of varying thickness adjustable by the band_width input
export donchianchannels(float src, int lkbk, float band_width) =>
upper = ta.highest(src, lkbk)
lower = ta.lowest(src, lkbk)
width = (upper - lower) / band_width
inner_upper = upper - width
inner_lower = lower + width
basis = math.avg(upper, lower)
[basis, upper, lower, inner_upper, inner_lower]
// @function Double Half Donchian Channels
// @param src float
// @param lkbk int
// @param divisor float
// @returns two adjustable bases calculated using Donchian Channels calculation that can act as a measure of volatility for below chart indicators
export doublehalfdonchianchannels(float src, int lkbk, float divisor) =>
_high = ta.highest(src, lkbk)
_low = ta.lowest(src, lkbk)
high_vol = _high / divisor
low_vol = _low / divisor
[high_vol, low_vol]
// @function Keltner Channels
// @param src float
// @param lkbk int
// @param mult float
// @param atr_lkbk int
// @param basis float
// @param band_width float
// @returns Keltner Channels with an outer band of varying thickness adjustable by the band_width input
export keltnerchannels(int atr_lkbk, float mult, float basis, float band_width) =>
upper = basis + ta.atr(atr_lkbk) * mult
lower = basis - ta.atr(atr_lkbk) * mult
width = (upper - lower) / band_width
inner_upper = upper - width
inner_lower = lower + width
[basis, upper, lower, inner_upper, inner_lower] |
Table | https://www.tradingview.com/script/GWvI1cvC-Table/ | jmosullivan | https://www.tradingview.com/u/jmosullivan/ | 5 | library | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jmosullivan
//@version=5
// @description This library provides an easy way to convert arrays and matrixes of data into tables. There are
// a few different implementations of each function so you can get more or less control over the appearance of
// the tables. The basic rule of thumb is that all matrix rows must have the same number of columns, and if you
// are providing multiple arrays/matrixes to specify additional colors (background/text), they must have the
// same number of rows/columns as the data array. Finally, you do have the option of spanning cells across rows
// or columns with some special syntax in the data cell. Look at the examples to see how the arrays and matrixes
// need to be built before they can be used by the functions.
library("Table", true)
import jmosullivan/Utils/1
// Constants used in the tables (as defaults, they can be overridden by custom scripts)
color COLOR_HOT = #e500a4
color COLOR_COOL = #2962ff
color COLOR_TEXT = color.white
// @type Type for each cell's content and appearance
export type Cell
string content
color bgColor = color.blue
color textColor = color.white
string align = text.align_center
int colspan = 1
int rowspan = 1
// @function Helper function that converts a float array to a Cell array so it can be rendered with the fromArray function
// @param floatArray (array<float>) the float array to convert to a Cell array.
// @returns array<Cell> The Cell array to return.
export floatArrayToCellArray(array<float> floatArray) =>
cellArray = array.new<Cell>()
for item in floatArray
array.push(cellArray, Cell.new(str.tostring(item)))
cellArray
// @function Helper function that converts a string array to a Cell array so it can be rendered with the fromArray function
// @param stringArray (array<string>) the array to convert to a Cell array.
// @returns array<Cell> The Cell array to return.
export stringArrayToCellArray(array<string> stringArray) =>
cellArray = array.new<Cell>()
for item in stringArray
array.push(cellArray, Cell.new(item))
cellArray
// @function Helper function that converts a float matrix to a Cell matrix so it can be rendered with the fromMatrix function
// @param floatMatrix (matrix<float>) the float matrix to convert to a string matrix.
// @returns matrix<Cell> The Cell matrix to render.
export floatMatrixToCellMatrix(matrix<float> floatMatrix) =>
rows = matrix.rows(floatMatrix)
cols = matrix.columns(floatMatrix)
cellMatrix = matrix.new<Cell>(rows, cols)
if rows > 0 and cols > 0
for a = 0 to rows - 1
for b = 0 to cols - 1
matrix.set(cellMatrix, a, b, Cell.new(str.tostring(matrix.get(floatMatrix, a, b))))
cellMatrix
// @function Helper function that converts a string matrix to a Cell matrix so it can be rendered with the fromMatrix function
// @param stringMatrix (matrix<string>) the string matrix to convert to a Cell matrix.
// @returns matrix<Cell> The Cell matrix to return.
export stringMatrixToCellMatrix(matrix<string> stringMatrix) =>
rows = matrix.rows(stringMatrix)
cols = matrix.columns(stringMatrix)
cellMatrix = matrix.new<Cell>(rows, cols)
if rows > 0 and cols > 0
for a = 0 to rows - 1
for b = 0 to cols - 1
matrix.set(cellMatrix, a, b, Cell.new(matrix.get(stringMatrix, a, b)))
cellMatrix
// @function Takes a CellMatrix and renders it as a table.
// @param CellMatrix (matrix<Cell>) The Cells to be rendered in a table
// @param position (string) Optional. The position of the table. Defaults to position.top_right
// @param verticalOffset (int) Optional. The vertical offset of the table from the top or bottom of the chart. Defaults to 0.
// @param transposeTable (bool) Optional. Will transpose all of the data in the matrices before rendering. Defaults to false.
// @param textSize (string) Optional. The size of text to render in the table. Defaults to size.small.
// @param borderWidth (int) Optional. The width of the border between table cells. Defaults to 2.
// @param tableNumRows (int) Optional. The number of rows in the table. Not required, defaults to the number of rows in the provided matrix. If your matrix will have a variable number of rows, you must provide the max number of rows or the function will error when it attempts to set a cell value on a row that the table hadn't accounted for when it was defined.
// @param blankCellText (string) Optional. Text to use cells when adding blank rows for vertical offsetting.
export fromMatrix(matrix<Cell> CellMatrix, string position = position.top_right, int verticalOffset = 0, bool transposeTable = false, string textSize = size.small, int borderWidth = 2, int tableNumRows = -1, string blankCellText = "") =>
if barstate.islast
matrix<Cell> _cellMatrix = CellMatrix
int rows = matrix.rows(CellMatrix)
int columns = matrix.columns(CellMatrix)
// Perform some validation to make sure we have all the things we need
if transposeTable
_cellMatrix := matrix.transpose(_cellMatrix)
rows := matrix.rows(_cellMatrix)
columns := matrix.columns(_cellMatrix)
// If the table is supposed to be offset from it's top or bottom, add rows to create the displacement
_position = Utils.getPositionFromString(position)
bool isBottom = _position == position.bottom_left or _position == position.bottom_center or _position == position.bottom_right
bool isTop = _position == position.top_left or _position == position.top_center or _position == position.top_right
if (verticalOffset > 0)
transparentColor = color.rgb(255,255,255,100)
blankCell = Cell.new(blankCellText, transparentColor, transparentColor)
matrix<Cell> blankRows = matrix.new<Cell>(verticalOffset, columns, blankCell)
if (isTop)
_cellMatrix := matrix.concat(blankRows, _cellMatrix)
else if (isBottom)
_cellMatrix := matrix.concat(_cellMatrix, blankRows)
Cell cell = na
mergeArray = array.new_string()
int matrixRows = matrix.rows(_cellMatrix)
int tableRows = matrixRows > tableNumRows ? matrixRows : tableNumRows
table matrixTable = table.new(position = _position, columns = columns, rows = tableRows, border_width = borderWidth)
for i = 0 to matrixRows - 1
for j = 0 to columns - 1
// Check the data for row & colspan specs
cell := matrix.get(_cellMatrix, i, j)
// Just insert blank cells if the matrix is missing something...
if na(cell)
cell := Cell.new("")
// Build a merge array to be merged after table is complete
if (cell.rowspan > 1 or cell.colspan > 1)
array.push(mergeArray, str.tostring(j) + ":" + str.tostring(i) + ":" + str.tostring(j+cell.colspan-1) + ":" + str.tostring(i+cell.rowspan-1))
table.cell(
matrixTable,
j,
i,
cell.content,
text_color=cell.textColor,
text_size=textSize,
text_halign=cell.align,
bgcolor=cell.bgColor
)
mergeArraySize = array.size(mergeArray)
if mergeArraySize > 0
for i = 0 to mergeArraySize - 1
mergeParts = str.split(array.get(mergeArray, i), ":")
if array.size(mergeParts) == 4
table.merge_cells(
matrixTable,
math.round(str.tonumber(array.get(mergeParts, 0))),
math.round(str.tonumber(array.get(mergeParts, 1))),
math.round(str.tonumber(array.get(mergeParts, 2))),
math.round(str.tonumber(array.get(mergeParts, 3)))
)
// @function Renders a float matrix as a table.
// @param dataMatrix (matrix_float) The data to be rendered in a table
// @param position (string) Optional. The position of the table. Defaults to position.top_right
// @param verticalOffset (int) Optional. The vertical offset of the table from the top or bottom of the chart. Defaults to 0.
// @param transposeTable (bool) Optional. Will transpose all of the data in the matrices before rendering. Defaults to false.
// @param textSize (string) Optional. The size of text to render in the table. Defaults to size.small.
// @param borderWidth (int) Optional. The width of the border between table cells. Defaults to 2.
// @param tableNumRows (int) Optional. The number of rows in the table. Not required, defaults to the number of rows in the provided matrix. If your matrix will have a variable number of rows, you must provide the max number of rows or the function will error when it attempts to set a cell value on a row that the table hadn't accounted for when it was defined.
// @param blankCellText (string) Optional. Text to use cells when adding blank rows for vertical offsetting.
export fromMatrix(matrix<float> dataMatrix, string position = position.top_right, int verticalOffset = 0, bool transposeTable = false, string textSize = size.small, int borderWidth = 2, int tableNumRows = -1, string blankCellText = "") =>
fromMatrix(floatMatrixToCellMatrix(dataMatrix), position, verticalOffset, transposeTable, textSize, borderWidth, tableNumRows, blankCellText)
// @function Renders a string matrix as a table.
// @param dataMatrix (matrix_string) The data to be rendered in a table
// @param position (string) Optional. The position of the table. Defaults to position.top_right
// @param verticalOffset (int) Optional. The vertical offset of the table from the top or bottom of the chart. Defaults to 0.
// @param transposeTable (bool) Optional. Will transpose all of the data in the matrices before rendering. Defaults to false.
// @param textSize (string) Optional. The size of text to render in the table. Defaults to size.small.
// @param borderWidth (int) Optional. The width of the border between table cells. Defaults to 2.
// @param tableNumRows (int) Optional. The number of rows in the table. Not required, defaults to the number of rows in the provided matrix. If your matrix will have a variable number of rows, you must provide the max number of rows or the function will error when it attempts to set a cell value on a row that the table hadn't accounted for when it was defined.
// @param blankCellText (string) Optional. Text to use cells when adding blank rows for vertical offsetting.
export fromMatrix(matrix<string> dataMatrix, string position = position.top_right, int verticalOffset = 0, bool transposeTable = false, string textSize = size.small, int borderWidth = 2, int tableNumRows = -1, string blankCellText = "") =>
fromMatrix(stringMatrixToCellMatrix(dataMatrix), position, verticalOffset, transposeTable, textSize, borderWidth, tableNumRows, blankCellText)
// @function Renders a Cell array as a table.
// @param dataArray (array<Cell>) The data to be rendered in a table
// @param position (string) Optional. The position of the table. Defaults to position.top_right
// @param verticalOffset (int) Optional. The vertical offset of the table from the top or bottom of the chart. Defaults to 0.
// @param transposeTable (bool) Optional. Will transpose all of the data in the matrices before rendering. Defaults to false.
// @param textSize (string) Optional. The size of text to render in the table. Defaults to size.small.
// @param borderWidth (int) Optional. The width of the border between table cells. Defaults to 2.
// @param blankCellText (string) Optional. Text to use cells when adding blank rows for vertical offsetting.
export fromArray(array<Cell> dataArray, string position = position.top_right, int verticalOffset = 0, bool transposeTable = false, string textSize = size.small, int borderWidth = 2, string blankCellText = "") =>
dataMatrix = matrix.new<Cell>()
matrix.add_row(dataMatrix, 0, dataArray)
fromMatrix(dataMatrix, position, verticalOffset, transposeTable, textSize, borderWidth, blankCellText=blankCellText)
// @function Renders a string array as a table.
// @param dataArray (array_string) The data to be rendered in a table
// @param position (string) Optional. The position of the table. Defaults to position.top_right
// @param verticalOffset (int) Optional. The vertical offset of the table from the top or bottom of the chart. Defaults to 0.
// @param transposeTable (bool) Optional. Will transpose all of the data in the matrices before rendering. Defaults to false.
// @param textSize (string) Optional. The size of text to render in the table. Defaults to size.small.
// @param borderWidth (int) Optional. The width of the border between table cells. Defaults to 2.
// @param blankCellText (string) Optional. Text to use cells when adding blank rows for vertical offsetting.
export fromArray(array<string> dataArray, string position = position.top_right, int verticalOffset = 0, bool transposeTable = false, string textSize = size.small, int borderWidth = 2, string blankCellText = "") =>
fromArray(stringArrayToCellArray(dataArray), position, verticalOffset, transposeTable, textSize, borderWidth, blankCellText=blankCellText)
// @function Renders a float array as a table.
// @param dataArray (array_float) The data to be rendered in a table
// @param position (string) Optional. The position of the table. Defaults to position.top_right
// @param verticalOffset (int) Optional. The vertical offset of the table from the top or bottom of the chart. Defaults to 0.
// @param transposeTable (bool) Optional. Will transpose all of the data in the matrices before rendering. Defaults to false.
// @param textSize (string) Optional. The size of text to render in the table. Defaults to size.small.
// @param borderWidth (int) Optional. The width of the border between table cells. Defaults to 2.
// @param blankCellText (string) Optional. Text to use cells when adding blank rows for vertical offsetting.
export fromArray(array<float> dataArray, string position = position.top_right, int verticalOffset = 0, bool transposeTable = false, string textSize = size.small, int borderWidth = 2, string blankCellText = "") =>
fromArray(floatArrayToCellArray(dataArray), position, verticalOffset, transposeTable, textSize, borderWidth, blankCellText=blankCellText)
// @function Renders a debug message in a table at the desired location on screen.
// @param message (string) The message to render.
// @param position (string) Optional. The position of the debug message. Defaults to position.middle_right.
export debug(string message, string position = position.middle_right) =>
debugArray = array.new_string()
array.push(debugArray, message)
fromArray(debugArray, position=position)
// Experiment #1, build a table of RSI values, changing colors when the rsi is extreme
// Convenience function for adding to the matrices
getRsiCells(length) =>
rsi = math.round(ta.rsi(close, length))
rsiColor = rsi >= 70 or rsi <= 30 ? COLOR_HOT : COLOR_COOL
array.from(
Cell.new(str.format("{0}P", length), rsiColor),
Cell.new(str.format("{0,number,#}", rsi), rsiColor)
)
// Build up the matrix to be rendered
dataMatrix = matrix.new<Cell>()
matrix.add_row(dataMatrix, 0, getRsiCells(2))
matrix.add_row(dataMatrix, 1, getRsiCells(14))
fromMatrix(dataMatrix, position=position.bottom_right)
// Experiment #2, build the multitimeframe rsi table
rsi = ta.rsi(close, 2)
rsi1 = request.security(symbol=syminfo.tickerid, timeframe="5", expression=rsi, lookahead=barmerge.lookahead_on)
rsi2 = request.security(symbol=syminfo.tickerid, timeframe="15", expression=rsi, lookahead=barmerge.lookahead_on)
rsi3 = request.security(symbol=syminfo.tickerid, timeframe="60", expression=rsi, lookahead=barmerge.lookahead_on)
// Build up the matrix to be rendered
mtfDataMatrix = matrix.new<Cell>()
matrix.add_row(mtfDataMatrix, 0, array.from(Cell.new(" RSI ", COLOR_HOT)))
// Convenience function for adding to the matrices
addTimeframe(dataMatrix, timeframe, rsi) =>
cellArray = array.from(Cell.new(
str.format(" {0} \n {1,number,#} ", Utils.timeframeToString(timeframe), rsi),
rsi >= 70 or rsi <= 30 ? COLOR_HOT : COLOR_COOL
))
matrix.add_row(dataMatrix, matrix.rows(dataMatrix), cellArray)
addTimeframe(mtfDataMatrix, "5", rsi1)
addTimeframe(mtfDataMatrix, "15", rsi2)
addTimeframe(mtfDataMatrix, "60", rsi3)
// Add a row that spans all columns
spanData = Cell.new("This is a single cell of data")
blankData = Cell.new("")
spanData.colspan := 4
matrix.add_col(mtfDataMatrix, matrix.columns(mtfDataMatrix), array.from(spanData, blankData, blankData, blankData))
fromMatrix(mtfDataMatrix, position=position.top_right, verticalOffset=1, transposeTable=true)
// Experiment #3. Writing a collection of debug messages to the screen, illustrate text alignment
rightCell = Cell.new("Right aligned")
rightCell.align := text.align_right
fromArray(array.from(
Cell.new("Center aligned table cell"),
rightCell
),
position=position.top_left,
transposeTable=true,
verticalOffset=2)
// Experiment #4. Writing a single debug message to another location on the screen
debug("This is the last test", position.bottom_left) |
Price - TP/SL | https://www.tradingview.com/script/BLqukQSJ-Price-TP-SL/ | DinGrogu | https://www.tradingview.com/u/DinGrogu/ | 4 | library | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DinGrogu
//@version=5
library('price')
// ############################################################
// # FUNCTIONS
// ############################################################
// Get the limit or stop loss price.
f_limit_stop_price(_price, _percentage, _bars_minimum=0, _bars_since_entry=0) =>
price = 0.0
if (_percentage > 0)
if (_bars_minimum == 0)
price := _price
else if (_bars_minimum > 0)
if (_bars_since_entry > _bars_minimum)
price := _price
else
price := na
else
price := na
else
price := na
response = price
// @function - Get the take profit price.
f_take_profit_price(_entry_price, _take_profit_percentage, _atr_length=0) =>
atr_enabled = _atr_length > 0
atr = atr_enabled ? ta.sma(ta.tr, _atr_length) : 0
_take_profit_percentage > 0 ? atr_enabled ? _entry_price + (atr * _take_profit_percentage) : _entry_price + (_entry_price * (_take_profit_percentage / 100)) : na
// @function - Get the stop loss price.
f_stop_loss_price(_entry_price, _stop_loss_percentage, _atr_length=0) =>
atr_enabled = _atr_length > 0
atr = atr_enabled ? ta.sma(ta.tr, _atr_length) : 0
_stop_loss_percentage > 0 ? atr_enabled ? _entry_price - (atr * _stop_loss_percentage) : _entry_price - (_entry_price * (_stop_loss_percentage / 100)) : na
// Calculate the difference between 2 assets in percentage.
f_difference(_src_1, _src_2) =>
math.abs(((_src_1 - _src_2) / _src_2) * 100)
// A condition for percentage differences.
f_difference_condition(_src_1, _src_2, _percentage) =>
_src_2 > _src_1 and f_difference(_src_1, _src_2) > _percentage
// Price change up.
f_up(_length, _percentage, _src=close, _low=low, _high=high) =>
_lowest = _low[_length]
change = _lowest < _src and math.abs((_high - _lowest) / _lowest * 100) > _percentage
// Price change down.
f_down(_length, _percentage, _src=close, _low=low, _high=high) =>
_highest = _high[_length]
change = _highest > _src and math.abs((_low - _highest) / _highest * 100) > _percentage
// Get the latest price from lower timeframe.
f_lower_timeframe(_prices, _last=false) =>
price = 0.0
if (array.size(_prices) > 0)
if (_last)
price := array.last(_prices)
else
price := array.first(_prices)
price
// Get the order size from properties tab.
f_strategy_order_size() =>
if (strategy.closedtrades > 0)
order_size = strategy.initial_capital / strategy.closedtrades.entry_price(0)
math.round(strategy.closedtrades.size(0) / order_size, 2) * 100
else
order_size = 100
// Get the commission from properties tab.
f_strategy_commission() =>
strategy.closedtrades > 0 ? math.round(strategy.closedtrades.commission(0) / strategy.initial_capital * 100, 2) / 2 : 0
// ############################################################
// # EXPORT FUNCTIONS
// ############################################################
// function - Calculate the limit or stop price.
//
// usage example:
// limit_price = price.take_profit_price(take_profit_price, take_profit_percentage, take_profit_atr_length, take_profit_bars, bars_since_opened)
// stop_price = price.stop_loss_price(stop_loss_price, stop_loss_percentage, stop_loss_atr_length, stop_loss_bars, bars_since_opened)
// strategy.exit(id='TP/SL', comment='TP', from_entry='LONG', limit=limit_price, stop=stop_price)
// @param _price <float> - The source input.
// @param _percentage <float> - The percentage.
// @param _atr_length <int> - ATR length (0 to use percentage).
// @param _bars_minimum <int> - The number of bars to compare with elapsed bars.
// @param _bars_since_entry <int> - The number of bars elapsed.
export take_profit_price(series float _price, float _percentage, int _atr_length=0, int _bars_minimum=0, int _bars_since_entry=0) =>
price = f_take_profit_price(_price, _percentage, _atr_length)
f_limit_stop_price(price, _percentage, _bars_minimum, _bars_since_entry)
// @param _price <float> - The source input.
// @param _percentage <float> - The percentage.
// @param _atr_length <int> - ATR length (0 to use percentage).
// @param _bars_minimum <int> - The number of bars to compare with elapsed bars.
// @param _bars_since_entry <int> - The number of bars elapsed.
export stop_loss_price(series float _price, float _percentage, int _atr_length=0, int _bars_minimum=0, int _bars_since_entry=0) =>
price = f_stop_loss_price(_price, _percentage, _atr_length)
f_limit_stop_price(price, _percentage, _bars_minimum, _bars_since_entry)
// function - Get the difference in percentage between 2 prices.
// @param _src_1 <series float> - Source 1.
// @param _src_2 <series float> - Source 2.
export difference(series float _src_1, series float _src_2) =>
f_difference(_src_1, _src_2)
// @param _length <simple int> - Lookback length.
// @param _percentage <simple float> - The percentage.
// @param _src <series float> - Source.
// @param _low <series float> - Low.
// @param _high <series float> - High
export up(simple int _length, simple float _percentage, series float _src=close, series float _low=low, series float _high=high) =>
f_up(_length, _percentage, _src, _low, _high)
// @param _length <simple int> - Lookback length.
// @param _percentage <simple float> - The percentage.
// @param _src <series <series float> - Source.
// @param _low <series float> - Low.
// @param _high <series float> - High.
export down(simple int _length, simple float _percentage, series float _src=close, series float _low=low, series float _high=high) =>
f_down(_length, _percentage, _src, _low, _high)
// function - Get lower timeframe price.
//
// usage example:
// price.ltf(request.security_lower_tf(ticker, '1', close))
//
// @param _prices <array float> - timeframe.
// @param _last <bool> - Show the last bar close instead of first.
export ltf(array<float> _prices, bool _last=false) =>
f_lower_timeframe(_prices, _last)
// function - Get the strategy position size price.
export position() =>
math.round_to_mintick(strategy.position_avg_price)
// function - Get the order size from the properties tab.
export order_size() =>
f_strategy_order_size()
// function - Get the commission from the properties tab.
export commission() =>
f_strategy_commission()
|
ETFFinderLib | https://www.tradingview.com/script/dsZIQ4MM-ETFFinderLib/ | Steversteves | https://www.tradingview.com/u/Steversteves/ | 7 | library | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//Made for:
// ((
// (((((
// (((((((((
// (((((((((((((
// ((((((((((((((((
// ((((((((((((((((((((
// ((((( (((((((((((((
// (((( ((((((((((((((
// ######### (( (((
// ################ ####
// ################## #######
// #################################
// #####################################
// _____ _ _ _
// | _ |_|___ ___ ___ ___ ___|_|___| |_
// | __| | | -_|_ -| _| _| | . | _|
// |__| |_|_|_|___|___|___|_| |_| _|_|
// |_|
// LAST UPDATE: November 2023
// NEXT SCHEDULED UPDATE: May 2024
// Compendium to the ETFHoldingsLibrary.
// This Library permits you to search the ETFHoldingsLibrary by specific tickers and by sectors.
// The two main functions provided by this library are to search for a ticker within various ETFs (using the etf_search_ticker) and the
// ability to search a breakdown of sectors that each etf in the database contains using the etf_search_sectors function.
// You can use this library standalone if you want to search for an ETF of interest in the ETFHoldingsLibrary by ticker.
// You will need to export the etf_search_sectors function if you want to search the ETFs by sectors.
// © Steversteves
//@version=5
// @description TODO: add library description here
library("ETFFinderLib")
// @function searches the entire ETF library by ticker and identifies which ETFs hold a specific tickers.
// @param input string as displayed by the syminfo.ticker function in pinescript.
// @returns returns 2 arrays, holding_array (string array) and compo_array(float array)
export etf_search_ticker(string ticker) =>
string[] holding_array = array.new<string>()
float[] compo_array = array.new<float>()
int inter = 0
spy_holdings = array.from("MSFT", "AAPL", "AMZN", "NVDA", "GOOG", "META", "GOOGL", "BRK.B", "TSLA", "UHN"), spy_comp = array.from(7.14, 7.14, 3.44, 2.86, 2.09, 1.90, 1.80, 1.77, 1.58, 1.41)
qqq_holdings = array.from("AAPL", "MSFT", "AMZN", "NVDA", "META", "AVGO", "GOOGL", "GOOG", "TSLA","COST"), qqq_comp = array.from(11.01, 10.36, 5.66, 4.15, 3.87, 3.07, 3.04, 3.00, 2.63, 2.17)
arkk_holdings = array.from("COIN", "TSLA", "ZM", "ROKU", "PATH", "SQ", "RBLX", "DKNG", "TWLO", "U"), arkk_comp = array.from(9.07, 8.68, 7.96, 7.80, 7.06, 5.02, 4.48, 4.22, 4.07, 3.46)
xle_holdings = array.from("XOM", "CVX", "EOG", "COP", "MPC", "SLB", "PXD", "PSX", "VLO", "WMB"), xle_comp = array.from(22.40, 17.07, 4.85, 4.63, 4.54, 4.43, 4.18, 3.81, 3.37, 3.14)
brk_holdings = array.from("HPQ","ATVI", "MCO", "KHC", "OXY", "CVX", "KO", "AXP", "BAC", "AAPL" ), brk_comp = array.from(1.1, 1.3, 2.3, 3.9, 4.1, 6.7, 7.6, 7.7, 9.1, 46.4)
ita_holdings = array.from("RTX", "BA", "LMT", "NOC", "GD", "LHX", "TXT", "AXON", "TDG", "HWM"), ita_comp = array.from(18.59, 16.63, 8.38, 5.15, 5.12, 4.88, 4.63, 4.43, 4.34, 4.22)
iwm_holdings = array.from("SMCI", "MTDR", "CHRD", "MUR", "XTSLA", "LNW", "WFRD", "FIX", "SIGI", "CHX"), iwm_comp = array.from(0.53, 0.33, 0.33, 0.32, 0.32, 0.32, 0.32, 0.31, 0.30, 0.29)
xlf_holdings = array.from("BRK.B", "JPM", "V", "MA", "BAC", "WFC", "SPGI", "GS", "MMC", "PGR"), xlf_comp = array.from(13.85, 8.99, 8.41, 6.97, 4.05, 3.24, 2.53, 2.23, 2.09, 2.06)
xlv_holdings = array.from("UNH", "LLY", "JNJ", "MRK", "ABBV", "PFE", "TMO", "ABT", "AMGN", "DHR"), xlv_comp = array.from(10.73, 9.56, 7.73, 5.64, 5.39, 3.73, 3.71, 3.55, 2.96, 2.73)
vnq_holdings = array.from("VRTPX", "PLD", "AMT", "EQIX", "PSA", "CCI", "WELL", "SPG", "O", "DLR"), vnq_comp = array.from(12.67, 7.50, 5.55, 4.92, 3.02, 2.89, 2.84, 2.48, 2.43, 2.42)
xbi_holdings = array.from("MRTX", "APLS", "BPMC", "IMVT", "IONS", "VRTX", "SGEN", "GILD", "BHVN", "NBIX"), xbi_comp = array.from(2.26, 1.70, 1.60, 1.60, 1.56, 1.53, 1.51, 1.50, 1.47, 1.47)
blcr_holdings = array.from("MSFT", "AMZN", "AAPL", "GOOGL", "BRK.B", "META", "CMCSA", "UNH", "AMAT", "NVO"), blcr_comp = array.from(8.28, 5.43, 3.97, 2.89, 2.86, 2.85, 2.54, 2.32, 2.29, 2.20)
vgt_holdings = array.from("AAPL", "MSFT", "NVDA", "AVGO", "ADBE", "CSCO", "CRM", "ACN", "ORCL", "AMD"), vgt_comp = array.from(21.23, 17.04, 6.16, 3.18, 2.16, 2.03, 1.87, 1.79, 1.59, 1.53)
vwo_holdings = array.from("2330.TW", "0700.HK", "9988.HK", "RELIANCE.NS", "3690.HK", "HDFCBANK.NS", "INFY.NS", "PDD", "00939", "VALE3.SA"), vwo_comp = array.from(4.77, 3.36, 2.56, 1.31, 1.07, 0.97, 0.84, 0.82, 0.73, 0.71)
vig_holdings = array.from("MSFT", "AAPL", "XOM", "UNH", "JPM", "JNJ", "V", "PG", "AVGO", "MA"), vig_comp = array.from(4.85, 4.32, 3.39, 3.36, 3.03, 2.70, 2.55, 2.49, 2.39, 2.38)
vug_holdings = array.from("AAPL", "MSFT", "AMZN", "NVDA", "GOOGL", "TSLA", "META", "GOOG", "LLY", "V"), vug_comp = array.from(12.78, 11.79, 5.93, 5.13, 3.90, 3.39, 3.35, 3.27, 2.31, 1.80)
vtv_holdings = array.from("BRK.B", "XOM", "UNH", "JPM", "JNJ", "PG", "AVGO", "CVX", "ABBV", "MRK"), vtv_comp = array.from(3.81, 2.80, 2.78, 2.51, 2.23, 2.05, 2.04, 1.78, 1.57, 1.56)
vea_holdings = array.from("Nestle SA", "Novo Nordisk Class B", "Samsung Electronics Co Ltd", "ASML Holding NV", "Toyota Motor Corp", "Shell PLC", "Novartis AG Registered Shares", "AstraZeneca PLC", "Roche Holding AG", "LVMH Moet Hennessy Louis Vuitton SE"), vea_comp = array.from(1.49, 1.41, 1.18, 1.15, 1.06, 1.05, 1.04, 0.98, 0.93, 0.92)
dia_holdings = array.from("UHN", "MSFT", "GS", "HD", "MCD", "AMGN", "V", "CAT", "CRM", "BA"), dia_comp = array.from(10.67, 6.74, 6.05, 5.67, 5.22, 5.09, 4.68, 4.50, 4.00, 3.72)
fngg_holdings = array.from("MSFT", "NFLX", "META", "AVGO", "AAPL", "AMZN", "GOOGL", "NVDA", "SNOW"), fngg_comp = array.from(5.76, 5.71, 5.65, 5.64, 5.61, 5.26, 5.19, 5.13, 5.02)
fngu_holdings = array.from("META", "TSLA", "NVDA", "AMD", "NFLX", "AAPL", "AMZN", "SNOW", "MSFT", "GOOGL"), fngu_comp = array.from(12.53, 11.71, 10.66, 10.03, 9.65, 9.39, 9.35, 9.10, 8.84, 8.74)
bnge_holdings = array.from("NFLX", "NTES", "INTC", "NTDOY", "SONY", "DIS", "PDYPF", "YY", "EA", "TME"), bnge_comp = array.from(5.38, 4.71, 4.68, 4.60, 4.58, 4.57, 4.48, 4.45, 4.45, 4.29)
ixp_holdings = array.from("META", "GOOGL", "GOOG", "DIS", "VZ", "NFLX", "CMCSA", "TME", "T", "DTEA"), ixp_comp = array.from(19.12, 11.85, 10.18, 4.64, 4.59, 4.40, 4.38, 4.30, 3.42, 2.35)
fcom_holdings = array.from("META", "GOOGL", "GOOG", "VZ", "NFLX", "DIS", "CMCSA", "T", "TMUS", "CHTR"), fcom_comp = array.from(21.46, 12.64, 10.45, 4.91, 4.77, 4.46, 4.19, 3.80, 3.17, 1.74)
pnqi_holdings = array.from("MSFT", "META", "AMZN", "ADBE", "GOOG", "DIS", "NFLX", "UBER", "CRM", "BKNG"), pnqi_comp = array.from(8.93, 8.81, 8.34, 8.23, 7.89, 4.22, 4.11, 3.96, 3.92, 3.89)
chps_holdings = array.from("INTC", "AVGO", "NVDA", "QCOM", "AMAT", "LRCX", "SMH", "AMD", "MU", "ASML"), chps_comp = array.from(5.69, 4.96, 4.88, 4.72, 4.71, 4.67, 4.42, 4.38, 4.33, 4.22)
soxx_holdings = array.from("AMD", "AVGO", "NVDA", "INTC", "TXN", "MU", "QCOM", "KLAC", "MCHP", "AMAT"), soxx_comp = array.from(8.55, 8.37, 7.59, 7.42, 6.04, 4.39, 4.37, 4.30, 4.00, 3.98)
xlk_holdings = array.from("MSFT", "AAPL", "AVGO", "NVDA", "ADBE", "CSCO", "CRM", "ACN", "ORCL", "AMD"), xlk_comp = array.from(24.43, 23.15, 4.35, 4.23, 3.04, 2.66, 2.45, 2.35, 2.04, 1.99)
jets_holdings = array.from("AAL", "DAL", "LUV", "UAL", "SKYW", "SNCY", "ALK", "ALGT", "AC", "GD"), jets_comp = array.from(9.87, 9.47, 9.15, 9.14, 3.66, 3.32, 2.97, 2.89, 2.78, 2.74)
moon_holdings = array.from("NKLA", "COIN", "EH", "S", "DBX", "NNDM", "SNAP", "HOOD", "SQSP", "BIGC"), moon_comp = array.from(5.25, 4.18, 3.74, 3.30, 3.25, 3.21, 2.84, 2.81, 2.75, 2.75)
ufo_holdings = array.from("SIRI", "GRMN", "GSAT", "SKPJY", "TRMB", "SES", "DISH", "SATS", "IRDM", "VSAT"), ufo_comp = array.from(5.67, 5.56, 5.31, 5.28, 5.05, 4.69, 4.54, 4.41, 4.33, 4.22)
vdc_holdings = array.from("PG", "COST", "WMT", "PEP", "KO", "PM", "MDLZ", "MO", "CL", "STZ"), vdc_comp = array.from(12.42, 8.73, 8.23, 8.14, 8.04, 4.57, 3.78, 3.02, 2.27, 1.72)
iedi_holdings = array.from("AMZN", "HD", "COST", "WMT", "TJX", "LOW", "CMG", "ORLY", "ROST", "TGT"), iedi_comp = array.from(14.43, 10.12, 8.01, 6.30, 3.89, 3.81, 2.87, 2.71, 2.14, 1.98)
virs_holdings = array.from("AMZN", "WMT", "NVDA", "NFLX", "HD", "ABT", "MRK", "JNJ", "LOW", "SNY"), virs_comp = array.from(5.62, 5.56, 5.49, 5.11, 4.99, 4.85, 4.84, 4.83, 4.64, 4.61)
ftxg_holdings = array.from("KHC", "KO", "MDLZ", "PEP", "ADM", "GIS", "USFD", "TAP", "KDP", "STZ"), ftxg_comp = array.from(8.32, 8.26, 8.13, 8.03, 7.90, 4.22, 4.21, 3.98, 3.94, 3.93)
iyj_holdings = array.from("V", "MA", "ACN", "UNP", "HON", "RTX", "GE", "CAT", "BA", "LMT"), iyj_comp = array.from(7.86, 6.52, 3.88, 2.61, 2.52, 2.46, 2.43, 2.41, 2.15, 2.12)
fxr_holdings = array.from("BWXT", "EME", "KNX", "AGCO", "GPK", "SON", "MDU", "GTES", "TT", "SYF"), fxr_comp = array.from(1.35, 1.34, 1.33, 1.32, 1.31, 1.30, 1.29, 1.28, 1.28, 1.25)
iyc_holdings = array.from("AMZN", "TSLA", "COST", "WMT", "HD", "MCD", "NFLX", "DIS", "NKE", "LOW"), iyc_comp = array.from(14.92, 7.60, 4.49, 4.43, 4.31, 4.00, 3.86, 3.28, 2.69, 2.46)
xly_holdings = array.from("AMZN", "TSLA", "MCD", "NKE", "HD", "LOW", "SBUX", "TJX", "BKNG", "ORLY"), xly_comp = array.from(24.23, 16.79, 4.62, 4.32, 4.26, 3.83, 3.63, 3.47, 3.42, 1.93)
iyk_holdings = array.from("PG", "PEP", "KO", "PM", "MDLZ", "CVS", "MO", "MCK", "CL", "KMB"), iyk_comp = array.from(16.93, 10.85, 10.62, 6.75, 4.46, 4.40, 3.59, 3.14, 3.13, 2.05)
fdis_holdings = array.from("AMZN", "TSLA", "HD", "MCD", "NKE", "LOW", "SBUX", "BKNG", "TJX", "ORLY"), fdis_comp = array.from(24.10, 12.93, 6.51, 4.37, 2.89, 2.58, 2.47, 2.42, 2.35, 1.32)
pej_holdings = array.from("CMG", "ABNB", "MAR", "BKNG", "LVS", "RCL", "WBD", "DAL", "LGF.A", "SKYW"), pej_comp = array.from(5.80, 5.21, 5.18, 5.07, 4.97, 4.78, 4.44, 4.21, 3.38, 3.20)
iyt_holdings = array.from("UNP", "UPS", "UBER", "CSX", "NSC", "FDX", "ODFL", "DAL", "EXPD", "JBHT"), iyt_comp = array.from(18.64, 15.05, 12.72, 4.81, 4.80, 4.72, 4.43, 3.74, 3.19, 2.77)
ftxr_holdings = array.from("UNP", "GM", "UPS", "F", "TSLA", "CSX", "PCAR", "NSC", "FDX", "URI"), ftxr_comp = array.from(7.95, 7.70, 7.63, 7.36, 7.12, 4.52, 4.33, 4.26, 4.21, 3.90)
xtn_holdings = array.from("ARCB", "XPO", "MATX", "R", "CSX", "RXO", "SKYW", "UNP", "NSC", "EXPD"), xtn_comp = array.from(3.05, 2.89, 2.79, 2.72, 2.71, 2.71, 2.70, 2.67, 2.65, 2.59)
sea_holdings = array.from("TNK", "TRMD", "CICOF", "OROVY", "HAFNF", "AMKBY", "NPNYY", "MSLOY", "SITIF", "EVGOF"), sea_comp = array.from(5.21, 5.00, 4.95, 4.81, 4.75, 4.68, 4.45, 4.44, 4.24, 3.92)
if array.includes(spy_holdings, ticker)
array.push(holding_array, "SPY")
inter := array.indexof(spy_holdings, ticker)
array.push(compo_array, array.get(spy_comp, inter))
if array.includes(qqq_holdings, ticker)
array.push(holding_array, "QQQ")
inter := array.indexof(qqq_holdings, ticker)
array.push(compo_array, array.get(qqq_comp, inter))
if array.includes(arkk_holdings, ticker)
array.push(holding_array, "ARKK")
inter := array.indexof(arkk_holdings, ticker)
array.push(compo_array, array.get(arkk_comp, inter))
if array.includes(xle_holdings, ticker)
array.push(holding_array, "XLE")
inter := array.indexof(xle_holdings, ticker)
array.push(compo_array, array.get(xle_comp, inter))
if array.includes(brk_holdings, ticker)
array.push(holding_array, "BRK.B")
inter := array.indexof(brk_holdings, ticker)
array.push(compo_array, array.get(brk_comp, inter))
if array.includes(ita_holdings, ticker)
array.push(holding_array, "ITA")
inter := array.indexof(ita_holdings, ticker)
array.push(compo_array, array.get(ita_comp, inter))
if array.includes(iwm_holdings, ticker)
array.push(holding_array, "IWM")
inter := array.indexof(iwm_holdings, ticker)
array.push(compo_array, array.get(iwm_comp, inter))
if array.includes(xlf_holdings, ticker)
array.push(holding_array, "XLF")
inter := array.indexof(xlf_holdings, ticker)
array.push(compo_array, array.get(xlf_comp, inter))
if array.includes(xlv_holdings, ticker)
array.push(holding_array, "XLV")
inter := array.indexof(xlv_holdings, ticker)
array.push(compo_array, array.get(xlv_comp, inter))
if array.includes(vnq_holdings, ticker)
array.push(holding_array, "VNQ")
inter := array.indexof(vnq_holdings, ticker)
array.push(compo_array, array.get(vnq_comp, inter))
if array.includes(xbi_holdings, ticker)
array.push(holding_array, "XBI")
inter := array.indexof(xbi_holdings, ticker)
array.push(compo_array, array.get(xbi_comp, inter))
if array.includes(blcr_holdings, ticker)
array.push(holding_array, "BLCR")
inter := array.indexof(blcr_holdings, ticker)
array.push(compo_array, array.get(blcr_comp, inter))
if array.includes(vgt_holdings, ticker)
array.push(holding_array, "VGT")
inter := array.indexof(vgt_holdings, ticker)
array.push(compo_array, array.get(vgt_comp, inter))
if array.includes(vwo_holdings, ticker)
array.push(holding_array, "VWO")
inter := array.indexof(vwo_holdings, ticker)
array.push(compo_array, array.get(vwo_comp, inter))
if array.includes(vig_holdings, ticker)
array.push(holding_array, "VIG")
inter := array.indexof(vig_holdings, ticker)
array.push(compo_array, array.get(vig_comp, inter))
if array.includes(vug_holdings, ticker)
array.push(holding_array, "VUG")
inter := array.indexof(vug_holdings, ticker)
array.push(compo_array, array.get(vug_comp, inter))
if array.includes(vtv_holdings, ticker)
array.push(holding_array, "VTV")
inter := array.indexof(vtv_holdings, ticker)
array.push(compo_array, array.get(vtv_comp, inter))
if array.includes(vea_holdings, ticker)
array.push(holding_array, "VEA")
inter := array.indexof(vea_holdings, ticker)
array.push(compo_array, array.get(vea_comp, inter))
if array.includes(dia_holdings, ticker)
array.push(holding_array, "DIA")
inter := array.indexof(dia_holdings, ticker)
array.push(compo_array, array.get(dia_comp, inter))
if array.includes(fngg_holdings, ticker)
array.push(holding_array, "FNGG")
inter := array.indexof(fngg_holdings, ticker)
array.push(compo_array, array.get(fngg_comp, inter))
if array.includes(fngu_holdings, ticker)
array.push(holding_array, "FNGU")
inter := array.indexof(fngu_holdings, ticker)
array.push(compo_array, array.get(fngu_comp, inter))
if array.includes(bnge_holdings, ticker)
array.push(holding_array, "BNGE")
inter := array.indexof(bnge_holdings, ticker)
array.push(compo_array, array.get(bnge_comp, inter))
if array.includes(ixp_holdings, ticker)
array.push(holding_array, "IXP")
inter := array.indexof(ixp_holdings, ticker)
array.push(compo_array, array.get(ixp_comp, inter))
if array.includes(fcom_holdings, ticker)
array.push(holding_array, "FCOM")
inter := array.indexof(fcom_holdings, ticker)
array.push(compo_array, array.get(fcom_comp, inter))
if array.includes(pnqi_holdings, ticker)
array.push(holding_array, "PNQI")
inter := array.indexof(pnqi_holdings, ticker)
array.push(compo_array, array.get(pnqi_comp, inter))
if array.includes(chps_holdings, ticker)
array.push(holding_array, "CHPS")
inter := array.indexof(chps_holdings, ticker)
array.push(compo_array, array.get(chps_comp, inter))
if array.includes(soxx_holdings, ticker)
array.push(holding_array, "SOXX")
inter := array.indexof(soxx_holdings, ticker)
array.push(compo_array, array.get(soxx_comp, inter))
if array.includes(xlk_holdings, ticker)
array.push(holding_array, "XLK")
inter := array.indexof(xlk_holdings, ticker)
array.push(compo_array, array.get(xlk_comp, inter))
if array.includes(moon_holdings, ticker)
array.push(holding_array, "MOON")
inter := array.indexof(moon_holdings, ticker)
array.push(compo_array, array.get(moon_comp, inter))
if array.includes(ufo_holdings, ticker)
array.push(holding_array, "UFO")
inter := array.indexof(ufo_holdings, ticker)
array.push(compo_array, array.get(ufo_comp, inter))
if array.includes(vdc_holdings, ticker)
array.push(holding_array, "VDC")
inter := array.indexof(vdc_holdings, ticker)
array.push(compo_array, array.get(vdc_comp, inter))
if array.includes(iedi_holdings, ticker)
array.push(holding_array, "IEDI")
inter := array.indexof(iedi_holdings, ticker)
array.push(compo_array, array.get(iedi_comp, inter))
if array.includes(virs_holdings, ticker)
array.push(holding_array, "VIRS")
inter := array.indexof(virs_holdings, ticker)
array.push(compo_array, array.get(virs_comp, inter))
if array.includes(ftxg_holdings, ticker)
array.push(holding_array, "FTXG")
inter := array.indexof(ftxg_holdings, ticker)
array.push(compo_array, array.get(ftxg_comp, inter))
if array.includes(jets_holdings, ticker)
array.push(holding_array, "JETS")
inter := array.indexof(jets_holdings, ticker)
array.push(compo_array, array.get(jets_comp, inter))
if array.includes(iyj_holdings, ticker)
array.push(holding_array, "IYJ")
inter := array.indexof(iyj_holdings, ticker)
array.push(compo_array, array.get(iyj_comp, inter))
if array.includes(fxr_holdings, ticker)
array.push(holding_array, "FXR")
inter := array.indexof(fxr_holdings, ticker)
array.push(compo_array, array.get(fxr_comp, inter))
if array.includes(iyc_holdings, ticker)
array.push(holding_array, "IYC")
inter := array.indexof(iyc_holdings, ticker)
array.push(compo_array, array.get(iyc_comp, inter))
if array.includes(xly_holdings, ticker)
array.push(holding_array, "XLY")
inter := array.indexof(xly_holdings, ticker)
array.push(compo_array, array.get(xly_comp, inter))
if array.includes(iyk_holdings, ticker)
array.push(holding_array, "IYK")
inter := array.indexof(iyk_holdings, ticker)
array.push(compo_array, array.get(iyk_comp, inter))
if array.includes(fdis_holdings, ticker)
array.push(holding_array, "FDIS")
inter := array.indexof(fdis_holdings, ticker)
array.push(compo_array, array.get(fdis_comp, inter))
if array.includes(pej_holdings, ticker)
array.push(holding_array, "PEJ")
inter := array.indexof(pej_holdings, ticker)
array.push(compo_array, array.get(pej_comp, inter))
if array.includes(iyt_holdings, ticker)
array.push(holding_array, "IYT")
inter := array.indexof(iyt_holdings, ticker)
array.push(compo_array, array.get(iyt_comp, inter))
if array.includes(ftxr_holdings, ticker)
array.push(holding_array, "FTXR")
inter := array.indexof(ftxr_holdings, ticker)
array.push(compo_array, array.get(ftxr_comp, inter))
if array.includes(xtn_holdings, ticker)
array.push(holding_array, "XTN")
inter := array.indexof(xtn_holdings, ticker)
array.push(compo_array, array.get(xtn_comp, inter))
if array.includes(sea_holdings, ticker)
array.push(holding_array, "SEA")
inter := array.indexof(sea_holdings, ticker)
array.push(compo_array, array.get(sea_comp, inter))
[holding_array, compo_array]
// @function searches the entire ETF library by sector and pulls by desired sector
// @param input string variable for sector, must be one of the following strings "Basic Materials", "Consumer Cyclical", "Financial Services", "Real Estate", "Consumer Defensive", "Healthcare", "Utilities", "Communication Services", "Energy", "Industrials", "Technology"
// @returns returns 2 arrays, sector_array (string array) and composition array (float array)
export etf_search_sectors(string sector) =>
string[] sector_array = array.new<string>()
float[] composition_array = array.new<float>()
int i = 0
spy_sectors = array.from(2.19, 10.74, 12.32, 2.35, 6.58, 13.19, 2.50, 8.71, 4.54, 8.19, 28.69)
qqq_sectors = array.from(0, 13.83, 0.50, 0.27, 6.36, 7.00, 1.30, 15.72, 0.56, 4.92, 49.53)
arkk_sectors = array.from(0, 12.90, 9.07, 0, 0.23, 24.57, 0, 17.40, 0, 1.07, 34.77)
xle_sectors = array.from(0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 100, 0.00, 0.00)
brk_sectors = array.from(0.18, 1.01, 21.86, 0, 10.94, 1.06, 0, 2.16, 9.34, 0.15, 53.25)
ita_sectors = array.from(0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 100.0, 0.00)
iwm_sectors = array.from(4.71, 10.16, 14.43, 7.32, 4.43, 14.37, 2.97, 2.18, 8.47, 15.46, 15.50)
xlf_sectors = array.from(0.00, 0.00, 96.59, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.62, 2.80)
xlv_sectors = array.from(0.00, 0.00, 0.00, 0.00, 0.00, 100.0, 0.00, 0.00, 0.00, 0.00, 0.00)
vnq_sectors = array.from(0.00, 0.00, 0.00, 99.17, 0.00, 0.00, 0.00, 0.82, 0.00, 0.00, 0.00)
xbi_sectors = array.from(0.00, 0.00, 0.00, 0.00, 0.00, 100.00, 0.00, 0.00, 0.00, 0.00, 0.00)
blcr_sectors = array.from(4.24, 11.88, 13.43, 0.00, 6.30, 15.10, 0.00, 13.56, 5.04, 3.44, 27.01)
vgt_sectors = array.from(0.02, 0.00, 0.10, 00.00, 0.00, 0.01, 0.00, 0.19, 0.00, 0.33, 99.35)
vwo_sectors = array.from(8.68, 13.39, 21.13, 2.82, 6.38, 4.64, 3.34, 9.04, 5.69, 8.21, 16.67)
vig_sectors = array.from(4.15, 7.17, 18.23, 0.00, 12.07, 15.47, 2.67, 1.37, 3.53, 12.97, 22.36)
vug_sectors = array.from(1.73, 16.88, 5.99, 1.71, 2.22, 8.76, 0.00, 13.72, 1.36, 3.36, 44.27)
vtv_sectors = array.from(2.72, 3.19, 19.92, 3.07, 11.26, 18.99, 5.06, 3.23, 8.45, 13.55, 10.54)
vea_sectors = array.from(7.79, 10.85, 19.03, 3.32, 8.08, 11.09, 2.91, 3.97, 5.91, 16.90, 10.14)
dia_sectors = array.from(0.96, 12.95, 19.77, 0.00, 7.38, 21.20, 0.00, 2.33, 2.91, 13.70, 18.80)
fngg_sectors = array.from(0.00, 17.84, 0.00, 0.00, 0.00, 0.00, 0.00, 31.11, 0.00, 0.00, 51.04)
fngu_sectors = array.from(0.00, 21.06, 0.00, 0.00, 0.00, 0.00, 0.00, 30.92, 0.00, 0.00, 48.02)
bnge_sectors = array.from(0.00, 21.23, 0.00, 0.00, 0.00, 0.00, 0.00, 59.44, 0.00, 0.00, 19.33)
ixp_sectors = array.from(0.00, 0.21, 0.00, 0.54, 0.00, 0.00, 0.00, 99.25, 0.00, 0.00, 0.00)
fcom_sectors = array.from(0.00, 0.63, 0.00, 0.00, 0.00, 0.00, 0.00, 96.97, 0.00, 0.09, 2.31)
pnqi_sectors = array.from(0.00, 26.74, 3.53, 1.50, 0.05, 0.16, 0.00, 32.38, 0.00, 0.00, 35.64)
chps_sectors = array.from(0.30, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.51, 98.19)
soxx_sectors = array.from(0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 100.00)
xlk_sectors = array.from(0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 100.00)
moon_sectors = array.from(0.00, 8.87, 6.63, 0.00, 0.00, 22.66, 0.00, 5.32, 0.00, 16.45, 40.07)
ufo_sectors = array.from(0.00, 0.67, 0.00, 0.00, 0.00, 0.00, 0.00, 34.59, 0.00, 31.75, 32.99)
vdc_sectors = array.from(0.20, 0.72, 0.00, 0.00, 98.21, 0.71, 0.00, 0.00, 0.00, 0.16, 0.00)
iedi_sectors = array.from(0.00, 67.59, 1.16, 0.40, 23.16, 0.48, 0.00, 1.67, 0.08, 3.71, 1.75)
virs_sectors = array.from(2.06, 15.28, 0.00, 0.00, 11.37, 52.82, 0.00, 5.12, 0.00, 4.43, 8.92)
ftxg_sectors = array.from(0.00, 0.00, 0.00, 0.00, 100.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00)
jets_sectors = array.from(0.00, 9.67, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 90.33, 0.00)
// Search for sector
if sector == "Basic Materials"
i := 0
if array.get(spy_sectors, i) > 0
array.push(sector_array, "SPY")
array.push(composition_array, array.get(spy_sectors, i))
if array.get(qqq_sectors, i) > 0
array.push(sector_array, "QQQ")
array.push(composition_array, array.get(qqq_sectors, i))
if array.get(arkk_sectors, i) > 0
array.push(sector_array, "ARKK")
array.push(composition_array, array.get(arkk_sectors, i))
if array.get(xle_sectors, i) > 0
array.push(sector_array, "XLE")
array.push(composition_array, array.get(xle_sectors, i))
if array.get(brk_sectors, i) > 0
array.push(sector_array, "BRK.B")
array.push(composition_array, array.get(brk_sectors, i))
if array.get(ita_sectors, i) > 0
array.push(sector_array, "ITA")
array.push(composition_array, array.get(ita_sectors, i))
if array.get(iwm_sectors, i) > 0
array.push(sector_array, "IWM")
array.push(composition_array, array.get(iwm_sectors, i))
if array.get(xlf_sectors, i) > 0
array.push(sector_array, "XLF")
array.push(composition_array, array.get(xlf_sectors, i))
if array.get(xlv_sectors, i) > 0
array.push(sector_array, "XLV")
array.push(composition_array, array.get(xlv_sectors, i))
if array.get(vnq_sectors, i) > 0
array.push(sector_array, "VNQ")
array.push(composition_array, array.get(vnq_sectors, i))
if array.get(xbi_sectors, i) > 0
array.push(sector_array, "XBI")
array.push(composition_array, array.get(xbi_sectors, i))
if array.get(blcr_sectors, i) > 0
array.push(sector_array, "BLCR")
array.push(composition_array, array.get(blcr_sectors, i))
if array.get(vgt_sectors, i) > 0
array.push(sector_array, "VGT")
array.push(composition_array, array.get(vgt_sectors, i))
if array.get(vwo_sectors, i) > 0
array.push(sector_array, "VWO")
array.push(composition_array, array.get(vwo_sectors, i))
if array.get(vig_sectors, i) > 0
array.push(sector_array, "VIG")
array.push(composition_array, array.get(vig_sectors, i))
if array.get(vug_sectors, i) > 0
array.push(sector_array, "VUG")
array.push(composition_array, array.get(vug_sectors, i))
if array.get(vtv_sectors, i) > 0
array.push(sector_array, "VTV")
array.push(composition_array, array.get(vtv_sectors, i))
if array.get(vea_sectors, i) > 0
array.push(sector_array, "VEA")
array.push(composition_array, array.get(vea_sectors, i))
if array.get(dia_sectors, i) > 0
array.push(sector_array, "DIA")
array.push(composition_array, array.get(dia_sectors, i))
if array.get(fngg_sectors, i) > 0
array.push(sector_array, "FNGG")
array.push(composition_array, array.get(fngg_sectors, i))
if array.get(fngu_sectors, i) > 0
array.push(sector_array, "FNGU")
array.push(composition_array, array.get(fngu_sectors, i))
if array.get(bnge_sectors, i) > 0
array.push(sector_array, "BNGE")
array.push(composition_array, array.get(bnge_sectors, i))
if array.get(ixp_sectors, i) > 0
array.push(sector_array, "IXP")
array.push(composition_array, array.get(ixp_sectors, i))
if array.get(fcom_sectors, i) > 0
array.push(sector_array, "FCOM")
array.push(composition_array, array.get(fcom_sectors, i))
if array.get(pnqi_sectors, i) > 0
array.push(sector_array, "PNQI")
array.push(composition_array, array.get(pnqi_sectors, i))
if array.get(chps_sectors, i) > 0
array.push(sector_array, "CHPS")
array.push(composition_array, array.get(chps_sectors, i))
if array.get(soxx_sectors, i) > 0
array.push(sector_array, "SOXX")
array.push(composition_array, array.get(soxx_sectors, i))
if array.get(xlk_sectors, i) > 0
array.push(sector_array, "XLK")
array.push(composition_array, array.get(xlk_sectors, i))
if array.get(moon_sectors, i) > 0
array.push(sector_array, "MOON")
array.push(composition_array, array.get(moon_sectors, i))
if array.get(ufo_sectors, i) > 0
array.push(sector_array, "UFO")
array.push(composition_array, array.get(ufo_sectors, i))
if array.get(vdc_sectors, i) > 0
array.push(sector_array, "VDC")
array.push(composition_array, array.get(vdc_sectors, i))
if array.get(iedi_sectors, i) > 0
array.push(sector_array, "IEDI")
array.push(composition_array, array.get(iedi_sectors, i))
if array.get(virs_sectors, i) > 0
array.push(sector_array, "VIRS")
array.push(composition_array, array.get(virs_sectors, i))
if array.get(ftxg_sectors, i) > 0
array.push(sector_array, "FTXG")
array.push(composition_array, array.get(ftxg_sectors, i))
if array.get(jets_sectors, i) > 0
array.push(sector_array, "JETS")
array.push(composition_array, array.get(jets_sectors, i))
if sector == "Consumer Cyclical"
i := 1
if array.get(spy_sectors, i) > 0
array.push(sector_array, "SPY")
array.push(composition_array, array.get(spy_sectors, i))
if array.get(qqq_sectors, i) > 0
array.push(sector_array, "QQQ")
array.push(composition_array, array.get(qqq_sectors, i))
if array.get(arkk_sectors, i) > 0
array.push(sector_array, "ARKK")
array.push(composition_array, array.get(arkk_sectors, i))
if array.get(xle_sectors, i) > 0
array.push(sector_array, "XLE")
array.push(composition_array, array.get(xle_sectors, i))
if array.get(brk_sectors, i) > 0
array.push(sector_array, "BRK.B")
array.push(composition_array, array.get(brk_sectors, i))
if array.get(ita_sectors, i) > 0
array.push(sector_array, "ITA")
array.push(composition_array, array.get(ita_sectors, i))
if array.get(iwm_sectors, i) > 0
array.push(sector_array, "IWM")
array.push(composition_array, array.get(iwm_sectors, i))
if array.get(xlf_sectors, i) > 0
array.push(sector_array, "XLF")
array.push(composition_array, array.get(xlf_sectors, i))
if array.get(xlv_sectors, i) > 0
array.push(sector_array, "XLV")
array.push(composition_array, array.get(xlv_sectors, i))
if array.get(vnq_sectors, i) > 0
array.push(sector_array, "VNQ")
array.push(composition_array, array.get(vnq_sectors, i))
if array.get(xbi_sectors, i) > 0
array.push(sector_array, "XBI")
array.push(composition_array, array.get(xbi_sectors, i))
if array.get(blcr_sectors, i) > 0
array.push(sector_array, "BLCR")
array.push(composition_array, array.get(blcr_sectors, i))
if array.get(vgt_sectors, i) > 0
array.push(sector_array, "VGT")
array.push(composition_array, array.get(vgt_sectors, i))
if array.get(vwo_sectors, i) > 0
array.push(sector_array, "VWO")
array.push(composition_array, array.get(vwo_sectors, i))
if array.get(vig_sectors, i) > 0
array.push(sector_array, "VIG")
array.push(composition_array, array.get(vig_sectors, i))
if array.get(vug_sectors, i) > 0
array.push(sector_array, "VUG")
array.push(composition_array, array.get(vug_sectors, i))
if array.get(vtv_sectors, i) > 0
array.push(sector_array, "VTV")
array.push(composition_array, array.get(vtv_sectors, i))
if array.get(vea_sectors, i) > 0
array.push(sector_array, "VEA")
array.push(composition_array, array.get(vea_sectors, i))
if array.get(dia_sectors, i) > 0
array.push(sector_array, "DIA")
array.push(composition_array, array.get(dia_sectors, i))
if array.get(fngg_sectors, i) > 0
array.push(sector_array, "FNGG")
array.push(composition_array, array.get(fngg_sectors, i))
if array.get(fngu_sectors, i) > 0
array.push(sector_array, "FNGU")
array.push(composition_array, array.get(fngu_sectors, i))
if array.get(bnge_sectors, i) > 0
array.push(sector_array, "BNGE")
array.push(composition_array, array.get(bnge_sectors, i))
if array.get(ixp_sectors, i) > 0
array.push(sector_array, "IXP")
array.push(composition_array, array.get(ixp_sectors, i))
if array.get(fcom_sectors, i) > 0
array.push(sector_array, "FCOM")
array.push(composition_array, array.get(fcom_sectors, i))
if array.get(pnqi_sectors, i) > 0
array.push(sector_array, "PNQI")
array.push(composition_array, array.get(pnqi_sectors, i))
if array.get(chps_sectors, i) > 0
array.push(sector_array, "CHPS")
array.push(composition_array, array.get(chps_sectors, i))
if array.get(soxx_sectors, i) > 0
array.push(sector_array, "SOXX")
array.push(composition_array, array.get(soxx_sectors, i))
if array.get(xlk_sectors, i) > 0
array.push(sector_array, "XLK")
array.push(composition_array, array.get(xlk_sectors, i))
if array.get(moon_sectors, i) > 0
array.push(sector_array, "MOON")
array.push(composition_array, array.get(moon_sectors, i))
if array.get(ufo_sectors, i) > 0
array.push(sector_array, "UFO")
array.push(composition_array, array.get(ufo_sectors, i))
if array.get(vdc_sectors, i) > 0
array.push(sector_array, "VDC")
array.push(composition_array, array.get(vdc_sectors, i))
if array.get(iedi_sectors, i) > 0
array.push(sector_array, "IEDI")
array.push(composition_array, array.get(iedi_sectors, i))
if array.get(virs_sectors, i) > 0
array.push(sector_array, "VIRS")
array.push(composition_array, array.get(virs_sectors, i))
if array.get(ftxg_sectors, i) > 0
array.push(sector_array, "FTXG")
array.push(composition_array, array.get(ftxg_sectors, i))
if array.get(jets_sectors, i) > 0
array.push(sector_array, "JETS")
array.push(composition_array, array.get(jets_sectors, i))
if sector == "Financial Services"
i := 2
if array.get(spy_sectors, i) > 0
array.push(sector_array, "SPY")
array.push(composition_array, array.get(spy_sectors, i))
if array.get(qqq_sectors, i) > 0
array.push(sector_array, "QQQ")
array.push(composition_array, array.get(qqq_sectors, i))
if array.get(arkk_sectors, i) > 0
array.push(sector_array, "ARKK")
array.push(composition_array, array.get(arkk_sectors, i))
if array.get(xle_sectors, i) > 0
array.push(sector_array, "XLE")
array.push(composition_array, array.get(xle_sectors, i))
if array.get(brk_sectors, i) > 0
array.push(sector_array, "BRK.B")
array.push(composition_array, array.get(brk_sectors, i))
if array.get(ita_sectors, i) > 0
array.push(sector_array, "ITA")
array.push(composition_array, array.get(ita_sectors, i))
if array.get(iwm_sectors, i) > 0
array.push(sector_array, "IWM")
array.push(composition_array, array.get(iwm_sectors, i))
if array.get(xlf_sectors, i) > 0
array.push(sector_array, "XLF")
array.push(composition_array, array.get(xlf_sectors, i))
if array.get(xlv_sectors, i) > 0
array.push(sector_array, "XLV")
array.push(composition_array, array.get(xlv_sectors, i))
if array.get(vnq_sectors, i) > 0
array.push(sector_array, "VNQ")
array.push(composition_array, array.get(vnq_sectors, i))
if array.get(xbi_sectors, i) > 0
array.push(sector_array, "XBI")
array.push(composition_array, array.get(xbi_sectors, i))
if array.get(blcr_sectors, i) > 0
array.push(sector_array, "BLCR")
array.push(composition_array, array.get(blcr_sectors, i))
if array.get(vgt_sectors, i) > 0
array.push(sector_array, "VGT")
array.push(composition_array, array.get(vgt_sectors, i))
if array.get(vwo_sectors, i) > 0
array.push(sector_array, "VWO")
array.push(composition_array, array.get(vwo_sectors, i))
if array.get(vig_sectors, i) > 0
array.push(sector_array, "VIG")
array.push(composition_array, array.get(vig_sectors, i))
if array.get(vug_sectors, i) > 0
array.push(sector_array, "VUG")
array.push(composition_array, array.get(vug_sectors, i))
if array.get(vtv_sectors, i) > 0
array.push(sector_array, "VTV")
array.push(composition_array, array.get(vtv_sectors, i))
if array.get(vea_sectors, i) > 0
array.push(sector_array, "VEA")
array.push(composition_array, array.get(vea_sectors, i))
if array.get(dia_sectors, i) > 0
array.push(sector_array, "DIA")
array.push(composition_array, array.get(dia_sectors, i))
if array.get(fngg_sectors, i) > 0
array.push(sector_array, "FNGG")
array.push(composition_array, array.get(fngg_sectors, i))
if array.get(fngu_sectors, i) > 0
array.push(sector_array, "FNGU")
array.push(composition_array, array.get(fngu_sectors, i))
if array.get(bnge_sectors, i) > 0
array.push(sector_array, "BNGE")
array.push(composition_array, array.get(bnge_sectors, i))
if array.get(ixp_sectors, i) > 0
array.push(sector_array, "IXP")
array.push(composition_array, array.get(ixp_sectors, i))
if array.get(fcom_sectors, i) > 0
array.push(sector_array, "FCOM")
array.push(composition_array, array.get(fcom_sectors, i))
if array.get(pnqi_sectors, i) > 0
array.push(sector_array, "PNQI")
array.push(composition_array, array.get(pnqi_sectors, i))
if array.get(chps_sectors, i) > 0
array.push(sector_array, "CHPS")
array.push(composition_array, array.get(chps_sectors, i))
if array.get(soxx_sectors, i) > 0
array.push(sector_array, "SOXX")
array.push(composition_array, array.get(soxx_sectors, i))
if array.get(xlk_sectors, i) > 0
array.push(sector_array, "XLK")
array.push(composition_array, array.get(xlk_sectors, i))
if array.get(moon_sectors, i) > 0
array.push(sector_array, "MOON")
array.push(composition_array, array.get(moon_sectors, i))
if array.get(ufo_sectors, i) > 0
array.push(sector_array, "UFO")
array.push(composition_array, array.get(ufo_sectors, i))
if array.get(vdc_sectors, i) > 0
array.push(sector_array, "VDC")
array.push(composition_array, array.get(vdc_sectors, i))
if array.get(iedi_sectors, i) > 0
array.push(sector_array, "IEDI")
array.push(composition_array, array.get(iedi_sectors, i))
if array.get(virs_sectors, i) > 0
array.push(sector_array, "VIRS")
array.push(composition_array, array.get(virs_sectors, i))
if array.get(ftxg_sectors, i) > 0
array.push(sector_array, "FTXG")
array.push(composition_array, array.get(ftxg_sectors, i))
if array.get(jets_sectors, i) > 0
array.push(sector_array, "JETS")
array.push(composition_array, array.get(jets_sectors, i))
if sector == "Real Estate"
i := 3
if array.get(spy_sectors, i) > 0
array.push(sector_array, "SPY")
array.push(composition_array, array.get(spy_sectors, i))
if array.get(qqq_sectors, i) > 0
array.push(sector_array, "QQQ")
array.push(composition_array, array.get(qqq_sectors, i))
if array.get(arkk_sectors, i) > 0
array.push(sector_array, "ARKK")
array.push(composition_array, array.get(arkk_sectors, i))
if array.get(xle_sectors, i) > 0
array.push(sector_array, "XLE")
array.push(composition_array, array.get(xle_sectors, i))
if array.get(brk_sectors, i) > 0
array.push(sector_array, "BRK.B")
array.push(composition_array, array.get(brk_sectors, i))
if array.get(ita_sectors, i) > 0
array.push(sector_array, "ITA")
array.push(composition_array, array.get(ita_sectors, i))
if array.get(iwm_sectors, i) > 0
array.push(sector_array, "IWM")
array.push(composition_array, array.get(iwm_sectors, i))
if array.get(xlf_sectors, i) > 0
array.push(sector_array, "XLF")
array.push(composition_array, array.get(xlf_sectors, i))
if array.get(xlv_sectors, i) > 0
array.push(sector_array, "XLV")
array.push(composition_array, array.get(xlv_sectors, i))
if array.get(vnq_sectors, i) > 0
array.push(sector_array, "VNQ")
array.push(composition_array, array.get(vnq_sectors, i))
if array.get(xbi_sectors, i) > 0
array.push(sector_array, "XBI")
array.push(composition_array, array.get(xbi_sectors, i))
if array.get(blcr_sectors, i) > 0
array.push(sector_array, "BLCR")
array.push(composition_array, array.get(blcr_sectors, i))
if array.get(vgt_sectors, i) > 0
array.push(sector_array, "VGT")
array.push(composition_array, array.get(vgt_sectors, i))
if array.get(vwo_sectors, i) > 0
array.push(sector_array, "VWO")
array.push(composition_array, array.get(vwo_sectors, i))
if array.get(vig_sectors, i) > 0
array.push(sector_array, "VIG")
array.push(composition_array, array.get(vig_sectors, i))
if array.get(vug_sectors, i) > 0
array.push(sector_array, "VUG")
array.push(composition_array, array.get(vug_sectors, i))
if array.get(vtv_sectors, i) > 0
array.push(sector_array, "VTV")
array.push(composition_array, array.get(vtv_sectors, i))
if array.get(vea_sectors, i) > 0
array.push(sector_array, "VEA")
array.push(composition_array, array.get(vea_sectors, i))
if array.get(dia_sectors, i) > 0
array.push(sector_array, "DIA")
array.push(composition_array, array.get(dia_sectors, i))
if array.get(fngg_sectors, i) > 0
array.push(sector_array, "FNGG")
array.push(composition_array, array.get(fngg_sectors, i))
if array.get(fngu_sectors, i) > 0
array.push(sector_array, "FNGU")
array.push(composition_array, array.get(fngu_sectors, i))
if array.get(bnge_sectors, i) > 0
array.push(sector_array, "BNGE")
array.push(composition_array, array.get(bnge_sectors, i))
if array.get(ixp_sectors, i) > 0
array.push(sector_array, "IXP")
array.push(composition_array, array.get(ixp_sectors, i))
if array.get(fcom_sectors, i) > 0
array.push(sector_array, "FCOM")
array.push(composition_array, array.get(fcom_sectors, i))
if array.get(pnqi_sectors, i) > 0
array.push(sector_array, "PNQI")
array.push(composition_array, array.get(pnqi_sectors, i))
if array.get(chps_sectors, i) > 0
array.push(sector_array, "CHPS")
array.push(composition_array, array.get(chps_sectors, i))
if array.get(soxx_sectors, i) > 0
array.push(sector_array, "SOXX")
array.push(composition_array, array.get(soxx_sectors, i))
if array.get(xlk_sectors, i) > 0
array.push(sector_array, "XLK")
array.push(composition_array, array.get(xlk_sectors, i))
if array.get(moon_sectors, i) > 0
array.push(sector_array, "MOON")
array.push(composition_array, array.get(moon_sectors, i))
if array.get(ufo_sectors, i) > 0
array.push(sector_array, "UFO")
array.push(composition_array, array.get(ufo_sectors, i))
if array.get(vdc_sectors, i) > 0
array.push(sector_array, "VDC")
array.push(composition_array, array.get(vdc_sectors, i))
if array.get(iedi_sectors, i) > 0
array.push(sector_array, "IEDI")
array.push(composition_array, array.get(iedi_sectors, i))
if array.get(virs_sectors, i) > 0
array.push(sector_array, "VIRS")
array.push(composition_array, array.get(virs_sectors, i))
if array.get(ftxg_sectors, i) > 0
array.push(sector_array, "FTXG")
array.push(composition_array, array.get(ftxg_sectors, i))
if array.get(jets_sectors, i) > 0
array.push(sector_array, "JETS")
array.push(composition_array, array.get(jets_sectors, i))
if sector == "Consumer Defensive"
i := 4
if array.get(spy_sectors, i) > 0
array.push(sector_array, "SPY")
array.push(composition_array, array.get(spy_sectors, i))
if array.get(qqq_sectors, i) > 0
array.push(sector_array, "QQQ")
array.push(composition_array, array.get(qqq_sectors, i))
if array.get(arkk_sectors, i) > 0
array.push(sector_array, "ARKK")
array.push(composition_array, array.get(arkk_sectors, i))
if array.get(xle_sectors, i) > 0
array.push(sector_array, "XLE")
array.push(composition_array, array.get(xle_sectors, i))
if array.get(brk_sectors, i) > 0
array.push(sector_array, "BRK.B")
array.push(composition_array, array.get(brk_sectors, i))
if array.get(ita_sectors, i) > 0
array.push(sector_array, "ITA")
array.push(composition_array, array.get(ita_sectors, i))
if array.get(iwm_sectors, i) > 0
array.push(sector_array, "IWM")
array.push(composition_array, array.get(iwm_sectors, i))
if array.get(xlf_sectors, i) > 0
array.push(sector_array, "XLF")
array.push(composition_array, array.get(xlf_sectors, i))
if array.get(xlv_sectors, i) > 0
array.push(sector_array, "XLV")
array.push(composition_array, array.get(xlv_sectors, i))
if array.get(vnq_sectors, i) > 0
array.push(sector_array, "VNQ")
array.push(composition_array, array.get(vnq_sectors, i))
if array.get(xbi_sectors, i) > 0
array.push(sector_array, "XBI")
array.push(composition_array, array.get(xbi_sectors, i))
if array.get(blcr_sectors, i) > 0
array.push(sector_array, "BLCR")
array.push(composition_array, array.get(blcr_sectors, i))
if array.get(vgt_sectors, i) > 0
array.push(sector_array, "VGT")
array.push(composition_array, array.get(vgt_sectors, i))
if array.get(vwo_sectors, i) > 0
array.push(sector_array, "VWO")
array.push(composition_array, array.get(vwo_sectors, i))
if array.get(vig_sectors, i) > 0
array.push(sector_array, "VIG")
array.push(composition_array, array.get(vig_sectors, i))
if array.get(vug_sectors, i) > 0
array.push(sector_array, "VUG")
array.push(composition_array, array.get(vug_sectors, i))
if array.get(vtv_sectors, i) > 0
array.push(sector_array, "VTV")
array.push(composition_array, array.get(vtv_sectors, i))
if array.get(vea_sectors, i) > 0
array.push(sector_array, "VEA")
array.push(composition_array, array.get(vea_sectors, i))
if array.get(dia_sectors, i) > 0
array.push(sector_array, "DIA")
array.push(composition_array, array.get(dia_sectors, i))
if array.get(fngg_sectors, i) > 0
array.push(sector_array, "FNGG")
array.push(composition_array, array.get(fngg_sectors, i))
if array.get(fngu_sectors, i) > 0
array.push(sector_array, "FNGU")
array.push(composition_array, array.get(fngu_sectors, i))
if array.get(bnge_sectors, i) > 0
array.push(sector_array, "BNGE")
array.push(composition_array, array.get(bnge_sectors, i))
if array.get(ixp_sectors, i) > 0
array.push(sector_array, "IXP")
array.push(composition_array, array.get(ixp_sectors, i))
if array.get(fcom_sectors, i) > 0
array.push(sector_array, "FCOM")
array.push(composition_array, array.get(fcom_sectors, i))
if array.get(pnqi_sectors, i) > 0
array.push(sector_array, "PNQI")
array.push(composition_array, array.get(pnqi_sectors, i))
if array.get(chps_sectors, i) > 0
array.push(sector_array, "CHPS")
array.push(composition_array, array.get(chps_sectors, i))
if array.get(soxx_sectors, i) > 0
array.push(sector_array, "SOXX")
array.push(composition_array, array.get(soxx_sectors, i))
if array.get(xlk_sectors, i) > 0
array.push(sector_array, "XLK")
array.push(composition_array, array.get(xlk_sectors, i))
if array.get(moon_sectors, i) > 0
array.push(sector_array, "MOON")
array.push(composition_array, array.get(moon_sectors, i))
if array.get(ufo_sectors, i) > 0
array.push(sector_array, "UFO")
array.push(composition_array, array.get(ufo_sectors, i))
if array.get(vdc_sectors, i) > 0
array.push(sector_array, "VDC")
array.push(composition_array, array.get(vdc_sectors, i))
if array.get(iedi_sectors, i) > 0
array.push(sector_array, "IEDI")
array.push(composition_array, array.get(iedi_sectors, i))
if array.get(virs_sectors, i) > 0
array.push(sector_array, "VIRS")
array.push(composition_array, array.get(virs_sectors, i))
if array.get(ftxg_sectors, i) > 0
array.push(sector_array, "FTXG")
array.push(composition_array, array.get(ftxg_sectors, i))
if array.get(jets_sectors, i) > 0
array.push(sector_array, "JETS")
array.push(composition_array, array.get(jets_sectors, i))
if sector == "Healthcare"
i := 5
if array.get(spy_sectors, i) > 0
array.push(sector_array, "SPY")
array.push(composition_array, array.get(spy_sectors, i))
if array.get(qqq_sectors, i) > 0
array.push(sector_array, "QQQ")
array.push(composition_array, array.get(qqq_sectors, i))
if array.get(arkk_sectors, i) > 0
array.push(sector_array, "ARKK")
array.push(composition_array, array.get(arkk_sectors, i))
if array.get(xle_sectors, i) > 0
array.push(sector_array, "XLE")
array.push(composition_array, array.get(xle_sectors, i))
if array.get(brk_sectors, i) > 0
array.push(sector_array, "BRK.B")
array.push(composition_array, array.get(brk_sectors, i))
if array.get(ita_sectors, i) > 0
array.push(sector_array, "ITA")
array.push(composition_array, array.get(ita_sectors, i))
if array.get(iwm_sectors, i) > 0
array.push(sector_array, "IWM")
array.push(composition_array, array.get(iwm_sectors, i))
if array.get(xlf_sectors, i) > 0
array.push(sector_array, "XLF")
array.push(composition_array, array.get(xlf_sectors, i))
if array.get(xlv_sectors, i) > 0
array.push(sector_array, "XLV")
array.push(composition_array, array.get(xlv_sectors, i))
if array.get(vnq_sectors, i) > 0
array.push(sector_array, "VNQ")
array.push(composition_array, array.get(vnq_sectors, i))
if array.get(xbi_sectors, i) > 0
array.push(sector_array, "XBI")
array.push(composition_array, array.get(xbi_sectors, i))
if array.get(blcr_sectors, i) > 0
array.push(sector_array, "BLCR")
array.push(composition_array, array.get(blcr_sectors, i))
if array.get(vgt_sectors, i) > 0
array.push(sector_array, "VGT")
array.push(composition_array, array.get(vgt_sectors, i))
if array.get(vwo_sectors, i) > 0
array.push(sector_array, "VWO")
array.push(composition_array, array.get(vwo_sectors, i))
if array.get(vig_sectors, i) > 0
array.push(sector_array, "VIG")
array.push(composition_array, array.get(vig_sectors, i))
if array.get(vug_sectors, i) > 0
array.push(sector_array, "VUG")
array.push(composition_array, array.get(vug_sectors, i))
if array.get(vtv_sectors, i) > 0
array.push(sector_array, "VTV")
array.push(composition_array, array.get(vtv_sectors, i))
if array.get(vea_sectors, i) > 0
array.push(sector_array, "VEA")
array.push(composition_array, array.get(vea_sectors, i))
if array.get(dia_sectors, i) > 0
array.push(sector_array, "DIA")
array.push(composition_array, array.get(dia_sectors, i))
if array.get(fngg_sectors, i) > 0
array.push(sector_array, "FNGG")
array.push(composition_array, array.get(fngg_sectors, i))
if array.get(fngu_sectors, i) > 0
array.push(sector_array, "FNGU")
array.push(composition_array, array.get(fngu_sectors, i))
if array.get(bnge_sectors, i) > 0
array.push(sector_array, "BNGE")
array.push(composition_array, array.get(bnge_sectors, i))
if array.get(ixp_sectors, i) > 0
array.push(sector_array, "IXP")
array.push(composition_array, array.get(ixp_sectors, i))
if array.get(fcom_sectors, i) > 0
array.push(sector_array, "FCOM")
array.push(composition_array, array.get(fcom_sectors, i))
if array.get(pnqi_sectors, i) > 0
array.push(sector_array, "PNQI")
array.push(composition_array, array.get(pnqi_sectors, i))
if array.get(chps_sectors, i) > 0
array.push(sector_array, "CHPS")
array.push(composition_array, array.get(chps_sectors, i))
if array.get(soxx_sectors, i) > 0
array.push(sector_array, "SOXX")
array.push(composition_array, array.get(soxx_sectors, i))
if array.get(xlk_sectors, i) > 0
array.push(sector_array, "XLK")
array.push(composition_array, array.get(xlk_sectors, i))
if array.get(moon_sectors, i) > 0
array.push(sector_array, "MOON")
array.push(composition_array, array.get(moon_sectors, i))
if array.get(ufo_sectors, i) > 0
array.push(sector_array, "UFO")
array.push(composition_array, array.get(ufo_sectors, i))
if array.get(vdc_sectors, i) > 0
array.push(sector_array, "VDC")
array.push(composition_array, array.get(vdc_sectors, i))
if array.get(iedi_sectors, i) > 0
array.push(sector_array, "IEDI")
array.push(composition_array, array.get(iedi_sectors, i))
if array.get(virs_sectors, i) > 0
array.push(sector_array, "VIRS")
array.push(composition_array, array.get(virs_sectors, i))
if array.get(ftxg_sectors, i) > 0
array.push(sector_array, "FTXG")
array.push(composition_array, array.get(ftxg_sectors, i))
if array.get(jets_sectors, i) > 0
array.push(sector_array, "JETS")
array.push(composition_array, array.get(jets_sectors, i))
if sector == "Utilities"
i := 6
if array.get(spy_sectors, i) > 0
array.push(sector_array, "SPY")
array.push(composition_array, array.get(spy_sectors, i))
if array.get(qqq_sectors, i) > 0
array.push(sector_array, "QQQ")
array.push(composition_array, array.get(qqq_sectors, i))
if array.get(arkk_sectors, i) > 0
array.push(sector_array, "ARKK")
array.push(composition_array, array.get(arkk_sectors, i))
if array.get(xle_sectors, i) > 0
array.push(sector_array, "XLE")
array.push(composition_array, array.get(xle_sectors, i))
if array.get(brk_sectors, i) > 0
array.push(sector_array, "BRK.B")
array.push(composition_array, array.get(brk_sectors, i))
if array.get(ita_sectors, i) > 0
array.push(sector_array, "ITA")
array.push(composition_array, array.get(ita_sectors, i))
if array.get(iwm_sectors, i) > 0
array.push(sector_array, "IWM")
array.push(composition_array, array.get(iwm_sectors, i))
if array.get(xlf_sectors, i) > 0
array.push(sector_array, "XLF")
array.push(composition_array, array.get(xlf_sectors, i))
if array.get(xlv_sectors, i) > 0
array.push(sector_array, "XLV")
array.push(composition_array, array.get(xlv_sectors, i))
if array.get(vnq_sectors, i) > 0
array.push(sector_array, "VNQ")
array.push(composition_array, array.get(vnq_sectors, i))
if array.get(xbi_sectors, i) > 0
array.push(sector_array, "XBI")
array.push(composition_array, array.get(xbi_sectors, i))
if array.get(blcr_sectors, i) > 0
array.push(sector_array, "BLCR")
array.push(composition_array, array.get(blcr_sectors, i))
if array.get(vgt_sectors, i) > 0
array.push(sector_array, "VGT")
array.push(composition_array, array.get(vgt_sectors, i))
if array.get(vwo_sectors, i) > 0
array.push(sector_array, "VWO")
array.push(composition_array, array.get(vwo_sectors, i))
if array.get(vig_sectors, i) > 0
array.push(sector_array, "VIG")
array.push(composition_array, array.get(vig_sectors, i))
if array.get(vug_sectors, i) > 0
array.push(sector_array, "VUG")
array.push(composition_array, array.get(vug_sectors, i))
if array.get(vtv_sectors, i) > 0
array.push(sector_array, "VTV")
array.push(composition_array, array.get(vtv_sectors, i))
if array.get(vea_sectors, i) > 0
array.push(sector_array, "VEA")
array.push(composition_array, array.get(vea_sectors, i))
if array.get(dia_sectors, i) > 0
array.push(sector_array, "DIA")
array.push(composition_array, array.get(dia_sectors, i))
if array.get(fngg_sectors, i) > 0
array.push(sector_array, "FNGG")
array.push(composition_array, array.get(fngg_sectors, i))
if array.get(fngu_sectors, i) > 0
array.push(sector_array, "FNGU")
array.push(composition_array, array.get(fngu_sectors, i))
if array.get(bnge_sectors, i) > 0
array.push(sector_array, "BNGE")
array.push(composition_array, array.get(bnge_sectors, i))
if array.get(ixp_sectors, i) > 0
array.push(sector_array, "IXP")
array.push(composition_array, array.get(ixp_sectors, i))
if array.get(fcom_sectors, i) > 0
array.push(sector_array, "FCOM")
array.push(composition_array, array.get(fcom_sectors, i))
if array.get(pnqi_sectors, i) > 0
array.push(sector_array, "PNQI")
array.push(composition_array, array.get(pnqi_sectors, i))
if array.get(chps_sectors, i) > 0
array.push(sector_array, "CHPS")
array.push(composition_array, array.get(chps_sectors, i))
if array.get(soxx_sectors, i) > 0
array.push(sector_array, "SOXX")
array.push(composition_array, array.get(soxx_sectors, i))
if array.get(xlk_sectors, i) > 0
array.push(sector_array, "XLK")
array.push(composition_array, array.get(xlk_sectors, i))
if array.get(moon_sectors, i) > 0
array.push(sector_array, "MOON")
array.push(composition_array, array.get(moon_sectors, i))
if array.get(ufo_sectors, i) > 0
array.push(sector_array, "UFO")
array.push(composition_array, array.get(ufo_sectors, i))
if array.get(vdc_sectors, i) > 0
array.push(sector_array, "VDC")
array.push(composition_array, array.get(vdc_sectors, i))
if array.get(iedi_sectors, i) > 0
array.push(sector_array, "IEDI")
array.push(composition_array, array.get(iedi_sectors, i))
if array.get(virs_sectors, i) > 0
array.push(sector_array, "VIRS")
array.push(composition_array, array.get(virs_sectors, i))
if array.get(ftxg_sectors, i) > 0
array.push(sector_array, "FTXG")
array.push(composition_array, array.get(ftxg_sectors, i))
if array.get(jets_sectors, i) > 0
array.push(sector_array, "JETS")
array.push(composition_array, array.get(jets_sectors, i))
if sector == "Communication Services"
i := 7
if array.get(spy_sectors, i) > 0
array.push(sector_array, "SPY")
array.push(composition_array, array.get(spy_sectors, i))
if array.get(qqq_sectors, i) > 0
array.push(sector_array, "QQQ")
array.push(composition_array, array.get(qqq_sectors, i))
if array.get(arkk_sectors, i) > 0
array.push(sector_array, "ARKK")
array.push(composition_array, array.get(arkk_sectors, i))
if array.get(xle_sectors, i) > 0
array.push(sector_array, "XLE")
array.push(composition_array, array.get(xle_sectors, i))
if array.get(brk_sectors, i) > 0
array.push(sector_array, "BRK.B")
array.push(composition_array, array.get(brk_sectors, i))
if array.get(ita_sectors, i) > 0
array.push(sector_array, "ITA")
array.push(composition_array, array.get(ita_sectors, i))
if array.get(iwm_sectors, i) > 0
array.push(sector_array, "IWM")
array.push(composition_array, array.get(iwm_sectors, i))
if array.get(xlf_sectors, i) > 0
array.push(sector_array, "XLF")
array.push(composition_array, array.get(xlf_sectors, i))
if array.get(xlv_sectors, i) > 0
array.push(sector_array, "XLV")
array.push(composition_array, array.get(xlv_sectors, i))
if array.get(vnq_sectors, i) > 0
array.push(sector_array, "VNQ")
array.push(composition_array, array.get(vnq_sectors, i))
if array.get(xbi_sectors, i) > 0
array.push(sector_array, "XBI")
array.push(composition_array, array.get(xbi_sectors, i))
if array.get(blcr_sectors, i) > 0
array.push(sector_array, "BLCR")
array.push(composition_array, array.get(blcr_sectors, i))
if array.get(vgt_sectors, i) > 0
array.push(sector_array, "VGT")
array.push(composition_array, array.get(vgt_sectors, i))
if array.get(vwo_sectors, i) > 0
array.push(sector_array, "VWO")
array.push(composition_array, array.get(vwo_sectors, i))
if array.get(vig_sectors, i) > 0
array.push(sector_array, "VIG")
array.push(composition_array, array.get(vig_sectors, i))
if array.get(vug_sectors, i) > 0
array.push(sector_array, "VUG")
array.push(composition_array, array.get(vug_sectors, i))
if array.get(vtv_sectors, i) > 0
array.push(sector_array, "VTV")
array.push(composition_array, array.get(vtv_sectors, i))
if array.get(vea_sectors, i) > 0
array.push(sector_array, "VEA")
array.push(composition_array, array.get(vea_sectors, i))
if array.get(dia_sectors, i) > 0
array.push(sector_array, "DIA")
array.push(composition_array, array.get(dia_sectors, i))
if array.get(fngg_sectors, i) > 0
array.push(sector_array, "FNGG")
array.push(composition_array, array.get(fngg_sectors, i))
if array.get(fngu_sectors, i) > 0
array.push(sector_array, "FNGU")
array.push(composition_array, array.get(fngu_sectors, i))
if array.get(bnge_sectors, i) > 0
array.push(sector_array, "BNGE")
array.push(composition_array, array.get(bnge_sectors, i))
if array.get(ixp_sectors, i) > 0
array.push(sector_array, "IXP")
array.push(composition_array, array.get(ixp_sectors, i))
if array.get(fcom_sectors, i) > 0
array.push(sector_array, "FCOM")
array.push(composition_array, array.get(fcom_sectors, i))
if array.get(pnqi_sectors, i) > 0
array.push(sector_array, "PNQI")
array.push(composition_array, array.get(pnqi_sectors, i))
if array.get(chps_sectors, i) > 0
array.push(sector_array, "CHPS")
array.push(composition_array, array.get(chps_sectors, i))
if array.get(soxx_sectors, i) > 0
array.push(sector_array, "SOXX")
array.push(composition_array, array.get(soxx_sectors, i))
if array.get(xlk_sectors, i) > 0
array.push(sector_array, "XLK")
array.push(composition_array, array.get(xlk_sectors, i))
if array.get(moon_sectors, i) > 0
array.push(sector_array, "MOON")
array.push(composition_array, array.get(moon_sectors, i))
if array.get(ufo_sectors, i) > 0
array.push(sector_array, "UFO")
array.push(composition_array, array.get(ufo_sectors, i))
if array.get(vdc_sectors, i) > 0
array.push(sector_array, "VDC")
array.push(composition_array, array.get(vdc_sectors, i))
if array.get(iedi_sectors, i) > 0
array.push(sector_array, "IEDI")
array.push(composition_array, array.get(iedi_sectors, i))
if array.get(virs_sectors, i) > 0
array.push(sector_array, "VIRS")
array.push(composition_array, array.get(virs_sectors, i))
if array.get(ftxg_sectors, i) > 0
array.push(sector_array, "FTXG")
array.push(composition_array, array.get(ftxg_sectors, i))
if array.get(jets_sectors, i) > 0
array.push(sector_array, "JETS")
array.push(composition_array, array.get(jets_sectors, i))
if sector == "Energy"
i := 8
if array.get(spy_sectors, i) > 0
array.push(sector_array, "SPY")
array.push(composition_array, array.get(spy_sectors, i))
if array.get(qqq_sectors, i) > 0
array.push(sector_array, "QQQ")
array.push(composition_array, array.get(qqq_sectors, i))
if array.get(arkk_sectors, i) > 0
array.push(sector_array, "ARKK")
array.push(composition_array, array.get(arkk_sectors, i))
if array.get(xle_sectors, i) > 0
array.push(sector_array, "XLE")
array.push(composition_array, array.get(xle_sectors, i))
if array.get(brk_sectors, i) > 0
array.push(sector_array, "BRK.B")
array.push(composition_array, array.get(brk_sectors, i))
if array.get(ita_sectors, i) > 0
array.push(sector_array, "ITA")
array.push(composition_array, array.get(ita_sectors, i))
if array.get(iwm_sectors, i) > 0
array.push(sector_array, "IWM")
array.push(composition_array, array.get(iwm_sectors, i))
if array.get(xlf_sectors, i) > 0
array.push(sector_array, "XLF")
array.push(composition_array, array.get(xlf_sectors, i))
if array.get(xlv_sectors, i) > 0
array.push(sector_array, "XLV")
array.push(composition_array, array.get(xlv_sectors, i))
if array.get(vnq_sectors, i) > 0
array.push(sector_array, "VNQ")
array.push(composition_array, array.get(vnq_sectors, i))
if array.get(xbi_sectors, i) > 0
array.push(sector_array, "XBI")
array.push(composition_array, array.get(xbi_sectors, i))
if array.get(blcr_sectors, i) > 0
array.push(sector_array, "BLCR")
array.push(composition_array, array.get(blcr_sectors, i))
if array.get(vgt_sectors, i) > 0
array.push(sector_array, "VGT")
array.push(composition_array, array.get(vgt_sectors, i))
if array.get(vwo_sectors, i) > 0
array.push(sector_array, "VWO")
array.push(composition_array, array.get(vwo_sectors, i))
if array.get(vig_sectors, i) > 0
array.push(sector_array, "VIG")
array.push(composition_array, array.get(vig_sectors, i))
if array.get(vug_sectors, i) > 0
array.push(sector_array, "VUG")
array.push(composition_array, array.get(vug_sectors, i))
if array.get(vtv_sectors, i) > 0
array.push(sector_array, "VTV")
array.push(composition_array, array.get(vtv_sectors, i))
if array.get(vea_sectors, i) > 0
array.push(sector_array, "VEA")
array.push(composition_array, array.get(vea_sectors, i))
if array.get(dia_sectors, i) > 0
array.push(sector_array, "DIA")
array.push(composition_array, array.get(dia_sectors, i))
if array.get(fngg_sectors, i) > 0
array.push(sector_array, "FNGG")
array.push(composition_array, array.get(fngg_sectors, i))
if array.get(fngu_sectors, i) > 0
array.push(sector_array, "FNGU")
array.push(composition_array, array.get(fngu_sectors, i))
if array.get(bnge_sectors, i) > 0
array.push(sector_array, "BNGE")
array.push(composition_array, array.get(bnge_sectors, i))
if array.get(ixp_sectors, i) > 0
array.push(sector_array, "IXP")
array.push(composition_array, array.get(ixp_sectors, i))
if array.get(fcom_sectors, i) > 0
array.push(sector_array, "FCOM")
array.push(composition_array, array.get(fcom_sectors, i))
if array.get(pnqi_sectors, i) > 0
array.push(sector_array, "PNQI")
array.push(composition_array, array.get(pnqi_sectors, i))
if array.get(chps_sectors, i) > 0
array.push(sector_array, "CHPS")
array.push(composition_array, array.get(chps_sectors, i))
if array.get(soxx_sectors, i) > 0
array.push(sector_array, "SOXX")
array.push(composition_array, array.get(soxx_sectors, i))
if array.get(xlk_sectors, i) > 0
array.push(sector_array, "XLK")
array.push(composition_array, array.get(xlk_sectors, i))
if array.get(moon_sectors, i) > 0
array.push(sector_array, "MOON")
array.push(composition_array, array.get(moon_sectors, i))
if array.get(ufo_sectors, i) > 0
array.push(sector_array, "UFO")
array.push(composition_array, array.get(ufo_sectors, i))
if array.get(vdc_sectors, i) > 0
array.push(sector_array, "VDC")
array.push(composition_array, array.get(vdc_sectors, i))
if array.get(iedi_sectors, i) > 0
array.push(sector_array, "IEDI")
array.push(composition_array, array.get(iedi_sectors, i))
if array.get(virs_sectors, i) > 0
array.push(sector_array, "VIRS")
array.push(composition_array, array.get(virs_sectors, i))
if array.get(ftxg_sectors, i) > 0
array.push(sector_array, "FTXG")
array.push(composition_array, array.get(ftxg_sectors, i))
if array.get(jets_sectors, i) > 0
array.push(sector_array, "JETS")
array.push(composition_array, array.get(jets_sectors, i))
if sector == "Industrials"
i := 10
if array.get(spy_sectors, i) > 0
array.push(sector_array, "SPY")
array.push(composition_array, array.get(spy_sectors, i))
if array.get(qqq_sectors, i) > 0
array.push(sector_array, "QQQ")
array.push(composition_array, array.get(qqq_sectors, i))
if array.get(arkk_sectors, i) > 0
array.push(sector_array, "ARKK")
array.push(composition_array, array.get(arkk_sectors, i))
if array.get(xle_sectors, i) > 0
array.push(sector_array, "XLE")
array.push(composition_array, array.get(xle_sectors, i))
if array.get(brk_sectors, i) > 0
array.push(sector_array, "BRK.B")
array.push(composition_array, array.get(brk_sectors, i))
if array.get(ita_sectors, i) > 0
array.push(sector_array, "ITA")
array.push(composition_array, array.get(ita_sectors, i))
if array.get(iwm_sectors, i) > 0
array.push(sector_array, "IWM")
array.push(composition_array, array.get(iwm_sectors, i))
if array.get(xlf_sectors, i) > 0
array.push(sector_array, "XLF")
array.push(composition_array, array.get(xlf_sectors, i))
if array.get(xlv_sectors, i) > 0
array.push(sector_array, "XLV")
array.push(composition_array, array.get(xlv_sectors, i))
if array.get(vnq_sectors, i) > 0
array.push(sector_array, "VNQ")
array.push(composition_array, array.get(vnq_sectors, i))
if array.get(xbi_sectors, i) > 0
array.push(sector_array, "XBI")
array.push(composition_array, array.get(xbi_sectors, i))
if array.get(blcr_sectors, i) > 0
array.push(sector_array, "BLCR")
array.push(composition_array, array.get(blcr_sectors, i))
if array.get(vgt_sectors, i) > 0
array.push(sector_array, "VGT")
array.push(composition_array, array.get(vgt_sectors, i))
if array.get(vwo_sectors, i) > 0
array.push(sector_array, "VWO")
array.push(composition_array, array.get(vwo_sectors, i))
if array.get(vig_sectors, i) > 0
array.push(sector_array, "VIG")
array.push(composition_array, array.get(vig_sectors, i))
if array.get(vug_sectors, i) > 0
array.push(sector_array, "VUG")
array.push(composition_array, array.get(vug_sectors, i))
if array.get(vtv_sectors, i) > 0
array.push(sector_array, "VTV")
array.push(composition_array, array.get(vtv_sectors, i))
if array.get(vea_sectors, i) > 0
array.push(sector_array, "VEA")
array.push(composition_array, array.get(vea_sectors, i))
if array.get(dia_sectors, i) > 0
array.push(sector_array, "DIA")
array.push(composition_array, array.get(dia_sectors, i))
if array.get(fngg_sectors, i) > 0
array.push(sector_array, "FNGG")
array.push(composition_array, array.get(fngg_sectors, i))
if array.get(fngu_sectors, i) > 0
array.push(sector_array, "FNGU")
array.push(composition_array, array.get(fngu_sectors, i))
if array.get(bnge_sectors, i) > 0
array.push(sector_array, "BNGE")
array.push(composition_array, array.get(bnge_sectors, i))
if array.get(ixp_sectors, i) > 0
array.push(sector_array, "IXP")
array.push(composition_array, array.get(ixp_sectors, i))
if array.get(fcom_sectors, i) > 0
array.push(sector_array, "FCOM")
array.push(composition_array, array.get(fcom_sectors, i))
if array.get(pnqi_sectors, i) > 0
array.push(sector_array, "PNQI")
array.push(composition_array, array.get(pnqi_sectors, i))
if array.get(chps_sectors, i) > 0
array.push(sector_array, "CHPS")
array.push(composition_array, array.get(chps_sectors, i))
if array.get(soxx_sectors, i) > 0
array.push(sector_array, "SOXX")
array.push(composition_array, array.get(soxx_sectors, i))
if array.get(xlk_sectors, i) > 0
array.push(sector_array, "XLK")
array.push(composition_array, array.get(xlk_sectors, i))
if array.get(moon_sectors, i) > 0
array.push(sector_array, "MOON")
array.push(composition_array, array.get(moon_sectors, i))
if array.get(ufo_sectors, i) > 0
array.push(sector_array, "UFO")
array.push(composition_array, array.get(ufo_sectors, i))
if array.get(vdc_sectors, i) > 0
array.push(sector_array, "VDC")
array.push(composition_array, array.get(vdc_sectors, i))
if array.get(iedi_sectors, i) > 0
array.push(sector_array, "IEDI")
array.push(composition_array, array.get(iedi_sectors, i))
if array.get(virs_sectors, i) > 0
array.push(sector_array, "VIRS")
array.push(composition_array, array.get(virs_sectors, i))
if array.get(ftxg_sectors, i) > 0
array.push(sector_array, "FTXG")
array.push(composition_array, array.get(ftxg_sectors, i))
if array.get(jets_sectors, i) > 0
array.push(sector_array, "JETS")
array.push(composition_array, array.get(jets_sectors, i))
if sector == "Technology"
i := 10
if array.get(spy_sectors, i) > 0
array.push(sector_array, "SPY")
array.push(composition_array, array.get(spy_sectors, i))
if array.get(qqq_sectors, i) > 0
array.push(sector_array, "QQQ")
array.push(composition_array, array.get(qqq_sectors, i))
if array.get(arkk_sectors, i) > 0
array.push(sector_array, "ARKK")
array.push(composition_array, array.get(arkk_sectors, i))
if array.get(xle_sectors, i) > 0
array.push(sector_array, "XLE")
array.push(composition_array, array.get(xle_sectors, i))
if array.get(brk_sectors, i) > 0
array.push(sector_array, "BRK.B")
array.push(composition_array, array.get(brk_sectors, i))
if array.get(ita_sectors, i) > 0
array.push(sector_array, "ITA")
array.push(composition_array, array.get(ita_sectors, i))
if array.get(iwm_sectors, i) > 0
array.push(sector_array, "IWM")
array.push(composition_array, array.get(iwm_sectors, i))
if array.get(xlf_sectors, i) > 0
array.push(sector_array, "XLF")
array.push(composition_array, array.get(xlf_sectors, i))
if array.get(xlv_sectors, i) > 0
array.push(sector_array, "XLV")
array.push(composition_array, array.get(xlv_sectors, i))
if array.get(vnq_sectors, i) > 0
array.push(sector_array, "VNQ")
array.push(composition_array, array.get(vnq_sectors, i))
if array.get(xbi_sectors, i) > 0
array.push(sector_array, "XBI")
array.push(composition_array, array.get(xbi_sectors, i))
if array.get(blcr_sectors, i) > 0
array.push(sector_array, "BLCR")
array.push(composition_array, array.get(blcr_sectors, i))
if array.get(vgt_sectors, i) > 0
array.push(sector_array, "VGT")
array.push(composition_array, array.get(vgt_sectors, i))
if array.get(vwo_sectors, i) > 0
array.push(sector_array, "VWO")
array.push(composition_array, array.get(vwo_sectors, i))
if array.get(vig_sectors, i) > 0
array.push(sector_array, "VIG")
array.push(composition_array, array.get(vig_sectors, i))
if array.get(vug_sectors, i) > 0
array.push(sector_array, "VUG")
array.push(composition_array, array.get(vug_sectors, i))
if array.get(vtv_sectors, i) > 0
array.push(sector_array, "VTV")
array.push(composition_array, array.get(vtv_sectors, i))
if array.get(vea_sectors, i) > 0
array.push(sector_array, "VEA")
array.push(composition_array, array.get(vea_sectors, i))
if array.get(dia_sectors, i) > 0
array.push(sector_array, "DIA")
array.push(composition_array, array.get(dia_sectors, i))
if array.get(fngg_sectors, i) > 0
array.push(sector_array, "FNGG")
array.push(composition_array, array.get(fngg_sectors, i))
if array.get(fngu_sectors, i) > 0
array.push(sector_array, "FNGU")
array.push(composition_array, array.get(fngu_sectors, i))
if array.get(bnge_sectors, i) > 0
array.push(sector_array, "BNGE")
array.push(composition_array, array.get(bnge_sectors, i))
if array.get(ixp_sectors, i) > 0
array.push(sector_array, "IXP")
array.push(composition_array, array.get(ixp_sectors, i))
if array.get(fcom_sectors, i) > 0
array.push(sector_array, "FCOM")
array.push(composition_array, array.get(fcom_sectors, i))
if array.get(pnqi_sectors, i) > 0
array.push(sector_array, "PNQI")
array.push(composition_array, array.get(pnqi_sectors, i))
if array.get(chps_sectors, i) > 0
array.push(sector_array, "CHPS")
array.push(composition_array, array.get(chps_sectors, i))
if array.get(soxx_sectors, i) > 0
array.push(sector_array, "SOXX")
array.push(composition_array, array.get(soxx_sectors, i))
if array.get(xlk_sectors, i) > 0
array.push(sector_array, "XLK")
array.push(composition_array, array.get(xlk_sectors, i))
if array.get(moon_sectors, i) > 0
array.push(sector_array, "MOON")
array.push(composition_array, array.get(moon_sectors, i))
if array.get(ufo_sectors, i) > 0
array.push(sector_array, "UFO")
array.push(composition_array, array.get(ufo_sectors, i))
if array.get(vdc_sectors, i) > 0
array.push(sector_array, "VDC")
array.push(composition_array, array.get(vdc_sectors, i))
if array.get(iedi_sectors, i) > 0
array.push(sector_array, "IEDI")
array.push(composition_array, array.get(iedi_sectors, i))
if array.get(virs_sectors, i) > 0
array.push(sector_array, "VIRS")
array.push(composition_array, array.get(virs_sectors, i))
if array.get(ftxg_sectors, i) > 0
array.push(sector_array, "FTXG")
array.push(composition_array, array.get(ftxg_sectors, i))
if array.get(jets_sectors, i) > 0
array.push(sector_array, "JETS")
array.push(composition_array, array.get(jets_sectors, i))
[sector_array, composition_array]
// Use as Standalone
search_for_ticker = input.bool(true, "Search for Current Ticker in ETFs")
current = syminfo.ticker
if search_for_ticker
[sector, compo] = etf_search_ticker(current)
var table results = table.new(position.middle_center, 3, 50, bgcolor = color.black, frame_color = color.white, frame_width = 2)
if array.size(sector) > 0
table.cell(results, 1, 1, text = "ETF", bgcolor = color.black, text_color = color.white)
table.cell(results, 2, 1, text = "Composition", bgcolor = color.black, text_color = color.white)
for i = 0 to array.size(sector) - 1
table.cell(results, 1, 2 + i, text = str.tostring(array.get(sector, i)), bgcolor = color.black, text_color = color.white)
table.cell(results, 2, 2 + i, text = str.tostring(array.get(compo, i)), bgcolor = color.black, text_color = color.white)
|
Polyline Plus | https://www.tradingview.com/script/whitXdWw-Polyline-Plus/ | algotraderdev | https://www.tradingview.com/u/algotraderdev/ | 8 | library | 5 | MPL-2.0 | // @license This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @author algotraderdev
// @description This library introduces the `PolylinePlus` type, which is an enhanced version of the built-in PineScript
// `polyline`. It enable two features that are absent from the built-in type:
// 1. Developers can now dynamically add or remove points from the poyline in an efficient manner. In contrast, the
// built-in `polyline` type is immutable, and developers are forced to reconstruct a new instance of the polyline
// if they were to add/remove points, which is unwieldy and comes with significant performance penalty.
// 2. Each PolylinePlus instance can theoretically hold up to ~1M points, instead of the 10K points allowed by the
// built-in `polyline` type, as long as it does not exceed the memory limit of the PineScript runtime.
// Under the hood, it stores an array of `line`s and use it as a buffer to hold the lines that are formed by the newly
// added points. When this buffer is full, it then flushes the buffer and converts the lines into polylines,
// which are expected to be updated much less frequently.
// This concept is similar to how "Buffered I/O" works in file and network systems.
// @version=5
library('polylineplus', overlay = true)
//#region Utilities
// @function Asserts the condition is met. Throws an exception if not.
// @param cond The condition to check.
// @param msg The message to display in the exception.
assert(bool cond, string msg) =>
if not cond
runtime.error(msg)
//#endregion
//#region PolylineWithPoints
// @type A helper type that serves as the union of a built-in `polyline` object and the `chart.point`s that back
// up the polyline. This object is needed because the built-in `polyline` type does not expose its underlying points
// to developers.
export type PolylineWithPoints
// Determines the field of the chart.point objects in the points array that the polyline will use for its
// x-coordinates. If xloc.bar_index, the polyline will use the index field from each point. If xloc.bar_time,
// it will use the time field.
string xloc = xloc.bar_index
// The color of the line segments.
color line_color = color.blue
// The style of the polyline. Possible values: line.style_solid, line.style_dotted, line.style_dashed,
// line.style_arrow_left, line.style_arrow_right, line.style_arrow_both.
string line_style = line.style_solid
// The width of the line segments, expressed in pixels.
int line_width = 1
// The maximum number of points that each built-in `polyline` instance can contain.
// NOTE: this is not to be confused with the maximum number of points that each `PolylinePlus` instance can contain.
// In fact, each `PolylinePlus` instance can theoretically hold up to 10,000 * 100 + 500 = 1,000,500 points as long
// as it does not exceed the memory limit of the PineScript runtime.
int max_points_per_builtin_polyline = 10000
// The underlying polyline.
polyline polyline
// The underlying points that form the polyline.
chart.point[] points
// @function Gets the size of points in this polyline.
method points_size(PolylineWithPoints this) =>
if na(this.points)
0
else
this.points.size()
// @function Gets the last point from this polyline.
method last_point(PolylineWithPoints this) =>
if not na(this.points)
if this.points.size() > 0
this.points.last()
// @function Sets the points for the polyline.
// @param points The new points to set.
method set_points(PolylineWithPoints this, chart.point[] points) =>
this.points := points.copy()
if not na(this.polyline)
this.polyline.delete()
this.polyline := polyline.new(
this.points,
xloc = this.xloc,
line_color = this.line_color,
line_style = this.line_style,
line_width = this.line_width)
// @function Checks if this instance has reached the maximum capacity for points.
// @returns Whether this instance has reached the maximum capacity for points.
method is_full(PolylineWithPoints this) =>
if na(this.points)
false
else
this.points.size() == this.max_points_per_builtin_polyline
// @function Pushes more points into the polyline. If it exceeds the max number of points that each polyline can store,
// then the remaining un-stored portion will be returned.
// @param new_points An array of points to add into the polyline.
// @returns The remaining points that are not added into the polyline, or na if all points were added.
method push_points(PolylineWithPoints this, chart.point[] new_points) =>
// Make sure `this.points` is initialized.
if na(this.points)
this.points := array.new<chart.point>()
int size = this.points.size()
int new_size = size + new_points.size()
if new_size > this.max_points_per_builtin_polyline
// Calculate the remaining capacity of `this.points`.
int capacity = this.max_points_per_builtin_polyline - size
// Split the `new_points` array into two parts, with the first part being the points that can be added into the
// polyline and the second part being the remaining points that cannot be added.
chart.point[] to_add = new_points.slice(0, capacity)
chart.point[] remaining = new_points.slice(capacity, new_points.size())
// Update `this.points` and `this.polyline`.
this.set_points(this.points.concat(to_add))
remaining
else // all points can be added into `this.points`.
this.set_points(this.points.concat(new_points))
na
// @function Pops N points from the polyline.
// @param n The number of points to pop.
// @returns An array of `chart.point`s that are popped.
method pop_points(PolylineWithPoints this, int n) =>
assert(not na(this.points), '`this.points` should not be na in `PolylineWithPoints#pop_points`.')
int size = this.points.size()
assert(n <= size, 'The number of points to pop should be less than or equal to the size of `this.points`.')
chart.point[] left = if size == n
// NOTE: ideally we should be able to do `this.points.slice(0, size - n)` regardless of whether size == n,
// but there's seems to be bug that in PineScript that if the second param provided to slice is 0, then
// the full array will be returned. e.g. [1, 2, 3].slice(0, 0) is [1, 2, 3] rather than [].
array.new<chart.point>()
else
this.points.slice(0, size - n)
chart.point[] right = this.points.slice(size - n, size)
this.set_points(left)
right
// @function Deletes the chart elements from this object and frees up memory.
method delete(PolylineWithPoints this) =>
if not na(this.polyline)
this.polyline.delete()
this.polyline := na
this.points := na
//#endregion
//#region PolylinePlus
// @type A PolylinePlus type is an enhanced version of the built-in PineScript `polyline` type to enable developers to
// dynamically add or remove points from the poyline with significantly optimized performance.
// Under the hood, it stores an array of `line`s and use it as a buffer to hold the lines that are formed by the newly
// added points. When this buffer is full, it then flushes the buffer and converts the lines into polylines,
// which are expected to be updated much less frequently.
// This concept is similar to how file system buffers and network buffers work.
export type PolylinePlus
// If true, the drawing will also connect the first point to the last point from the points array, resulting in a
// closed polyline.
bool closed = false
// Determines the field of the chart.point objects in the points array that the polyline will use for its
// x-coordinates. If xloc.bar_index, the polyline will use the index field from each point. If xloc.bar_time,
// it will use the time field.
string xloc = xloc.bar_index
// The color of the line segments.
color line_color = color.blue
// The style of the polyline. Possible values: line.style_solid, line.style_dotted, line.style_dashed,
// line.style_arrow_left, line.style_arrow_right, line.style_arrow_both.
string line_style = line.style_solid
// The width of the line segments, expressed in pixels.
int line_width = 1
// The maximum number of points that each built-in `polyline` instance can contain.
// NOTE: this is not to be confused with the maximum number of points that each `PolylinePlus` instance can contain.
// In fact, each `PolylinePlus` instance can theoretically hold up to 10,000 * 100 + 500 = 1,000,500 points as long as
// it does not exceed the memory limit of the PineScript runtime.
int max_points_per_builtin_polyline = 10000
// The number of lines to keep in the buffer. If more points are to be added while the buffer is full, then all the
// lines in the buffer will be flushed into the poylines. The higher the number, the less frequent we'll need to
// flush the buffer, and thus lead to better performance.
// NOTE: the maximum total number of lines per chart allowed by PineScript is 500. But given there might be other
// places where the indicator or strategy are drawing lines outside this poyline context, we use a conservative
// number here to be safe.
// NOTE: When specifying a higher number here, please also make sure to use a higher number for the
// `max_lines_count` param for the indicator. Otherwise the lines beyond the `max_lines_count` may be automatically
// deleted and thus lead to missing points in the polyline.
int lines_buffer_size = 50
// [Private] The first point that's added to the polyline.
chart.point first_point
// [Private] The lines buffer. This buffer holds the most recently added lines until the buffer is full.
line[] lines
// [Private] The underlying polylines that represent the old-generation lines.
PolylineWithPoints[] polylines_with_points
// [Private] The line that connects the first point to the last point, if the `closed` property is set to true.
// NOTE: using `polyline` instead of `line` here since the polylines can be displayed on the chart even if their
// starting points are outside of the viewport.
polyline close_line
// @function Gets the internal lines property while making sure it's properly initialized.
method lines(PolylinePlus this) =>
if na(this.lines)
this.lines := array.new_line()
this.lines
// @function Gets the internal polylines property while making sure it's properly initialized.
method polylines_with_points(PolylinePlus this) =>
if na(this.polylines_with_points)
this.polylines_with_points := array.new<PolylineWithPoints>()
this.polylines_with_points
// @function Creates a new instance of `PolylineWithPoints`.
// @returns The newly created instance.
method new_polyline_with_points(PolylinePlus this) =>
PolylineWithPoints pwp = PolylineWithPoints.new(
xloc = this.xloc,
line_color = this.line_color,
line_style = this.line_style,
line_width = this.line_width,
max_points_per_builtin_polyline = this.max_points_per_builtin_polyline)
PolylineWithPoints[] pwps = this.polylines_with_points()
if pwps.size() > 0
pwp.push_points(array.from(pwps.last().last_point()))
pwps.push(pwp)
pwp
// @function Gets the start and end endpoints for the given line.
// @param ln The line instance.
// @returns A two-element tuple that contains the start and end endpoints (both of the `chart.point` type).
method line_endpoints(PolylinePlus this, line ln) =>
if this.xloc == xloc.bar_index
[chart.point.from_index(ln.get_x1(), ln.get_y1()), chart.point.from_index(ln.get_x2(), ln.get_y2())]
else
[chart.point.from_time(ln.get_x1(), ln.get_y1()), chart.point.from_time(ln.get_x2(), ln.get_y2())]
// @function Gets the last point in the polyline.
// @returns The last point in the polyline, or na if the polyline is empty.
method last_point(PolylinePlus this) =>
line[] lines = this.lines()
chart.point p = if lines.size() > 0
[start, end] = this.line_endpoints(lines.last())
end
else
PolylineWithPoints[] pwps = this.polylines_with_points()
if pwps.size() > 0
pwps.last().last_point()
na(p) ? this.first_point : p
// @function Updates the close line.
method update_close_line(PolylinePlus this) =>
if this.closed and not na(this.first_point) and not na(this.last_point())
if not na(this.close_line)
this.close_line.delete()
this.close_line := polyline.new(
array.from(this.first_point, this.last_point()),
xloc = this.xloc,
line_color = this.line_color,
line_style = this.line_style,
line_width = this.line_width)
else
if not na(this.close_line)
this.close_line.delete()
this.close_line := na
this
// @function Flushes the lines buffer if it's full.
method flush_if_full(PolylinePlus this) =>
line[] lines = this.lines()
if lines.size() == this.lines_buffer_size
PolylineWithPoints[] pwps = this.polylines_with_points()
if pwps.size() == 0
this.new_polyline_with_points()
PolylineWithPoints pwp = this.polylines_with_points.last()
chart.point[] points = array.new<chart.point>()
for [i, ln] in lines
[start, end] = this.line_endpoints(ln)
// Add the start point of the first line into the points array if the pwp is currently empty.
if i == 0 and pwp.points_size() == 0
points.push(start)
points.push(end)
ln.delete()
lines.clear()
// Gets the last polyline from the list and try to add the points into it.
// If the polyline is full, then create a new polyline.
while not na(points)
pwp := this.polylines_with_points.last()
if pwp.is_full()
pwp := this.new_polyline_with_points()
chart.point[] remaining = pwp.push_points(points)
points := remaining
// @function Pushes a new point into this polyline.
// @param point A chart.point object that specifies the coordinate.
export method push_point(PolylinePlus this, chart.point point) =>
if na(this.first_point)
this.first_point := point
else
this.flush_if_full()
line ln = line.new(
first_point = this.last_point(),
second_point = point,
xloc = this.xloc,
color = this.line_color,
style = this.line_style,
width = this.line_width)
this.lines().push(ln)
this.update_close_line()
// @function Pushes a list of new point into this polyline.
// @param points A list of new points to push.
export method push_points(PolylinePlus this, chart.point[] points) =>
for p in points
this.push_point(p)
// @function Formats the chart.point type.
// @returns A string representing the chart.point.
method format_point(PolylinePlus this, chart.point point) =>
string x = if this.xloc == xloc.bar_index
str.tostring(point.index)
else
str.format_time(point.time)
str.format('({0}, {1})', x, point.price)
// @function Pops the last point from the polyline.
export method pop_point(PolylinePlus this) =>
line[] lines = this.lines()
if lines.size() > 0
line ln = lines.pop()
ln.delete()
else // lines.size() == 0
PolylineWithPoints[] pwps = this.polylines_with_points()
if pwps.size() > 0
PolylineWithPoints pwp = pwps.last()
if pwp.points_size() > 2
// If there are more than two points in the pwp, then move some points from the pwp into the lines
// buffer.
int num_points_to_pop = math.min(this.lines_buffer_size + 1, pwp.points_size() - 1)
chart.point[] points = pwp.pop_points(num_points_to_pop)
points.pop()
// Deletes and pop the pwp if it only has one point remaining.
if pwp.points_size() == 1
this.polylines_with_points.pop().delete()
if this.polylines_with_points.size() == 0
this.first_point := na
this.push_points(points)
else // pwp.points_size() <= 2
this.polylines_with_points.pop().delete()
this.update_close_line()
// @function Deletes the chart elements from this object and frees up memory.
export method delete(PolylinePlus this) =>
line[] lines = this.lines()
for ln in lines
ln.delete()
lines.clear()
this.lines := na
if not na(this.close_line)
this.close_line.delete()
this.close_line := na
PolylineWithPoints[] pwps = this.polylines_with_points()
for pwp in pwps
pwp.delete()
pwps.clear()
this.polylines_with_points := na
this.first_point := na
// @function Sets the point in the polyline.
// @param points The points to set.
export method set_points(PolylinePlus this, chart.point[] points) =>
this.delete()
this.push_points(points)
// @function Generates the debug string for a `PolylineWithPoints` instance.
// @returns A string representing the debug information.
method pwp_debug_str(PolylinePlus this, PolylineWithPoints pwp) =>
string[] rows = array.new_string()
if not na(pwp.points)
for p in pwp.points
rows.push(this.format_point(p))
rows.join('\n')
// @function Generates the debug string for this instance.
// @returns A string representing the debug information.
method debug_str(PolylinePlus this) =>
string[] rows = array.new_string()
rows.push(str.format('lines={0} polylines={1}', this.lines().size(), this.polylines_with_points().size()))
for [i, pwp] in this.polylines_with_points
rows.push(str.format('------- Polyline {0} -------', i))
rows.push(this.pwp_debug_str(pwp))
rows.push('---------- Lines ----------')
for ln in this.lines
[start, end] = this.line_endpoints(ln)
rows.push(str.format('{0} -> {1}', this.format_point(start), this.format_point(end)))
rows.join('\n')
//#endregion |
Fear & Greed Index (Zeiierman) | https://www.tradingview.com/script/qC7RI6cj-Fear-Greed-Index-Zeiierman/ | Zeiierman | https://www.tradingview.com/u/Zeiierman/ | 462 | study | 5 | CC-BY-NC-SA-4.0 | // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © Zeiierman {
//@version=5
indicator("Fear & Greed Index (Zeiierman)",max_bars_back = 500,max_lines_count = 500,precision = 1)
//~~}
// ~~ Vars {
b = bar_index
xy = array.new<chart.point>()
var poly = array.new<polyline>(20,na)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Funcs {
Scales(input) => ((input - ta.min(input)) / (ta.max(input) - ta.min(input))) * 100
Scale(input) => ((input - ta.lowest(input,100)) / (ta.highest(input,100) - ta.lowest(input,100))) * 100
createZone(color _zoneColor, float _startAngle, float _endAngle) =>
int leftIndex = math.round((_startAngle + 90.0) / 0.01)
int rightIndex = math.round((_endAngle + 90.0) / 0.01)
zone = xy.slice(leftIndex, rightIndex)
zone.push(chart.point.from_index(b, 0))
poly.pop().delete()
poly.unshift(polyline.new(zone, false, true, line_color=color.new(_zoneColor, 80), fill_color=color.new(_zoneColor, 50)))
zone
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Visual {
// Create zones
if barstate.islast
int x1 = na
float y1 = na
for i = -90.0 to 90 by 0.01
x2 = b + math.round(100 * math.sin(math.toradians(i)))
y2 = 100 * math.cos(math.toradians(i))
xy.push(chart.point.from_index(x1, y1))
xy.push(chart.point.from_index(x2, y2))
x1 := x2
y1 := y2
// Color
colors = array.from(
color.rgb(255, 0, 0),
color.rgb(233, 16, 16),
color.rgb(201, 34, 34),
color.rgb(197, 51, 51),
color.rgb(197, 69, 69),
color.rgb(199, 89, 89),
color.rgb(227, 113, 113),
color.rgb(232, 134, 134),
color.rgb(232, 157, 134),
color.rgb(255, 185, 80),
color.rgb(255, 185, 80),
color.rgb(144, 243, 177),
color.rgb(144, 243, 177),
color.rgb(117, 225, 153),
color.rgb(97, 193, 129),
color.rgb(79, 189, 116),
color.rgb(49, 169, 89),
color.rgb(38, 193, 89),
color.rgb(21, 224, 88),
color.rgb(0, 255, 85))
// Loop through zones
int zoneCount = 20
float zoneWidth = 360 / zoneCount
for i = 0 to zoneCount-1
startAngle = -90.0 + (i * zoneWidth)
endAngle = startAngle + zoneWidth
createZone(colors.get(i), startAngle, endAngle)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Fear & Greed {
//S&P 500 125-day moving average
[spxPrice, spxAverage] = request.security("SPX", "D", [close, ta.sma(close, 125)])
sp125 = Scales(spxPrice - spxAverage)
//STOCK PRICE STRENGTH - 52 week high vs 52 week low
week52 = request.security("NYSE:NYA","W",close-math.avg(ta.highest(high,52),ta.lowest(low,52)))/100
hl52 = Scales(week52)
//STOCK PRICE BREADTH - McClellan
adv = ta.sma(request.security("ADVN", "D", close),19)
dec = ta.sma(request.security("DECN", "D", close),19)
mcsi = Scales(ta.sma(adv-dec, 19))
//PUT AND CALL OPTIONS - Put and Call 5-day average
putCallRatio = ta.sma(request.security("USI:PCC", "D", close), 5)
putcall = Scale(-putCallRatio)
//MARKET VOLATILITY - VIX vs 50day average
vix = request.security("CBOE:VIX", "D", close)
vixMA = ta.sma(vix, 50)
vix50 = Scale(-(vix-vixMA))
//SAFE HAVEN DEMAND - SPX vs Bonds
stockReturns = ta.sma(spxPrice - spxPrice[20], 20)
[bond,bond20] = request.security("US10Y", "D", [close,close[20]])
safe = Scales(stockReturns-(bond-bond20))
// JUNK BOND DEMAND - Yield spread: junk bonds vs. investment grade
junkBondYield = request.security("AMEX:JNK", "D", close)
treasuryYield = request.security("US10Y", "D", close)
yieldSpread = Scale(junkBondYield - treasuryYield)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Arrow {
combined = math.avg(sp125,hl52,vix50,mcsi,putcall,safe,yieldSpread)
new = combined>50?200-(combined*2):combined*2
loc = combined>50?b+math.round((combined*2)-100):b-math.round(100-(combined*2))
l1 = line.new(b,0,loc,new,color=chart.fg_color,width=3,style=line.style_arrow_right)
lab1 = label.new(b,0,"",style=label.style_circle,color=chart.fg_color,size=size.small)
lab2 = label.new(loc,new,str.tostring(math.round(combined)),style=loc>b?label.style_label_left:label.style_label_right,color=color(na),textcolor=chart.fg_color,size=size.normal)
(l1[1]).delete()
(lab1[1]).delete()
(lab2[1]).delete()
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Labels {
EF = label.new(b-100,0,"Extreme Fear",color=color(na),textcolor=color.red,style=label.style_label_right)
EG = label.new(b+100,0,"Extreme Greed",color=color(na),textcolor=color.green,style=label.style_label_left)
F = label.new(b-65,85,"Fear",color=color(na),textcolor=color.red,style=label.style_label_right)
G = label.new(b+65,85,"Greed",color=color(na),textcolor=color.green,style=label.style_label_left)
N = label.new(b,100,"Neutral",color=color(na),textcolor=chart.fg_color)
(EF[1]).delete()
(EG[1]).delete()
(F[1]).delete()
(G[1]).delete()
(N[1]).delete()
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} |
PineUnit | https://www.tradingview.com/script/HIQiZXdL/ | Guardian667 | https://www.tradingview.com/u/Guardian667/ | 5 | library | 5 | MPL-2.0 | "// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.or(...TRUNCATED) |
End of preview. Expand
in Dataset Viewer.
- Downloads last month
- 59