Xem Tiếng Việt
Chương 4Original (EN)

Chapter 4: Using Trade Dependence to Improve Trend Following (The Turtle Filter)


Chapter Overview — 00:00

In classical finance, trade returns are assumed to be independent and identically distributed (i.i.d.). Under this assumption, whether your last trade won or lost provides zero information about the expected value of your next trade. In reality, certain trading systems exhibit significant trade dependence—a statistical condition where a trade's payoff is conditioned on the outcome of previous trades.

The most famous historical application of trade dependence comes from Richard Dennis and William Eckhardt's legendary Turtle Traders. One of their core rules was strictly counter-intuitive: skip a breakout entry if the preceding trade signal was a winner.

This chapter investigates trade dependence using Bitcoin hourly data and the classic Donchian Channel breakout:

  1. Trade Isolation & Distributional Asymmetry: Converting continuous position vectors into discrete trade logs to analyze skewness and fat tails.
  2. Visualizing Conditional Returns: Mapping trade return against lagged return (Lag1Lag_1) via scatter plots.
  3. Statistical Verification via the Runs Test: Calculating expected runs, variance, and Z-scores to formally prove serial non-independence.
  4. The Modified "Prior-Loser" Strategy: Testing the Turtle rule across lookback horizons from 12 to 168 hours to establish parameter invariance.

1. Baseline Strategy: Donchian Channel Breakout — 00:31

Strategy Logic

The classic Donchian breakout is an "always-in-the-market" trend following system:

  • Long Entry: When the current close exceeds the highest close of the past NN bars (Close > max(Close[t-1 : t-N])). Hold until a short signal occurs.
  • Short Entry: When the current close falls below the lowest close of the past NN bars (Close < min(Close[t-1 : t-N])). Hold until a long signal occurs.

Baseline Performance

Tested on hourly Bitcoin data with a standard lookback of N=24N = 24 hours:

  • Raw performance is marginally profitable before friction, but average trade expectation is small.
  • Once realistic exchange fees and slippage are factored in, continuous whipsawing rapidly erodes net equity.
  • Filtering entries is mandatory for survival.

2. Isolating Individual Trades & The Payoff Distribution — 01:34

Converting Position Signals to Trade Objects

To evaluate trade dependence, one cannot rely on bar-by-bar returns; trades must be segmented into discrete episodes:

  • The get_trades_from_signal function loops through the ternary signal series (+1, 0, -1).
  • When a transition occurs, it records the entry price and timestamp, calculates the percentage return upon exit (inverting short return signs: Rshort=(Pentry−Pexit)/PentryR_{\text{short}} = (P_{\text{entry}} - P_{\text{exit}}) / P_{\text{entry}}), and compiles discrete trade dataframes.
Signal:   ... -1 -1 -1  +1  +1  +1  +1 -1 -1 ...
Trade:    [--- Short ---][---- Long ---][-- Short ...]
Return:       -1.2%          +8.4%        ...

Anatomy of Trend Following Returns — 03:52

Plotting the histogram of all Donchian trade returns reveals two structural hallmarks of trend following:

  1. Negative Mode / Peak Below Zero: The single most common trade is a small loss caused by false breakouts and choppy sideways noise.
  2. Heavy Positive Skew (Fat Right Tail): Strategy profitability is entirely driven by a small handful of massive winning outlier trades that ride sustained macro trends.

3. Identifying Trade Dependence — 04:23

Lagged Return Scatter Plot

By plotting the previous trade's return (Rt−1R_{t-1}) on the X-axis against the current trade's return (RtR_t) on the Y-axis, a striking pattern emerges:

  • Trades following a Winner (Rt−1>0R_{t-1} > 0): Average return is negative. Large winning trades are exceptionally rare.
  • Trades following a Loser (Rt−1<0R_{t-1} < 0): Average return is positive. Nearly all major fat-tail winners occur immediately after a losing trade.
        Next Trade Return (R_t)
                  ^
         Fat Tail |      *
         Winners  |    *   *   *
                  |   *     *
      - - - - - - + - - - - - - - - - - > R_{t-1}
                  |     *  *   *
         Small    |   * *   * *   *
         Losers   |  * * *   *
                  v (Loser) | (Winner)

The Market Mechanism

Why does this happen in trend following? After an extended, explosive trend ends, the market almost never transitions immediately into an equally clean opposing trend. Instead, it enters a period of high volatility, consolidation, and false breakouts. The first reversal signal is usually caught in this chop (resulting in a loss). Once the consolidation range resolves, the subsequent breakout captures the next real trend.


4. Formal Statistical Proof: The Wald-Wolfowitz Runs Test — 05:09

Rather than relying purely on visual scatter plots, the Runs Test provides rigorous non-parametric hypothesis testing for serial independence.

Mathematical Formulation

Convert the sequence of trade returns into a sequence of binary signs (+1+1 for win, −1-1 for loss). A run is a maximal contiguous subsequence of identical signs. Let:

  • N+N_+ = Total number of winning trades.
  • N−N_- = Total number of losing trades.
  • N=N++N−N = N_+ + N_- = Total number of trades.
  • RR = Observed number of runs.

Under the null hypothesis of statistical independence, the expected number of runs μR\mu_R and variance σR2\sigma_R^2 are:

μR=2N+N−N+1\mu_R = \frac{2 N_+ N_-}{N} + 1

σR2=2N+N−(2N+N−−N)N2(N−1)\sigma_R^2 = \frac{2 N_+ N_- (2 N_+ N_- - N)}{N^2 (N - 1)}

Z=R−μRσRZ = \frac{R - \mu_R}{\sigma_R}

Interpreting the Z-Score

  • Z≈0Z \approx 0: The win/loss sequence is purely random and independent.
  • Z<0Z < 0 (Fewer runs than expected): Clustering/streaking behavior (winners follow winners, losers follow losers).
  • Z>0Z > 0 (More runs than expected): Alternating behavior (winners follow losers, losers follow winners).

Empirical Results on Bitcoin

  • For N=24N = 24 hours: Z=+2.7Z = +2.7, corresponding to a p-value<0.007p\text{-value} < 0.007. This soundly rejects the independence hypothesis.
  • Grid Evaluation (N=12N = 12 to 168168 hours): Computing the Z-score across the entire parameter spectrum reveals positive, elevated Z-scores across virtually all lookbacks. The alternating tendency is an intrinsic property of the market's interaction with the channel breakout.

5. Implementing the Modified Signal & Results — 08:00

The Modified Signal Engine

A stateful filter wraps the base Donchian signal:

  1. Track the entry price and active direction of the current position.
  2. When the base signal reverses, compute whether the closing trade resulted in a profit or loss.
  3. Execution Rule:
    • If last_trade == LOSS, take the new breakout signal (signal = +1 or -1).
    • If last_trade == WIN, stay flat (signal = 0), skipping the trade until the skipped signal closes.
def generate_dependent_signal(prices: np.ndarray, base_signal: np.ndarray, take_after: str = 'loss') -> np.ndarray:
    mod_signal = np.zeros_like(base_signal)
    last_long_result = None
    last_short_result = None
    # Track positions and conditionally output 1, -1, or 0
    ...
    return mod_signal

Performance Comparison (N=24N = 24 Lookback) — 10:23

Three variations were benchmarked:

  1. Base Donchian Breakout: Choppy, marginally positive equity curve with severe drawdowns.
  2. Prior-Winner Rule (Take trades only after a win): Steadily deteriorating equity curve with heavy net losses.
  3. Prior-Loser Rule (Take trades only after a loss): Smooth upward-sloping equity curve with substantially reduced drawdown and higher Profit Factor.

Parameter Robustness Grid (N∈[12,168]N \in [12, 168]) — 10:39

Plotting ln⁡(Profit Factor)\ln(\text{Profit Factor}) across all lookbacks demonstrates remarkable robustness:

  • For every single lookback period, the "prior-loser" rule significantly boosted the Profit Factor compared to the base strategy.
  • Conversely, taking trades following a winner produced net unprofitable results across almost the entire spectrum.

Key Takeaways & Practical Wisdom

  • Trade dependence is strategy-specific: In most mean-reversion or arbitrary indicator strategies, trade dependence is absent (Z≈0Z \approx 0). However, in breakout trend following, it is powerful and pervasive.
  • The Turtle Traders were right: Decades after Richard Dennis taught this rule to commodity traders, the exact same statistical dynamic governs hourly cryptocurrency markets.
  • Whipsaw dampening: Skipping trades after winners effectively insulates capital from post-trend consolidation traps.
  • Alternative dependence vectors: Traders can expand this research by conditioning entries not just on binary win/loss outcomes, but on trade magnitude (e.g., skipping only after large outlier winners) or trade duration.

Nguồn duy nhất: Kênh YouTube chính thức của neurotrader. Nội dung được hệ thống hóa phục vụ học tập & tra cứu — bấm các mốc thời gian trong bài để xem trực tiếp video gốc của tác giả.