OPEN-SOURCE SCRIPT

STAX

123
# STAX - MapleStax Candle by Candle Automation

## Overview
STAX is a trend-following indicator that automates the "MapleStax Candle by Candle (CBC)" methodology for futures and equity trading. This system uses a higher timeframe anchor trend combined with lower timeframe execution filters to identify high-probability pullback entries in the direction of the prevailing trend.

## How It Works

### 1. Anchor Trend Detection (10-Minute CBC Flip)
The core of this system is the CBC (Candle by Candle) flip logic on the anchor timeframe (default: 10 minutes):

- **Bullish Flip**: Occurs when a 10m candle closes ABOVE the high of the previous 10m candle
- **Bearish Flip**: Occurs when a 10m candle closes BELOW the low of the previous 10m candle
- Once a flip occurs, the trend remains in that direction until an opposite flip happens

The anchor trend is calculated using `request.security()` with `lookahead=barmerge.lookahead_off` and indexed historical data `[1]` to ensure non-repainting behavior. This means signals will not change or disappear after they appear.

### 2. Execution Filters (Current Timeframe)
On your current chart timeframe (recommended: 3 minutes), the indicator applies two key filters:

**EMA Confirmation**:
- For LONG signals: 9-period EMA must be greater than 20-period EMA
- For SHORT signals: 9-period EMA must be less than 20-period EMA

**VWAP Filter** (Strict or Target mode):
- **Strict Mode** (default): Only shows signals when price is on the correct side of VWAP
- LONG signals only above VWAP
- SHORT signals only below VWAP
- **Target Mode**: Shows all valid signals but uses VWAP as the take profit target when price is on the "wrong" side

### 3. Entry Signal Logic
The indicator looks for pullback entries:

- **BUY Signal**: 10m trend is Bullish + EMA 9 > 20 + Current 3m candle is RED (close < open)
- Logic: Wait for a red pullback candle in a bullish trend with bullish EMA alignment

- **SELL Signal**: 10m trend is Bearish + EMA 9 < 20 + Current 3m candle is GREEN (close > open)
- Logic: Wait for a green retracement candle in a bearish trend with bearish EMA alignment

This pullback logic helps you enter after a brief counter-trend move, improving risk/reward compared to chasing breakouts.

### 4. Risk Management
**Stop Loss**: Automatically set at the previous 10-minute candle's low (for longs) or high (for shorts). This represents the last swing point that would invalidate the trend structure.

**Take Profit**:
- When aligned with VWAP: Fixed tick-based target (default: 20 ticks, adjustable)
- When counter to VWAP: Target is VWAP itself, providing a logical profit target

The indicator displays TP and SL levels visually and alerts when they are hit.

### 5. Signal Management
To prevent over-trading, the indicator includes a **cooldown period** (default: 10 bars minimum between signals). This stops signal spam in choppy conditions and forces you to wait for the market to develop before taking another trade.

### 6. Time Session Filters
Two separate trading sessions can be configured with 12-hour clock inputs:
- **Session 1**: Default 9:30 AM - 4:00 PM (New York regular hours)
- **Session 2**: Optional second session for extended hours or different time zones

Signals only appear during enabled sessions, helping you trade during liquid market hours.

## What Makes This Original

This indicator automates a specific methodology (MapleStax CBC) that combines multiple proven concepts:
1. Higher timeframe trend structure (CBC flip logic)
2. Lower timeframe execution timing (EMA filters)
3. Pullback entry strategy (counter-colored candles)
4. Volume-based target selection (VWAP integration)
5. Swing-based stop placement (previous anchor swing points)

The combination of these elements into an automated system with visual feedback and alert functionality is what provides value beyond using these indicators separately.

## How to Use

1. **Choose Your Timeframes**:
- Anchor timeframe: 10 minutes (adjustable) for trend direction
- Execution timeframe: 3-5 minutes recommended for entries

2. **Select VWAP Mode**:
- **Strict Mode**: More conservative, only trades with VWAP bias
- **Target Mode**: More aggressive, uses VWAP as profit target

3. **Configure Sessions**: Enable Session 1 and optionally Session 2 to match your trading hours

4. **Set Risk Parameters**: Adjust take profit ticks based on your instrument and risk tolerance

5. **Watch for Signals**:
- Green "BUY" label below bars = Long entry
- Red "SELL" label above bars = Short entry
- Dashed red line = Stop loss level
- Green "TP ✓" or Red "SL ✗" labels show exit points

6. **Monitor the Status Table**: The table in the top-right shows:
- Current 10m trend direction
- EMA alignment status
- VWAP position
- Active session status
- Current signal state
- Active trade information

7. **Set Alerts**: Use TradingView's alert system with the built-in alert conditions:
- BUY Signal
- SELL Signal
- Take Profit Hit
- Stop Loss Hit

## Best Practices

- **Recommended Timeframes**: 3m execution chart with 10m anchor works well for active trading
- **Instrument Selection**: Works best on liquid futures contracts (ES, NQ, CL, etc.) and major forex pairs
- **Session Trading**: Enable Session 1 for New York hours; avoid low-volume periods
- **Backtest First**: Always backtest the settings on your specific instrument before live trading
- **Use Realistic Parameters**: Default 20-tick TP is conservative; adjust based on instrument volatility

## Limitations and Warnings

**This indicator does NOT**:
- Guarantee profitable trades (past performance does not indicate future results)
- Account for slippage, commissions, or real-world execution challenges
- Work equally well in all market conditions (performs poorly in low-volume, range-bound markets)
- Replace proper risk management and position sizing
- Provide financial advice

**Repainting**: This indicator is designed to be non-repainting. Signals use indexed historical data from the anchor timeframe, meaning they will not change or disappear after they appear. However, the current bar's status will update in real-time until it closes.

**Market Conditions**: This trend-following pullback system performs best in trending markets with clear directional bias. In choppy, range-bound conditions, expect more false signals despite the cooldown filter.

**Stop Loss Execution**: The stop loss levels shown are theoretical. In fast-moving markets, actual fills may occur at worse prices due to slippage.

## Input Parameters

**Anchor Settings**:
- Anchor Timeframe: Higher timeframe for trend detection (default: 10 minutes)

**EMA Settings**:
- Fast EMA: Short-period EMA for execution bias (default: 9)
- Slow EMA: Long-period EMA for execution bias (default: 20)

**VWAP Settings**:
- Strict VWAP Filter: Toggle between strict filtering and target mode

**Signal Management**:
- Min Bars Between Signals: Cooldown period to prevent spam (default: 10 bars)

**Time Filters**:
- Session 1 & 2: Configure up to two trading sessions with start/end times in 12-hour format

**Risk Management**:
- Take Profit (Ticks): Fixed tick target when aligned with VWAP (default: 20)

**Visual Settings**:
- Show Trend Background: Background color based on 10m trend
- Show Stop Loss Lines: Display SL levels on chart
- Show EMAs: Display 9/20 EMAs on chart
- Show VWAP: Display daily VWAP on chart

## Technical Notes

- Uses Pine Script v5
- Non-repainting implementation via `request.security()` with `lookahead_off` and indexed data
- Suitable for alerts and automated trading integration
- Maximum 50 labels and 50 lines to maintain performance
- Status table updates on each bar close

## Credits

This indicator automates the MapleStax Candle by Candle methodology. The CBC flip logic and pullback entry concept are part of the MapleStax trading education system.

---

**Disclaimer**: This indicator is for educational and informational purposes only. It is not financial advice. Trading futures, forex, and equities carries substantial risk of loss. Past performance is not indicative of future results. Always trade with risk capital you can afford to lose and use proper position sizing.

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.