PROTECTED SOURCE SCRIPT

配對交易waynecoin製作2

26
原始策略邏輯
只要zScore大於某個值(如2)就做空ETH做多BTC
只要zScore小於某個值(如-2)就做多ETH做空BTC
但這種方式有時訊號太多、容易假突破、勝率不穩定

優化邏輯目標
1. 降低訊號頻率,過濾掉沒意義的雜訊交易
2. 等到「明顯極端」再動手,讓每一單都更有「均值回歸」的機會
3. 進場後,避免被盤整來回洗掉,強制休息一段時間(冷卻期)再考慮下一單

1. 「極端區才做」:提高入場門檻
以前你設定zScore>2或<-2就進場,這個「門檻」容易被雜訊觸發。
優化方式:把門檻拉高(例如2.5或3),訊號只會在「非常極端」的狀態下才出現,減少亂進場。

2. 「回歸動能確認」:等它真的要回來再做
傳統做法常在zScore剛突破極端值時就馬上進場,結果價格還是繼續爆走,導致虧損。
優化方式:
先等zScore跑到極端區(>2.5或<-2.5),
等它「開始回頭」(例如:zScore從3往下跌,跌破2.5時才進場),
這樣能增加「回歸」動能,少做那種「突破後持續單邊爆走」的盤。

3. 「冷卻期」:強制休息、減少來回被巴
很多交易在平倉後,立刻又收到新訊號反向進場,容易被盤整來回磨。
優化方式:設一個「冷卻期」(例如15根K線),這段期間內不再產生新訊號,即使條件觸發也忽略,讓你有時間等下一波「真正有利的極端機會」。

主要變數說明
plotH:入場門檻(如2.5),zScore超過這個數才考慮進場。
cooldown:冷卻K線數,這段期間內無論有無訊號都不能再進新倉。
last_entry_bar:紀錄上次開倉的bar_index,用於計算冷卻期。

進場邏輯
如果zScore「向上」突破-plotH,並且目前不在冷卻期,則產生一個做多ETH/做空BTC訊號(標籤顯示)。
如果zScore「向下」突破plotH,且不在冷卻期,則產生做空ETH/做多BTC訊號。
每次有訊號進場後,都把last_entry_bar更新為當下K線的bar_index,進入冷卻期。

入場標準差原本設定2.5,但可自行設定峰值,數值設定越高,信號越少
冷卻k線數可以自己設定,當你設定的數值越高,信號越少
Look-Back Periodu也可以自己設定,數值越高回朔時間越長,信號越少


我一直在思考什麼樣的策略適合散戶交易
想了一年多只想到兩種交易
1.對沖策略只吃異常波動率
2.資金費率套利

當前先針對對沖策略來發佈
後續會繼續發表資費套利

**Original Strategy Logic**
As long as the zScore is greater than a certain value (e.g., 2), short ETH and long BTC.
As long as the zScore is less than a certain value (e.g., -2), long ETH and short BTC.
However, this approach sometimes generates too many signals, is prone to false breakouts, and has unstable win rates.
---
**Optimization Goals**
1. Reduce signal frequency and filter out meaningless/noisy trades
2. Wait for "obvious extremes" before taking action, giving each trade a better chance at mean reversion
3. After entry, avoid getting chopped in sideways markets by enforcing a cooldown period before considering the next trade

---
**1. "Only trade in extreme zones": Increase entry threshold**
Previously, you entered whenever zScore > 2 or < -2. This threshold is easily triggered by noise.
**Optimization:** Raise the threshold (e.g., to 2.5 or 3), so signals only appear in "very extreme" conditions, reducing random entries.

**2. "Confirm mean reversion momentum": Wait until it actually starts to revert**
The traditional approach often enters right when zScore first breaks the extreme value, but sometimes price keeps moving in the same direction, leading to losses.
**Optimization:**

* First, wait until zScore reaches the extreme zone (>2.5 or <-2.5),
* Then, wait for it to "start reverting" (for example, zScore falls back below 2.5 from above 3),
* Only enter then. This increases the likelihood of actual mean reversion and avoids getting caught in one-sided trends after the breakout.

**3. "Cooldown period": Force a rest and reduce getting chopped**
Many trades, after closing, immediately receive a new signal and reverse position, which often leads to losses in choppy markets.
**Optimization:** Set a "cooldown period" (e.g., 15 candles). During this time, no new signals are generated—even if conditions are met—allowing you to wait for the next "truly favorable extreme opportunity."

---
**Key Variables**
* `plotH`: Entry threshold (e.g., 2.5). Only consider entries when zScore exceeds this value.
* `cooldown`: Number of cooldown candles. No new entries can be made during this period, regardless of signals.
* `last_entry_bar`: Records the bar\_index of the last entry, used to calculate the cooldown period.
---

**Entry Logic**

* If zScore breaks upwards through -plotH and you’re not in a cooldown period, generate a long ETH/short BTC signal (show a label).
* If zScore breaks downwards through plotH and not in a cooldown period, generate a short ETH/long BTC signal.
* Every time you enter a trade, update `last_entry_bar` to the current bar\_index and enter the cooldown period.

The entry standard deviation threshold is originally set to 2.5, but you can set it to any peak value you prefer—the higher the value, the fewer the signals.
The cooldown candle count is also customizable; the higher the value, the fewer the signals.
The look-back period is adjustable as well; the higher it is, the longer the historical window considered, and the fewer the signals.

---
I’ve been thinking for over a year about what kind of strategies are suitable for retail traders.
After all this time, I’ve only come up with two types:
1. Hedge strategies that only capture abnormal volatility
2. Funding rate arbitrage
Currently, I’m publishing the hedge strategy first.
I’ll continue to share funding rate arbitrage in the future.

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.