OPEN-SOURCE SCRIPT
Telah dikemas kini

Bullish and Bearish Breakout Alert for Gold Futures Pullback

319
Below is a Pine Script (version 6) for TradingView that includes both bullish and bearish breakout conditions for my intraday trading strategy on micro gold futures (MGC). The strategy focuses on scalping two-legged pullbacks to the 20 EMA or key levels with breakout confirmation, tailored for the Apex Trader Funding $300K challenge. The script accounts for the Daily Sentiment Index (DSI) at 87 (overbought, favoring pullbacks). It generates alerts for placing stop-limit orders for 175 MGC contracts, ensuring compliance with Apex’s rules ($7,500 trailing threshold, $20,000 profit target, 4:59 PM ET close).

Script Requirements
Version: Pine Script v6 (latest for TradingView, April 2025).
Purpose:
Bullish: Alert when price breaks above a rejection candle’s high after a two-legged pullback to the 20 EMA in a bullish trend (price above 20 EMA, VWAP, higher highs/lows).
Bearish: Alert when price breaks below a rejection candle’s low after a two-legged pullback to the 20 EMA in a bearish trend (price below 20 EMA, VWAP, lower highs/lows).
Context: 5-minute MGC chart, U.S. session (8:30 AM–12:00 PM ET), avoiding overbought breakouts above $3,450 (DSI 87).
Output: Alerts for stop-limit orders (e.g., “Buy: Stop=$3,377, Limit=$3,377.10” or “Sell: Stop=$3,447, Limit=$3,446.90”), quantity 175 MGC.
Apex Compliance: 175-contract limit, stop-losses, one-directional news trading, close by 4:59 PM ET.

How to Use the Script in TradingView

1. Add Script:
Open TradingView (tradingview.com).
Go to “Pine Editor” (bottom panel).
Copy the script from the <xaiArtifact> content.
Click “Add to Chart” to apply to your MGC 5-minute chart [].

2. Configure Chart:
Symbol: MGC (Micro Gold Futures, CME, via Tradovate/Apex data feed).
Timeframe: 5-minute (entries), 15-minute (trend confirmation, manually check).
Indicators: Script plots 20 EMA and VWAP; add RSI (14) and volume manually if needed [].

3. Set Alerts:
Click the “Alert” icon (bell).
Add two alerts:
Bullish Breakout: Condition = “Bullish Breakout Alert for Gold Futures Pullback,” trigger = “Once Per Bar Close.”
Bearish Breakout: Condition = “Bearish Breakout Alert for Gold Futures Pullback,” trigger = “Once Per Bar Close.”
Customize messages (default provided) and set notifications (e.g., TradingView app, SMS).
Example: Bullish alert at $3,377 prompts “Stop=$3,377, Limit=$3,377.10, Quantity=175 MGC” [].

4. Execute Orders:
Bullish:
Alert triggers (e.g., stop $3,377, limit $3,377.10).
In TradingView’s “Order Panel,” select “Stop-Limit,” set:
Stop Price: $3,377.
Limit Price: $3,377.10.
Quantity: 175 MGC.
Direction: Buy.
Confirm via Tradovate.
Add bracket order (OCO):
Stop-loss: Sell 175 at $3,376.20 (8 ticks, $1,400 risk).
Take-profit: Sell 87 at $3,378 (1:1), 88 at $3,379 (2:1) [].
Bearish:
Alert triggers (e.g., stop $3,447, limit $3,446.90).
Select “Stop-Limit,” set:
Stop Price: $3,447.
Limit Price: $3,446.90.
Quantity: 175 MGC.
Direction: Sell.
Confirm via Tradovate.
Add bracket order:
Stop-loss: Buy 175 at $3,447.80 (8 ticks, $1,400 risk).
Take-profit: Buy 87 at $3,446 (1:1), 88 at $3,445 (2:1) [].

5. Monitor:
Green triangles (bullish) or red triangles (bearish) confirm signals.
Avoid bullish entries above $3,450 (DSI 87, overbought) or bearish entries below $3,296 (support) [].
Close trades by 4:59 PM ET (set 4:50 PM alert) [].
Nota Keluaran
Explanation of Changes and Code

Version: version=6 ensures compatibility with TradingView’s latest features.

Inputs:
ema_length (20): For pullback target.
rsi_length (14): Filters overbought/oversold.
volume_length (20): Confirms breakout volume.
rsi_min (30): Allows bearish entries above oversold (RSI > 30, avoiding extreme lows).
rsi_max (70): Prevents bullish entries in overbought conditions (DSI 87) [].

Trend Confirmation:
is_bullish: Price above 20 EMA, VWAP, and higher lows (mimics 15-minute trend on 5-minute chart).
is_bearish: Price below 20 EMA, VWAP, and lower highs [].

Bullish Setup (unchanged from prior script):
bull_pullback: Two down candles near 20 EMA (close < ema).
bull_rejection: Bullish candle (close > open) touching EMA, higher high.
bull_breakout: Close above rejection candle’s high with high volume.
bull_valid: Adds RSI (40–70) and bullish trend filters [].

Bearish Setup:
bear_pullback: Two up candles in a bearish trend (close > close[1] and close[1] > close[2]) near 20 EMA (close > ema).
bear_rejection: Bearish candle (close < open) touching EMA, lower low.
bear_breakout: Close below rejection candle’s low with high volume.
bear_valid: RSI between 30–60 (avoids oversold entries, allows bearish momentum) and bearish trend [].


Alerts:
Bullish: “Bullish Breakout! Place stop-limit order: Stop={{high[1]}}, Limit={{high[1] + 0.10}}, Quantity=175 MGC” (e.g., stop $3,377, limit $3,377.10).
Bearish: “Bearish Breakout! Place stop-limit order: Stop={{low[1]}}, Limit={{low[1] - 0.10}}, Quantity=175 MGC” (e.g., stop $3,447, limit $3,446.90) [].

How to Use the Script in TradingView
Configure Chart:
Symbol: MGC (Micro Gold Futures, CME)
Timeframe: 5-minute (entries), 15-minute (trend confirmation, manually check).
Indicators: Script plots 20 EMA and VWAP; add RSI (14) and volume manually if needed [].
Set Alerts:
Click the “Alert” icon (bell).
Add two alerts:
Bullish Breakout: Condition = “Bullish Breakout Alert for Gold Futures Pullback,” trigger = “Once Per Bar Close.”
Bearish Breakout: Condition = “Bearish Breakout Alert for Gold Futures Pullback,” trigger = “Once Per Bar Close.”
Customize messages (default provided) and set notifications (e.g., TradingView app, SMS).
Example: Bullish alert at $3,377 prompts “Stop=$3,377, Limit=$3,377.10, Quantity=175 MGC” [].

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.