DivHK_Weights

S-Schmidt · library · 126 行 · 点赞 2 · TradingView 原页

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

Pine Script

//@version=6
// ╔══════════════════════════════════════════════════════════════════════════════╗
// ║  DivHK_Weights  ·  Zentrale Gewichtungs-Library                            ║
// ║  Publish as: S-Schmidt/DivHK_Weights/1                                     ║
// ║  Usage:   import S-Schmidt/DivHK_Weights/1 as dw                           ║
// ╠══════════════════════════════════════════════════════════════════════════════╣
// ║  Funktionsbereiche:                                                         ║
// ║  1. f_profil_gewichte  — Systemprofile (Z-Zyklen + Indikatorgruppen)       ║
// ║  2. f_branchen_gewichte — Branchenspezifische Indikatorgewichte System A   ║
// ╚══════════════════════════════════════════════════════════════════════════════╝
// Branchen-IDs:
//   0 = Transport & Logistik         (B0)
//   1 = Basiskonsumgüter             (B1)
//   2 = Versorger                    (B2)
//   3 = Telekommunikation            (B3)
//   4 = Finanzen / Banken            (B4)
//   5 = REITs / Immobilien           (B5)
//   6 = Energie / Rohstoffe / Chemie (B6)
//   7 = Automobil / Industrie        (B7)
//   8 = Healthcare / Pharma          (B8)
//   9 = Medien / Konsum              (B9)
//  -1 = Unbekannt / Fallback         (neutral 1.0)
// ─────────────────────────────────────────────────────────────────────────────
 
library("DivHK_Weights", overlay = false)
 
// ═══════════════════════════════════════════════════════════════════════════════
// FUNKTION 1 — f_profil_gewichte
// Systemübergreifende Gewichtsprofile für Z-Zyklen und Indikatorgruppen.
//
// Parameter:
//   profil     — "konservativ" | "ausgewogen" | "aggressiv"
//   schluessel — Bezeichner des abgefragten Gewichts (siehe unten)
//
// Z-Gewichte (Summe = 1.0):
//   "z1" — kürzester Zyklus
//   "z2" — kurzer Zyklus
//   "z3" — mittlerer Zyklus
//   "z4" — langer Zyklus
//   "z5" — ultra-langer Zyklus
//
// Gruppengewichte System A:
//   "a_fundamental" — Fundamentalgruppe (KGV, DivR, KBV)
//   "a_momentum"    — Momentumgruppe (RSI, MFI, CMF)
//
// Gruppengewichte System B:
//   "b_technisch"   — Technischgruppe (Swing, VP)
//   "b_pivot"       — Pivotgruppe
//
// Rückgabe: float — Gewichtsfaktor; na bei unbekanntem Schlüssel
// ═══════════════════════════════════════════════════════════════════════════════
 
export f_profil_gewichte(simple string profil, simple string schluessel) =>
    float _result = na
 
    if schluessel == "z1"
        _result := profil == "konservativ" ? 0.10 : profil == "aggressiv" ? 0.30 : 0.20
 
    else if schluessel == "z2"
        _result := profil == "konservativ" ? 0.15 : profil == "aggressiv" ? 0.30 : 0.25
 
    else if schluessel == "z3"
        _result := profil == "konservativ" ? 0.25 : profil == "aggressiv" ? 0.20 : 0.25
 
    else if schluessel == "z4"
        _result := profil == "konservativ" ? 0.25 : profil == "aggressiv" ? 0.15 : 0.20
 
    else if schluessel == "z5"
        _result := profil == "konservativ" ? 0.25 : profil == "aggressiv" ? 0.05 : 0.10
 
    else if schluessel == "a_fundamental"
        _result := profil == "konservativ" ? 1.4 : profil == "aggressiv" ? 0.7 : 1.0
 
    else if schluessel == "a_momentum"
        _result := profil == "konservativ" ? 0.7 : profil == "aggressiv" ? 1.4 : 1.0
 
    else if schluessel == "b_technisch"
        _result := 1.0
 
    else if schluessel == "b_pivot"
        _result := 1.0
 
    _result
 
// ═══════════════════════════════════════════════════════════════════════════════
// FUNKTION 2 — f_branchen_gewichte
// Branchenspezifisches Gewicht für einen Indikator in System A.
//
// Parameter:
//   branche_id — int 0..9 (B0–B9) oder -1 (unbekannt/Fallback)
//   indikator  — "kgv" | "divr" | "kurs" | "rsi" | "mfi" | "cmf" | "kbv"
//
// Gewichtsquellen:
//   kgv  — höher bei stabilen Gewinnsektoren (B1, B2, B3, B8)
//   divr — höher bei Dividendensektoren (B2, B3, B5)
//   kurs — höher bei zyklischen Sektoren (B0, B6, B7)
//   rsi/mfi/cmf — höher bei volatilen/zyklischen Sektoren
//   kbv  — höher bei kapitalintensiven/buchwertrelevanten Sektoren (B4, B5)
//          niedriger bei Intangible-dominierten Sektoren (B8, B9, B1, B3)
//
// Rückgabe: float — Gewichtsfaktor; 1.0 bei unbekanntem branche_id oder indikator
// ═══════════════════════════════════════════════════════════════════════════════
 
export f_branchen_gewichte(simple int branche_id, simple string indikator) =>
    float _result = 1.0
 
    if indikator == "kgv"
        _result := branche_id == 0 ? 1.0 : branche_id == 1 ? 1.3 : branche_id == 2 ? 1.2 : branche_id == 3 ? 1.2 : branche_id == 4 ? 0.8 : branche_id == 5 ? 0.9 : branche_id == 6 ? 0.7 : branche_id == 7 ? 0.7 : branche_id == 8 ? 1.3 : branche_id == 9 ? 1.0 : 1.0
 
    else if indikator == "divr"
        _result := branche_id == 0 ? 0.9 : branche_id == 1 ? 1.2 : branche_id == 2 ? 1.4 : branche_id == 3 ? 1.3 : branche_id == 4 ? 1.0 : branche_id == 5 ? 1.4 : branche_id == 6 ? 1.0 : branche_id == 7 ? 0.8 : branche_id == 8 ? 1.0 : branche_id == 9 ? 0.8 : 1.0
 
    else if indikator == "kurs"
        _result := branche_id == 0 ? 1.1 : branche_id == 1 ? 0.9 : branche_id == 2 ? 0.8 : branche_id == 3 ? 0.9 : branche_id == 4 ? 1.0 : branche_id == 5 ? 1.0 : branche_id == 6 ? 1.2 : branche_id == 7 ? 1.2 : branche_id == 8 ? 1.0 : branche_id == 9 ? 1.1 : 1.0
 
    else if indikator == "rsi"
        _result := branche_id == 0 ? 1.0 : branche_id == 1 ? 0.9 : branche_id == 2 ? 0.9 : branche_id == 3 ? 0.9 : branche_id == 4 ? 1.0 : branche_id == 5 ? 0.9 : branche_id == 6 ? 1.1 : branche_id == 7 ? 1.1 : branche_id == 8 ? 1.0 : branche_id == 9 ? 1.1 : 1.0
 
    else if indikator == "mfi"
        _result := branche_id == 0 ? 1.0 : branche_id == 1 ? 0.9 : branche_id == 2 ? 0.9 : branche_id == 3 ? 0.9 : branche_id == 4 ? 1.1 : branche_id == 5 ? 1.0 : branche_id == 6 ? 1.1 : branche_id == 7 ? 1.1 : branche_id == 8 ? 1.0 : branche_id == 9 ? 1.0 : 1.0
 
    else if indikator == "cmf"
        _result := branche_id == 0 ? 1.0 : branche_id == 1 ? 0.9 : branche_id == 2 ? 0.9 : branche_id == 3 ? 0.9 : branche_id == 4 ? 1.1 : branche_id == 5 ? 1.0 : branche_id == 6 ? 1.1 : branche_id == 7 ? 1.1 : branche_id == 8 ? 1.0 : branche_id == 9 ? 1.0 : 1.0
 
    else if indikator == "kbv"
        _result := branche_id == 0 ? 1.0 : branche_id == 1 ? 0.7 : branche_id == 2 ? 1.0 : branche_id == 3 ? 0.7 : branche_id == 4 ? 1.5 : branche_id == 5 ? 1.3 : branche_id == 6 ? 0.9 : branche_id == 7 ? 1.0 : branche_id == 8 ? 0.6 : branche_id == 9 ? 0.6 : 1.0

← 返回列表