OPEN-SOURCE SCRIPT

VWAP & Band Cross Strategy v6 - Advanced

194
These are a few updates made to the original script. The daily take profit and stop loss functions correctly for 1 contract but because of the pyramiding input even if not used you'll need to multiply the values by the number of contracts to keep consistent results. I have been unable to correct that function. Let me know if you test the script and have any recommendations for improvement. If trading an actual account I do recommend setting hard daily limits with your provider because there is still slippage from the original exit alerts even with the daily stop loss in place.

1. Real-Time Execution & Hard PnL Limits (The Focus)
The most critical changes were implemented to ensure the daily profit and loss limits act as hard, real-time barriers instead of waiting for the candle to close.
• Intrabar Tick Execution: The parameter calc_on_every_tick=true was added to the strategy() declaration. This forces the entire script to re-evaluate its logic on every single price update (tick), enabling immediate action.
• Real-Time PnL Tracking: The PnL calculation was updated to track the total_daily_pnl by summing the realized profit/loss (from closed trades) and the unrealized profit/loss (strategy.openprofit) on every tick.
• Immediate Closure: The script now checks the total_daily_pnl against the user-defined limits (daily_take_profit_value, daily_stop_loss_value) and immediately executes strategy.close_all() the moment the threshold is breached, preventing further trading.
• Combined Risk Enforcement: The user-defined "Max Intraday Risk ($)" and the "Daily Stop Loss (Value)" are compared, and the script enforces the tighter of the two limits.
2. Visibility and External Alerting
To address the unavoidable issue of slippage (which causes price overshoot in fast markets even with tick execution), dedicated alert mechanisms were added.
• Dedicated Alert Condition: An alertcondition named DAILY PNL LIMIT REACHED was added. This allows you to set up a TradingView alert that triggers the instant the daily_limit_reached variable turns true, giving you the fastest possible notification.
• Visual Marker: A large red triangle (\u25b2) is plotted on the chart using plotchar at the exact moment the daily limit condition is met, providing a clear visual confirmation of the trigger bar.
3. Strategy Features and Input Flexibility
Several user-requested features were integrated to make the strategy more robust and customizable.
• Trailing Stop / Breakeven (TSL/BE): A new exit option, Fixed Ticks + TSL, was added, allowing you to set a fixed profit target while also deploying a trailing stop or breakeven level based on points/ticks gained.
• Multiple Exit Types: The exit strategy was expanded to include logic for several types: Fixed Ticks, ATR-based, Capped ATR-based, VWAP Cross, and Price/Band Crosses.
• Pyramiding Control: An input Max Pyramiding Entries was introduced to control how many positions the strategy can have open at the same time.
• Confirmation Logic Toggle: Added an input to choose how multiple confirmation indicators (RSI, SMMA, MACD) are combined: "AND" (all must be true) or "OR" (at least one must be true).
• Indicator Confirmations: Logic for three external indicators—RSI, SMMA (EMA), and MACD—was fully integrated to act as optional filters for entry.
• VWAP Reset Anchors: Logic was corrected to properly reset the VWAP calculation based on the selected period ("Daily", "Weekly", or "Session") by using Pine Script v6's required anchor series.
Trading Day Filters: Inputs were added to select which specific days of the week the strategy is allowed to trade.

免責事項

これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。