OPEN-SOURCE SCRIPT
Güncellendi

SMA Angle Alerts

1 026
SMA Angle Alerts
Overview:
The "SMA Angle Alerts" indicator measures the angle of the Simple Moving Average (SMA) over a specified number of bars, helping traders identify when the market is gaining or losing momentum. The indicator provides real-time alerts when the angle of the SMA crosses user-defined thresholds, indicating strong upward or downward movements in the trend.

How it works:

SMA Calculation: The indicator calculates the Simple Moving Average (SMA) of the closing price over a customizable length.
Angle Calculation: It determines the slope of the SMA by measuring the price change over a set number of bars and converts that slope into an angle (in degrees).
Alerts: Alerts are triggered when the SMA angle crosses above or below specified thresholds, allowing traders to react to significant trend changes in real time.
Key Features:

Customizable SMA and Angle Threshold:

The length of the SMA and the threshold for the angle can be customized to fit your trading strategy.
Real-Time Alerts:

Alerts are triggered when the angle of the SMA crosses upward or downward by more than the defined threshold, providing actionable insights into trend strength and direction.
Visual Markers:

The chart visually highlights points where the angle of the SMA exceeds the threshold, with "UP" and "DOWN" labels to mark when the angle is steep enough to signal significant trend changes.
Background Color Alerts:

The chart’s background color changes when the angle exceeds the thresholds—green for upward crosses and red for downward crosses—allowing traders to quickly spot moments of interest.
Plotting the Angle:

The slope of the SMA is plotted in degrees, giving traders a visual representation of the market's momentum. Horizontal lines mark the upper and lower angle thresholds, offering a clear view of when price momentum is accelerating or decelerating.
Use Case:
This indicator is ideal for traders looking to catch strong trend reversals, breakouts, or momentum shifts. It can be used across multiple timeframes to monitor market momentum and identify key moments when the trend is gaining strength in either direction.

Customization:

SMA Length: Adjust the length of the SMA to suit different timeframes or asset classes.
Angle Threshold: Define the angle at which alerts are triggered, allowing you to focus on strong upward or downward movements.
Bars to Check: Customize how many bars are used to calculate the slope and angle of the SMA.
Alerts:

Set alerts to notify you when the SMA is angling up or down by more than your specified threshold, ensuring that you never miss a significant trend shift.
Sürüm Notları
Here’s a comprehensive description of your **enhanced "MA Angle Alerts" indicator**, including a detailed comparison with the **original SMA-only version**:

---

## 📈 MA Angle Alerts (SMA, EMA, VWMA, WMA) — Full Indicator Description

This Pine Script v6 indicator analyzes the **angle (slope)** of a selected **moving average (MA)** and generates alerts when the angle exceeds a specified threshold — indicating a strong trend or potential breakout condition.

### 🔍 What It Does:

* Measures the **slope of a moving average** over a set number of bars
* Converts the slope to **degrees** using trigonometry
* Triggers visual and alert-based signals when:

* The angle **exceeds a positive threshold** (angling up)
* The angle **drops below a negative threshold** (angling down)
* Supports **multiple MA types**: SMA, EMA, WMA, and VWMA

---

## ✅ Key Features

### 📊 MA Type Selection

Choose your preferred moving average method:

* **SMA**: Simple Moving Average
* **EMA**: Exponential Moving Average (faster reaction to price)
* **WMA**: Weighted Moving Average
* **VWMA**: Volume-Weighted Moving Average

> 🔄 This is a major upgrade from the original script, which only used **SMA**.

---

### 📐 Angle Detection Logic

* Calculates slope: `(MA - MA[n bars ago]) / n`
* Converts to angle using: `atan(slope) * (180 / π)`
* Threshold-based alerts:

* **Upward angle alert** if angle > threshold (e.g., 35°)
* **Downward angle alert** if angle < -threshold

---

### 🎯 Custom Parameters

| Input | Description |
| --------------------------- | --------------------------------------- |
| **MA Type** | Choose SMA, EMA, VWMA, or WMA |
| **MA Length** | Period used for moving average |
| **Angle Threshold (°)** | Angle required to trigger an alert |
| **Bars to Check for Slope** | How many bars back to measure the slope |

---

### 📈 Visual Outputs

* Plots the selected **MA line** on the price chart
* Plots the **slope angle** in a subchart
* Adds **horizontal reference lines** for the positive and negative angle thresholds
* Shows **color-coded background**:

* Green for upward alert
* Red for downward alert
* Places **label markers** ("UP" or "DOWN") on signal bars

---

### 🔔 Alerts

* Fires **TradingView alerts** when:

* MA is angling **up** past the threshold
* MA is angling **down** below the threshold
* Uses **constant strings** (required in Pine v6)

> 🔄 In the original script, alerts were also present, but limited to **SMA** only. This version improves accuracy and flexibility.

---

### 🧠 Enhancements Over the Original Script

| Feature | Original Script | Updated Script |
| ----------------------- | -------------------- | ---------------------------------------------------- |
| **MA Type** | SMA only | Select SMA, EMA, VWMA, WMA |
| **Language Version** | Pine Script v5 | Pine Script **v6** |
| **Alert Flexibility** | Basic | Clean constant alerts with TradingView v6 compliance |
| **Slope Label Logic** | Present | Enhanced with value plotting and visual angles |
| **Background Coloring** | ✓ | ✓ |
| **Signal Filtering** | Basic | Fully parameterized and precise |
| **Code Stability** | Uses `na` improperly | Proper type-safe booleans (`false`) for tracking |
| **Customization** | Limited | Fully parameterized and robust |

---

## 🧪 Ideal Use Cases

* Spotting strong **trend acceleration**
* Confirming breakout conditions based on **MA angle**
* Filtering trades with **angle-based trend strength**
* Backtesting strategies that depend on **MA momentum**

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.