Multi-Asset Seasonal & Quantitative Matrix [Almaghamsi]

wmaghmsi · study · 181 行 · 点赞 18 · TradingView 原页

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

Pine Script

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Almaghamsi
 
//@version=6
indicator('Multi-Asset Seasonal & Quantitative Matrix [Almaghamsi]', shorttitle = 'MASQM Matrix', overlay = false)
 
// --- INPUTS & ASSET SELECTOR ---
asset_type = input.string('US Stocks', title = 'Select Asset Class', options = ['US Stocks', 'Saudi Stocks (TASI)', 'Indices', 'Gold & Silver', 'Bitcoin / Crypto', 'Forex'])
show_table = input.bool(true, title = 'Display Dashboard Table')
ma_len = input.int(200, title = 'Macro Trend Filter Length (SMA)')
vol_len = input.int(20, title = 'Volume Average Length')
pat_len = input.int(10, title = 'Fractal Pattern Lookback')
 
cur_month = month(time)
 
// ==========================================
// 1. ASSET-SPECIFIC SEASONAL BIAS MATRICES
// ==========================================
float seasonal_bias = 0.50
 
if asset_type == 'US Stocks'
    seasonal_bias := switch cur_month
        1 => 0.65 // January Effect
        2 => 0.55
        3 => 0.60
        4 => 0.70 // Spring Strength
        5 => 0.45 // Sell in May
        6 => 0.45
        7 => 0.55
        8 => 0.40
        9 => 0.35 // September Weakness
        10 => 0.65 // Uptober
        11 => 0.85 // Q4 Rally
        12 => 0.80 // Santa Claus Rally
        => 0.50
    seasonal_bias
 
else if asset_type == 'Saudi Stocks (TASI)'
    seasonal_bias := switch cur_month
        1 => 0.60
        2 => 0.65
        3 => 0.70
        4 => 0.75 // Earnings & Dividends Season
        5 => 0.50
        6 => 0.45
        7 => 0.45
        8 => 0.40 // Summer Slowdown
        9 => 0.55 // Back to School / Activity
        10 => 0.70
        11 => 0.80 // Year-End Momentum
        12 => 0.75
        => 0.50
    seasonal_bias
 
else if asset_type == 'Indices'
    seasonal_bias := switch cur_month
        1 => 0.65
        2 => 0.55
        3 => 0.60
        4 => 0.70
        5 => 0.48
        6 => 0.48
        7 => 0.60
        8 => 0.42
        9 => 0.38
        10 => 0.68
        11 => 0.85
        12 => 0.82
        => 0.50
    seasonal_bias
 
else if asset_type == 'Gold & Silver'
    seasonal_bias := switch cur_month
        1 => 0.75 // Historical January Strength
        2 => 0.60
        3 => 0.55
        4 => 0.50
        5 => 0.45
        6 => 0.45
        7 => 0.50
        8 => 0.60
        9 => 0.70
        10 => 0.65
        11 => 0.55
        12 => 0.70
        => 0.50
    seasonal_bias
 
else if asset_type == 'Bitcoin / Crypto'
    seasonal_bias := switch cur_month
        1 => 0.55
        2 => 0.70
        3 => 0.60
        4 => 0.65
        5 => 0.50
        6 => 0.40
        7 => 0.50
        8 => 0.45
        9 => 0.35 // Historical Crypto Weakness
        10 => 0.75 // Uptober
        11 => 0.90 // Peak Historical Cycle
        12 => 0.70
        => 0.50
    seasonal_bias
 
else if asset_type == 'Forex'
    seasonal_bias := switch cur_month
        1 => 0.50
        2 => 0.52
        3 => 0.65 // Q1 Rebalancing
        4 => 0.50
        5 => 0.48
        6 => 0.60 // Mid-Year Close
        7 => 0.50
        8 => 0.45
        9 => 0.55
        10 => 0.50
        11 => 0.48
        12 => 0.70 // Year-End Liquidity Shifting
        => 0.50
    seasonal_bias
 
// ==========================================
// 2. QUANTITATIVE SCORE
// ==========================================
float quant_score = seasonal_bias >= 0.65 ? 85.0 : seasonal_bias <= 0.45 ? 30.0 : 50.0
 
// ==========================================
// 3. MACRO REGIME FILTER (200 SMA)
// ==========================================
macro_trend = close > ta.sma(close, ma_len)
float macro_score = macro_trend ? 100.0 : 0.0
 
// ==========================================
// 4. FRACTAL & VOLUME PATTERN
// ==========================================
highest_high = ta.highest(high, pat_len)
lowest_low = ta.lowest(low, pat_len)
range_width = highest_high - lowest_low
avg_range = ta.sma(range_width, 50)
 
is_compression = range_width < avg_range * 0.85
is_breakout_pattern = close > ta.highest(high[1], pat_len) and is_compression[1]
 
vol_sma = ta.sma(volume, vol_len)
rel_vol = volume / vol_sma
 
float fractal_pat_score = is_breakout_pattern and rel_vol > 1.1 ? 100.0 : is_compression ? 65.0 : 40.0
 
// ==========================================
// COMPOSITE CONFLUENCE SCORE (0 - 100%)
// ==========================================
float composite_score = seasonal_bias * 100 * 0.3 + quant_score * 0.3 + macro_score * 0.2 + fractal_pat_score * 0.2
 
// --- PLOTS ---
plot(composite_score, title = 'Composite Confluence Score', color = #29dfff, linewidth = 2)
hline(75, 'High Confluence Zone (Strong Buy)', color = color.green, linestyle = hline.style_dashed)
hline(35, 'Risk / Avoid Zone', color = color.maroon, linestyle = hline.style_dashed)
 
bgcolor(composite_score >= 75 ? color.new(color.green, 85) : composite_score <= 35 ? color.new(color.maroon, 85) : na)
 
// --- DASHBOARD TABLE ---
var table dash = table.new(position = position.top_right, columns = 2, rows = 6, bgcolor = color.new(color.black, 20), border_color = color.gray, border_width = 1)
if barstate.islast and show_table
    table.cell(dash, 0, 0, 'Asset Class', text_color = color.white, text_size = size.small, bgcolor = color.gray)
    table.cell(dash, 1, 0, str.tostring(asset_type), text_color = color.yellow, text_size = size.small, bgcolor = color.gray)
 
    table.cell(dash, 0, 1, '1. Seasonal Bias', text_color = color.white, text_size = size.small)
    table.cell(dash, 1, 1, str.tostring(seasonal_bias * 100, '#.##') + '%', text_color = seasonal_bias >= 0.65 ? color.green : color.red, text_size = size.small)
 
    table.cell(dash, 0, 2, '2. Quantitative Score', text_color = color.white, text_size = size.small)
    table.cell(dash, 1, 2, str.tostring(quant_score, '#.##') + '%', text_color = quant_score > 60 ? color.green : color.orange, text_size = size.small)
 
    table.cell(dash, 0, 3, '3. Macro Trend (200 SMA)', text_color = color.white, text_size = size.small)
    table.cell(dash, 1, 3, macro_trend ? 'BULLISH' : 'BEARISH', text_color = macro_trend ? color.green : color.red, text_size = size.small)
 
    table.cell(dash, 0, 4, '4. Fractal / Pattern', text_color = color.white, text_size = size.small)
    table.cell(dash, 1, 4, is_breakout_pattern ? 'BREAKOUT' : is_compression ? 'COMPRESSION' : 'NEUTRAL', text_color = is_breakout_pattern ? color.green : color.yellow, text_size = size.small)
 
    table.cell(dash, 0, 5, 'Composite Score', text_color = color.white, text_size = size.small, bgcolor = color.gray)
    table.cell(dash, 1, 5, str.tostring(composite_score, '#.##'), text_color = color.rgb(13, 0, 255), text_size = size.small, bgcolor = color.gray)

← 返回列表