OPEN-SOURCE SCRIPT
EMA(9) / SMMA(14) Crossover Alert with time blocks

This Pine Script v6 code is a Moving Average Crossover Alert Indicator that generates trading signals and alerts only within a specified time window. It uses a faster Exponential Moving Average (EMA) and a slower Smoothed Moving Average (SMMA) to identify potential shifts in market momentum.
Key Features and Logic
1. Moving Average Calculations
The indicator plots two moving averages (MAs) on the chart:
Fast MA (EMA 9): An Exponential Moving Average (EMA) with a default length of 9 periods. The EMA reacts more quickly to price changes.
Slow MA (SMMA 14): A Smoothed Moving Average (SMMA) with a default length of 14 periods. The SMMA (calculated using ta.rma in Pine v6) smooths price data more than a standard Simple Moving Average.
The user can customize both the EMA Length and SMMA Length via the indicator settings.
2. Time Window Restriction ⏰
The script incorporates a critical time filter to restrict all signals and alerts to a specific daily trading session.
Time Session: The alerts are restricted to the time between 6:30 AM CST and 2:30 PM CST.
Implementation: This is achieved by converting the Central Time (CST) range to 7:30-15:30 (EST) and applying the time() function with the "GMT-5" timezone (which covers EST/EDT). The boolean variable time_in_range is only true when the current bar falls within this time window.
3. Crossover Signals
The code defines two primary crossover events, which represent the trading signals:
Bullish Cross (Cross Up): The EMA 9 (blue line) crosses above the SMMA 14 (red line), indicating bullish momentum.
Bearish Cross (Cross Down): The EMA 9 (blue line) crosses below the SMMA 14 (red line), indicating bearish momentum.
4. Visuals and Alerts
Plots: Both the EMA 9 (blue) and SMMA 14 (red) lines are plotted directly on the price chart (overlay=true).
Visual Highlights: Small plotshapes are drawn on the chart only when a crossover occurs and the time is within the specified time_in_range window:
Green Triangle Up: for a Bullish Cross.
Red Triangle Down: for a Bearish Cross.
Alerts: Two separate alertcondition calls are configured to trigger external notifications. Crucially, the alerts will only fire if both the crossover condition AND the time_in_range condition are met. The alerts include dynamic placeholders for the ticker, interval, and closing price.
Key Features and Logic
1. Moving Average Calculations
The indicator plots two moving averages (MAs) on the chart:
Fast MA (EMA 9): An Exponential Moving Average (EMA) with a default length of 9 periods. The EMA reacts more quickly to price changes.
Slow MA (SMMA 14): A Smoothed Moving Average (SMMA) with a default length of 14 periods. The SMMA (calculated using ta.rma in Pine v6) smooths price data more than a standard Simple Moving Average.
The user can customize both the EMA Length and SMMA Length via the indicator settings.
2. Time Window Restriction ⏰
The script incorporates a critical time filter to restrict all signals and alerts to a specific daily trading session.
Time Session: The alerts are restricted to the time between 6:30 AM CST and 2:30 PM CST.
Implementation: This is achieved by converting the Central Time (CST) range to 7:30-15:30 (EST) and applying the time() function with the "GMT-5" timezone (which covers EST/EDT). The boolean variable time_in_range is only true when the current bar falls within this time window.
3. Crossover Signals
The code defines two primary crossover events, which represent the trading signals:
Bullish Cross (Cross Up): The EMA 9 (blue line) crosses above the SMMA 14 (red line), indicating bullish momentum.
Bearish Cross (Cross Down): The EMA 9 (blue line) crosses below the SMMA 14 (red line), indicating bearish momentum.
4. Visuals and Alerts
Plots: Both the EMA 9 (blue) and SMMA 14 (red) lines are plotted directly on the price chart (overlay=true).
Visual Highlights: Small plotshapes are drawn on the chart only when a crossover occurs and the time is within the specified time_in_range window:
Green Triangle Up: for a Bullish Cross.
Red Triangle Down: for a Bearish Cross.
Alerts: Two separate alertcondition calls are configured to trigger external notifications. Crucially, the alerts will only fire if both the crossover condition AND the time_in_range condition are met. The alerts include dynamic placeholders for the ticker, interval, and closing price.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.