commit bd681dc939bba6bd771f082d25c3128f656a0d52 Author: mfcheah Date: Thu Apr 9 14:16:26 2026 +0800 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..0469321 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# John Carter TTM TradingView Project + +This repository contains Pine Script implementations of John Carter’s **TTM Trend** and **TTM Squeeze** indicators, adapted for TradingView. +It also includes crossover logic (8/18 SMA) and long-term trend filters (100 SMA). + +--- + +## 📂 Project Structure +- `ttm_trend.pine` → Solid candle coloring (blue/red/gray) + SMA crossover signals. +- `ttm_squeeze.pine` → Momentum histogram + squeeze dots (with adjustable size). +- `ttm_strategy.pine` → Combined signals for backtesting entries/exits. +- `README.md` → Documentation and usage notes. + +--- + +## ⚙️ Default Settings (John Carter) +- **TTM Squeeze** + - Bollinger Bands: 20-period SMA, 2.0 StdDev + - Keltner Channels: 20-period SMA, 1.5 × ATR + - Histogram: 20-period linear regression +- **TTM Trend** + - Trend baseline: 20 SMA + - Candle colors: Blue (uptrend), Red (downtrend), Gray (neutral) +- **Crossover** + - Fast SMA: 8 + - Slow SMA: 18 + - Long-term SMA: 100 (white) + +--- + +## 🚀 Usage +1. Copy `.pine` files into TradingView’s Pine Editor. +2. Add indicators to your chart: + - Overlay `ttm_trend.pine` on price. + - Add `ttm_squeeze.pine` in a separate panel. +3. Adjust inputs (lengths, multipliers) in the settings panel to match your trading style. + +--- + +## 📈 Strategy Notes +- **Buy Signal**: 8 SMA crosses above 18 SMA, candles blue, squeeze fires. +- **Sell Signal**: 8 SMA crosses below 18 SMA, candles red, squeeze fires. +- **Filter**: Optional — only take signals aligned with the 100 SMA trend. + +--- + +## 📝 Next Steps +- Add alerts for squeeze releases. +- Backtest combined signals in `ttm_strategy.pine`. +- Experiment with different lengths (e.g., 21, 30) for volatility adaptation. diff --git a/ttm_squeeze.pine b/ttm_squeeze.pine new file mode 100644 index 0000000..3766b98 --- /dev/null +++ b/ttm_squeeze.pine @@ -0,0 +1,29 @@ +//@version=5 +indicator("TTM Squeeze", overlay=false) + +squeezeLen = input.int(20, "Squeeze Length") +mult = input.float(2.0, "StdDev Multiplier") + +// Bollinger Bands +basis = ta.sma(close, squeezeLen) +dev = mult * ta.stdev(close, squeezeLen) +upperBB = basis + dev +lowerBB = basis - dev + +// Keltner Channels +atr = ta.atr(squeezeLen) +upperKC = basis + atr * 1.5 +lowerKC = basis - atr * 1.5 + +// Squeeze condition +squeezeOn = (upperBB < upperKC) and (lowerBB > lowerKC) + +// Momentum histogram +mom = ta.linreg(close - basis, squeezeLen, 0) + +// Bigger squeeze dots +plot(squeezeOn ? 0 : na, style=plot.style_circles, color=color.red, linewidth=4, title="Squeeze On") +plot(not squeezeOn ? 0 : na, style=plot.style_circles, color=color.green, linewidth=4, title="Squeeze Off") + +// Momentum histogram +plot(mom, style=plot.style_histogram, color=mom >= 0 ? color.lime : color.orange, title="Momentum") diff --git a/ttm_strategy.pine b/ttm_strategy.pine new file mode 100644 index 0000000..aa305ac --- /dev/null +++ b/ttm_strategy.pine @@ -0,0 +1,39 @@ +//@version=5 +indicator("TTM Trend + SMA Crossover + 100 SMA", overlay=true) + +// Trend baseline +length = input.int(20, "Trend Length") +ma = ta.sma(close, length) + +// Candle colors (TTM Trend) +trendColor = close > ma ? color.blue : close < ma ? color.red : color.gray +plotcandle(open, high, low, close, + color=trendColor, + wickcolor=trendColor, + bordercolor=trendColor, + title="TTM Trend Candles") + +// SMA crossover logic +fastLen = input.int(8, "Fast SMA") +slowLen = input.int(18, "Slow SMA") + +fastMA = ta.sma(close, fastLen) +slowMA = ta.sma(close, slowLen) + +plot(fastMA, color=color.yellow, title="8 SMA") +plot(slowMA, color=color.purple, title="18 SMA") + +// Add 100 SMA in white +sma100 = ta.sma(close, 100) +plot(sma100, color=color.white, title="100 SMA") + +// Detect crossovers +bullCross = ta.crossover(fastMA, slowMA) +bearCross = ta.crossunder(fastMA, slowMA) + +// Print buy/sell labels +plotshape(bullCross, title="Buy Signal", text="BUY", style=shape.labelup, + location=location.belowbar, color=color.green, textcolor=color.white, size=size.tiny) + +plotshape(bearCross, title="Sell Signal", text="SELL", style=shape.labeldown, + location=location.abovebar, color=color.red, textcolor=color.white, size=size.tiny) diff --git a/ttm_trend.pine b/ttm_trend.pine new file mode 100644 index 0000000..e69de29