OPEN-SOURCE SCRIPT

EMA(9) / SMMA(14) Crossover Alert with time blocks

108
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.

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ ข้อกำหนดการใช้งาน