Weekly currency strength - M.S.

M12314S · study · 175 行 · 点赞 6 · TradingView 原页

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

Pine Script

//@version=6
indicator("Weekly currency strength - M.S.", overlay=true, dynamic_requests=true)
 
// ─────────────────────────────────────────────
// SETTINGS
// ─────────────────────────────────────────────
 
positionInput = input.string("Top Right", "Table Position", options=["Top Right", "Top Left", "Bottom Right", "Bottom Left"])
sizeInput = input.string("Normal", "Text Size", options=["Small", "Normal", "Large"])
 
tablePosition = switch positionInput
    "Top Left" => position.top_left
    "Bottom Right" => position.bottom_right
    "Bottom Left" => position.bottom_left
    => position.top_right
 
textSize = switch sizeInput
    "Small" => size.small
    "Large" => size.large
    => size.normal
 
// ─────────────────────────────────────────────
// COLORS
// ─────────────────────────────────────────────
 
dark = #080E18
rowA = #0D1929
rowB = #101E30
headerBg = #11263D
blue = #48AFFF
white = #F2F6FC
muted = #91A7BF
green = #28DA8A
red = #FF5266
strongBg = #102C27
weakBg = #291923
 
// ─────────────────────────────────────────────
// WEEKLY PERFORMANCE
// ─────────────────────────────────────────────
 
weekChange(symbol) =>
    request.security(symbol, "W", (close / close[1] - 1) * 100, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
 
// Currency indexes
 
usd = weekChange("TVC:DXY")
eur = weekChange("TVC:EXY")
gbp = weekChange("TVC:BXY")
jpy = weekChange("TVC:JXY")
chf = weekChange("TVC:SXY")
aud = weekChange("TVC:AXY")
cad = weekChange("TVC:CXY")
nzd = weekChange("TVC:ZXY")
 
// ─────────────────────────────────────────────
// RANKING
// ─────────────────────────────────────────────
 
names = array.from("USD", "EUR", "GBP", "JPY", "CHF", "AUD", "CAD", "NZD")
 
values = array.from(usd, eur, gbp, jpy, chf, aud, cad, nzd)
 
// Strongest to weakest
ranking = array.sort_indices(values, order.descending)
 
// ─────────────────────────────────────────────
// TABLE
// ─────────────────────────────────────────────
 
var table fxTable = table.new(
     tablePosition, 3, 11,
     bgcolor=dark,
     frame_color=#294461,
     frame_width=1,
     border_width=0
     )
 
if barstate.isfirst
    table.merge_cells(fxTable, 0, 0, 2, 0)
    table.merge_cells(fxTable, 0, 1, 2, 1)
 
if barstate.islast
 
    // Main title
    table.cell(
         fxTable, 0, 0,
         "▰  FX PERFORMANCE",
         text_color=white,
         bgcolor=dark,
         text_size=size.large,
         text_halign=text.align_center
         )
 
    // Subtitle
    table.cell(
         fxTable, 0, 1,
         "W E E K L Y   C U R R E N C Y   S T R E N G T H",
         text_color=muted,
         bgcolor=dark,
         text_size=size.tiny,
         text_halign=text.align_center
         )
 
    // Column headers
    table.cell(
         fxTable, 0, 2, "  #  ",
         text_color=muted,
         bgcolor=headerBg,
         text_size=size.small
         )
 
    table.cell(
         fxTable, 1, 2, "  CURRENCY  ",
         text_color=muted,
         bgcolor=headerBg,
         text_size=size.small
         )
 
    table.cell(
         fxTable, 2, 2, "    THIS WEEK    ",
         text_color=blue,
         bgcolor=headerBg,
         text_size=size.small
         )
 
    // Ranked currencies
    for i = 0 to 7
 
        idx = array.get(ranking, i)
        currency = array.get(names, idx)
        change = array.get(values, idx)
 
        // Alternating rows and ranking highlights
        rowBg = i == 0 ? strongBg : i == 7 ? weakBg : i % 2 == 0 ? rowA : rowB
 
        // Change colors
        changeColor = na(change) ? muted : change > 0 ? green : change < 0 ? red : muted
 
        // Percentage formatting
        direction = na(change) ? "" : change > 0 ? "▲ +" : change < 0 ? "▼ " : "• "
 
        changeText = na(change) ? "N/A" : direction + str.tostring(change, "0.00") + "%"
 
        rankText = i < 9 ? "0" + str.tostring(i + 1) : str.tostring(i + 1)
 
        // Ranking number
        table.cell(
             fxTable, 0, i + 3,
             "  " + rankText + "  ",
             text_color=muted,
             bgcolor=rowBg,
             text_size=textSize,
             text_halign=text.align_center
             )
 
        // Currency
        table.cell(
             fxTable, 1, i + 3,
             "  " + currency + "  ",
             text_color=white,
             bgcolor=rowBg,
             text_size=textSize,
             text_halign=text.align_center
             )
 
        // Weekly performance
        table.cell(
             fxTable, 2, i + 3,
             "  " + changeText + "  ",
             text_color=changeColor,
             bgcolor=rowBg,
             text_size=textSize,
             text_halign=text.align_right
             )

← 返回列表