本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
strategy('MVWAP 5/20 Beak + MA 200 + MVWAP 8 Stop', overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)
// --- 參數設定 (Inputs) ---
fast_period = input.int(5, 'Fast MVWAP Period')
slow_period = input.int(20, 'Slow MVWAP Period')
stop_period = input.int(8, 'Stop MVWAP Period (Exit)')
trend_period = input.int(200, 'Trend Filter MA Period (MA 200)')
trend_type = input.string('SMA', 'Trend MA Type', options = ['SMA', 'EMA'])
max_dist_pct = input.float(0.5, 'Max Distance % (Bird\'s Beak Squeeze)')
enable_long = input.bool(true, 'Enable Long')
enable_short = input.bool(true, 'Enable Short')
// --- 指標計算 (Calculations) ---
fast_vwma = ta.vwma(close, fast_period)
slow_vwma = ta.vwma(close, slow_period)
stop_vwma = ta.vwma(close, stop_period)
trend_ma = trend_type == 'SMA' ? ta.sma(close, trend_period) : ta.ema(close, trend_period)
// 1. 鳥嘴糾結檢查 (Bird's Beak Squeeze - 過去 5 根內)
was_entangled = false
for i = 0 to 4 by 1
f_val = ta.vwma(close, fast_period)[i]
s_val = ta.vwma(close, slow_period)[i]
dist = math.abs(f_val - s_val) / s_val * 100.0
if dist <= max_dist_pct
was_entangled := true
was_entangled
// 2. 鳥嘴張開 (Expansion)
bullish_beak = fast_vwma > slow_vwma and fast_vwma - slow_vwma > fast_vwma[1] - slow_vwma[1]
bearish_beak = fast_vwma < slow_vwma and slow_vwma - fast_vwma > slow_vwma[1] - fast_vwma[1]
// 3. 大趨勢過濾 (Trend Filter)
above_trend = close > trend_ma
below_trend = close < trend_ma
// --- 進場條件 (Entry Conditions) ---
long_condition = enable_long and above_trend and bullish_beak and was_entangled
short_condition = enable_short and below_trend and bearish_beak and was_entangled
if long_condition and strategy.position_size == 0
strategy.entry('Long', strategy.long)
if short_condition and strategy.position_size == 0
strategy.entry('Short', strategy.short)
// --- 離場條件 (Exit: MVWAP 8 Stop) ---
if strategy.position_size > 0 and close < stop_vwma
strategy.close('Long', comment = 'MVWAP8 Exit')
if strategy.position_size < 0 and close > stop_vwma
strategy.close('Short', comment = 'MVWAP8 Exit')
// --- 圖表繪製與指定顏色 (Plotting) ---
plot(fast_vwma, 'Fast MVWAP 5', color = color.red, linewidth = 2)
plot(slow_vwma, 'Slow MVWAP 20', color = color.green, linewidth = 2)
plot(stop_vwma, 'Stop MVWAP 8', color = color.gray, linewidth = 1)
plot(trend_ma, 'Trend MA 200', color = color.orange, linewidth = 2)