PROTECTED SOURCE SCRIPT

MACD HTF - Accurate Backtest Metrics

71
// ╔══════════════════════════════════════════════════════════════════════════════╗
// ║ MACD HTF STRATEGY WITH ACCURATE BACKTEST ║
// ╚══════════════════════════════════════════════════════════════════════════════╝
//
// 📊 STRATEGY OVERVIEW:
// This advanced MACD strategy allows you to execute trades based on Higher Timeframe (HTF)
// signals while operating on lower timeframe charts for precise entry timing.
//
// ⚡ KEY FEATURES:
// • Higher Timeframe Signal Detection (e.g., 15min signals on 1min chart)
// • Accurate Backtest Calculations with Commission & Slippage
// • Trailing Stop Loss with Offset
// • Hard Stop Loss (Percentage or Points based)
// • Cooldown Period after trade exits
// • Detailed Performance Metrics Panel
// • Visual Stop Loss Lines
// • Real-time Signal State Tracking
//
// 📈 HOW IT WORKS:
// 1. SIGNAL GENERATION:
// - Detects MACD crossovers on selected timeframe (current or HTF)
// - HTF mode: Captures 15min (or custom) signals while on 1min chart
// - Bullish: MACD crosses above Signal line → BUY
// - Bearish: MACD crosses below Signal line → SELL
//
// 2. ENTRY EXECUTION:
// - Current TF Mode: Executes immediately on signal
// - HTF Mode + Close: Waits for HTF candle close (more accurate)
// - HTF Mode + Immediate: Executes as soon as HTF signal appears
//
// 3. RISK MANAGEMENT:
// - Hard Stop Loss: Fixed percentage or points from entry
// - Trailing Stop: Activates after reaching trail points profit
// - Trail Offset: Maintains distance from highest/lowest point
// - Cooldown: Prevents overtrading after exits
//
// 4. POSITION MANAGEMENT:
// - Long Only / Short Only / Both directions
// - Automatic position reversal on opposite signals
// - One position at a time (no pyramiding)
//
// 🎯 RECOMMENDED SETTINGS:
// • For Scalping: 1min chart with 15min HTF signals
// • For Day Trading: 5min chart with 1H HTF signals
// • For Swing Trading: 1H chart with 4H/Daily HTF signals
//
// 📊 BACKTEST ACCURACY:
// • Commission: 0.1% per trade (adjustable)
// • Slippage: 3 ticks default (adjustable)
// • Execution: On bar close for realistic results
// • No repainting: lookahead=false on security calls
//
// ⚠️ IMPORTANT NOTES:
// • HTF signals may appear delayed on lower timeframes
// • Always wait for HTF close for most accurate backtesting
// • Stop losses may trigger intrabar (not visible in backtest)
// • Past performance does not guarantee future results
//
// 📝 USAGE INSTRUCTIONS:
// 1. Add to chart (recommended: 1min or 5min)
// 2. Enable "Use Higher Timeframe Signals"
// 3. Set Signal Timeframe (15min, 30min, 1H, etc.)
// 4. Configure Stop Loss settings
// 5. Set appropriate Cooldown period
// 6. Review backtest metrics in bottom-right panel
//
// 🔧 CUSTOMIZATION:
// • Adjust MACD parameters (Fast/Slow/Signal)
// • Modify Stop Loss percentage or points
// • Change trailing stop activation and offset
// • Set custom backtest date range
// • Fine-tune commission and slippage
//
// 💡 PRO TIPS:
// • Use HTF for trend direction, LTF for entry timing
// • Higher commission/slippage = more realistic results
// • Longer cooldown periods reduce overtrading
// • Trail offset prevents premature exits
//
// 📧 SUPPORT:
// For questions or suggestions, please comment on TradingView

כתב ויתור

המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.