OPEN-SOURCE SCRIPT
SPY/TLT Strategy

█ STRATEGY OVERVIEW
The "SPY/TLT Strategy" is a trend-following crossover strategy designed to trade the relationship between TLT and its Simple Moving Average (SMA). The default configuration uses TLT (iShares 20+ Year Treasury Bond ETF) with a 20-period SMA, entering long positions on bullish crossovers and exiting on bearish crossunders. **This strategy is NOT optimized and performs best in trending markets.**
█ KEY FEATURES
█ SIGNAL GENERATION
1. LONG ENTRY CONDITION
2. EXIT CONDITION
█ ADDITIONAL SETTINGS
█ PERFORMANCE OVERVIEW
The "SPY/TLT Strategy" is a trend-following crossover strategy designed to trade the relationship between TLT and its Simple Moving Average (SMA). The default configuration uses TLT (iShares 20+ Year Treasury Bond ETF) with a 20-period SMA, entering long positions on bullish crossovers and exiting on bearish crossunders. **This strategy is NOT optimized and performs best in trending markets.**
█ KEY FEATURES
- SMA Crossover System: Uses price/SMA relationship for signal generation (Default: 20-period)
- Dynamic Time Window: Configurable backtesting period (Default: 2014-2099)
- Equity-Based Position Sizing: Default 100% equity allocation per trade
- Real-Time Visual Feedback: Price/SMA plot with trend-state background coloring
- Event-Driven Execution: Processes orders at bar close for accurate backtesting
█ SIGNAL GENERATION
1. LONG ENTRY CONDITION
- TLT closing price crosses ABOVE SMA
- Occurs within specified time window
- Generates market order at next bar open
2. EXIT CONDITION
- TLT closing price crosses BELOW SMA
- Closes all open positions immediately
█ ADDITIONAL SETTINGS
- SMA Period: Simple Moving Average length (Default: 20)
- Start Time and End Time: The time window for trade execution (Default: 1 Jan 2014 - 1 Jan 2099)
- Security Symbol: Ticker for analysis (Default: TLT)
█ PERFORMANCE OVERVIEW
- Ideal Market Conditions: Strong trending environments
- Potential Drawbacks: Whipsaws in range-bound markets
- Backtesting results should be analyzed to optimize the MA Period and EMA Filter settings for specific instruments
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.