Stock % Chg. From OPEN (instead of prev. day close) (22 Tickers)

mattb348 · study · 102 行 · 点赞 4 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
 
// CREATED BY:  mattb348
 
indicator('% Change From Open', shorttitle = '%Chg. From Open', overlay = true)
 
u01 = input.bool(true, title = '', group = 'Symbols', inline = 's01')
u02 = input.bool(true, title = '', group = 'Symbols', inline = 's02')
u03 = input.bool(true, title = '', group = 'Symbols', inline = 's03')
u04 = input.bool(true, title = '', group = 'Symbols', inline = 's04')
u05 = input.bool(true, title = '', group = 'Symbols', inline = 's05')
u06 = input.bool(true, title = '', group = 'Symbols', inline = 's06')
u07 = input.bool(true, title = '', group = 'Symbols', inline = 's07')
u08 = input.bool(true, title = '', group = 'Symbols', inline = 's08')
u09 = input.bool(true, title = '', group = 'Symbols', inline = 's09')
u10 = input.bool(true, title = '', group = 'Symbols', inline = 's10')
u11 = input.bool(true, title = '', group = 'Symbols', inline = 's11')
u12 = input.bool(true, title = '', group = 'Symbols', inline = 's12')
u13 = input.bool(true, title = '', group = 'Symbols', inline = 's13')
u14 = input.bool(true, title = '', group = 'Symbols', inline = 's14')
u15 = input.bool(true, title = '', group = 'Symbols', inline = 's15')
u16 = input.bool(true, title = '', group = 'Symbols', inline = 's16')
u17 = input.bool(true, title = '', group = 'Symbols', inline = 's17')
u18 = input.bool(true, title = '', group = 'Symbols', inline = 's18')
 
s1 = u01 ? input(defval = 'AMD', title = 'Stock 1', group = 'Symbols', inline = 's01', display = display.none) : na
s2 = u02 ? input(defval = 'PLTR', title = 'Stock 2', group = 'Symbols', inline = 's02', display = display.none) : na
s3 = u03 ? input(defval = 'CRWD', title = 'Stock 3', group = 'Symbols', inline = 's03', display = display.none) : na
s4 = u04 ? input(defval = 'TSLA', title = 'Stock 4', group = 'Symbols', inline = 's04', display = display.none) : na
s5 = u05 ? input(defval = 'META', title = 'Stock 5', group = 'Symbols', inline = 's05', display = display.none) : na
s6 = u06 ? input(defval = 'NVDA', title = 'Stock 6', group = 'Symbols', inline = 's06', display = display.none) : na
s7 = u07 ? input(defval = 'NFLX', title = 'Stock 7', group = 'Symbols', inline = 's07', display = display.none) : na
s8 = u08 ? input(defval = 'AMZN', title = 'Stock 8', group = 'Symbols', inline = 's08', display = display.none) : na
s9 = u09 ? input(defval = 'GOOGL', title = 'Stock 9', group = 'Symbols', inline = 's09', display = display.none) : na
s10 = u10 ? input(defval = 'MSFT', title = 'Stock 10', group = 'Symbols', inline = 's10', display = display.none) : na
s11 = u11 ? input(defval = 'AAPL', title = 'Stock 11', group = 'Symbols', inline = 's11', display = display.none) : na
s12 = u12 ? input(defval = 'AVGO', title = 'Stock 12', group = 'Symbols', inline = 's12', display = display.none) : na
s13 = u13 ? input(defval = 'INTC', title = 'Stock 13', group = 'Symbols', inline = 's13', display = display.none) : na
s14 = u14 ? input(defval = 'MU', title = 'Stock 14', group = 'Symbols', inline = 's14', display = display.none) : na
s15 = u15 ? input(defval = 'ORCL', title = 'Stock 15', group = 'Symbols', inline = 's15', display = display.none) : na
s16 = u16 ? input(defval = 'PANW', title = 'Stock 16', group = 'Symbols', inline = 's16', display = display.none) : na
s17 = u17 ? input(defval = 'WMT', title = 'Stock 17', group = 'Symbols', inline = 's17', display = display.none) : na
s18 = u18 ? input(defval = 'SPY', title = 'Stock 18', group = 'Symbols', inline = 's18', display = display.none) : na
 
show_open_change = true
 
row_color = input(defval = color.rgb(0, 0, 0), title = 'Row Color')
 
table_placement = input.string(defval = 'bottom_right', title = 'Table Placement', options = ['top_right', 'top_left', 'bottom_right', 'bottom_left', 'top_center', 'bottom_center'], display = display.none)
 
calc_pct_change(stock, reference_price) =>
    ref_price = na(stock) ? na : request.security(stock, 'D', reference_price)
    c = na(stock) ? na : request.security(stock, 'D', close)
    pct_change = na(ref_price) or na(c) ? na : (c - ref_price) / ref_price * 100
    pct_change
 
var table tbl = table.new(table_placement, 22, 2, bgcolor = color.gray)
 
// Function to set the color of the text based on its value
 
text_color(value) =>
    value < 0 ? color.red : color.green
 
if barstate.islast
    table.cell(tbl, 1, 0, s1, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 2, 0, s2, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 3, 0, s3, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 4, 0, s4, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 5, 0, s5, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 6, 0, s6, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 7, 0, s7, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 8, 0, s8, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 9, 0, s9, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 10, 0, s10, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 11, 0, s11, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 12, 0, s12, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 13, 0, s13, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 14, 0, s14, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 15, 0, s15, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 16, 0, s16, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 17, 0, s17, text_color = color.white, bgcolor = row_color)
    table.cell(tbl, 18, 0, s18, text_color = color.white, bgcolor = row_color)
 
    if show_open_change
        table.cell(tbl, 1, 1, na(calc_pct_change(s1, open)) ? na : str.tostring(calc_pct_change(s1, open), '#.00') + '%', text_color = text_color(calc_pct_change(s1, open)), bgcolor = row_color)
        table.cell(tbl, 2, 1, na(calc_pct_change(s2, open)) ? na : str.tostring(calc_pct_change(s2, open), '#.00') + '%', text_color = text_color(calc_pct_change(s2, open)), bgcolor = row_color)
        table.cell(tbl, 3, 1, na(calc_pct_change(s3, open)) ? na : str.tostring(calc_pct_change(s3, open), '#.00') + '%', text_color = text_color(calc_pct_change(s3, open)), bgcolor = row_color)
        table.cell(tbl, 4, 1, na(calc_pct_change(s4, open)) ? na : str.tostring(calc_pct_change(s4, open), '#.00') + '%', text_color = text_color(calc_pct_change(s4, open)), bgcolor = row_color)
        table.cell(tbl, 5, 1, na(calc_pct_change(s5, open)) ? na : str.tostring(calc_pct_change(s5, open), '#.00') + '%', text_color = text_color(calc_pct_change(s5, open)), bgcolor = row_color)
        table.cell(tbl, 6, 1, na(calc_pct_change(s6, open)) ? na : str.tostring(calc_pct_change(s6, open), '#.00') + '%', text_color = text_color(calc_pct_change(s6, open)), bgcolor = row_color)
        table.cell(tbl, 7, 1, na(calc_pct_change(s7, open)) ? na : str.tostring(calc_pct_change(s7, open), '#.00') + '%', text_color = text_color(calc_pct_change(s7, open)), bgcolor = row_color)
        table.cell(tbl, 8, 1, na(calc_pct_change(s8, open)) ? na : str.tostring(calc_pct_change(s8, open), '#.00') + '%', text_color = text_color(calc_pct_change(s8, open)), bgcolor = row_color)
        table.cell(tbl, 9, 1, na(calc_pct_change(s9, open)) ? na : str.tostring(calc_pct_change(s9, open), '#.00') + '%', text_color = text_color(calc_pct_change(s9, open)), bgcolor = row_color)
        table.cell(tbl, 10, 1, na(calc_pct_change(s10, open)) ? na : str.tostring(calc_pct_change(s10, open), '#.00') + '%', text_color = text_color(calc_pct_change(s10, open)), bgcolor = row_color)
        table.cell(tbl, 11, 1, na(calc_pct_change(s11, open)) ? na : str.tostring(calc_pct_change(s11, open), '#.00') + '%', text_color = text_color(calc_pct_change(s11, open)), bgcolor = row_color)
        table.cell(tbl, 12, 1, na(calc_pct_change(s12, open)) ? na : str.tostring(calc_pct_change(s12, open), '#.00') + '%', text_color = text_color(calc_pct_change(s12, open)), bgcolor = row_color)
        table.cell(tbl, 13, 1, na(calc_pct_change(s13, open)) ? na : str.tostring(calc_pct_change(s13, open), '#.00') + '%', text_color = text_color(calc_pct_change(s13, open)), bgcolor = row_color)
        table.cell(tbl, 14, 1, na(calc_pct_change(s14, open)) ? na : str.tostring(calc_pct_change(s14, open), '#.00') + '%', text_color = text_color(calc_pct_change(s14, open)), bgcolor = row_color)
        table.cell(tbl, 15, 1, na(calc_pct_change(s15, open)) ? na : str.tostring(calc_pct_change(s15, open), '#.00') + '%', text_color = text_color(calc_pct_change(s15, open)), bgcolor = row_color)
        table.cell(tbl, 16, 1, na(calc_pct_change(s16, open)) ? na : str.tostring(calc_pct_change(s16, open), '#.00') + '%', text_color = text_color(calc_pct_change(s16, open)), bgcolor = row_color)
        table.cell(tbl, 17, 1, na(calc_pct_change(s17, open)) ? na : str.tostring(calc_pct_change(s17, open), '#.00') + '%', text_color = text_color(calc_pct_change(s17, open)), bgcolor = row_color)
        table.cell(tbl, 18, 1, na(calc_pct_change(s18, open)) ? na : str.tostring(calc_pct_change(s18, open), '#.00') + '%', text_color = text_color(calc_pct_change(s18, open)), bgcolor = row_color)

← 返回列表