OPEN-SOURCE SCRIPT

Custom Trend Indicator


**Custom Trend Indicator**
This indicator identifies bullish and bearish trends using two simple moving averages (SMAs) of customizable lengths. The fast-moving average reacts more quickly to price changes, while the slow-moving average provides a smoother view of the trend. Key features include:

1. **Trend Detection:**
- A bullish trend is identified when the fast-moving average crosses above the slow-moving average.
- A bearish trend is identified when the fast-moving average crosses below the slow-moving average.

2. **Visual Aids:**
- Moving averages are plotted on the chart for clear trend visualization.
- Background colors (green for bullish, red for bearish) highlight the active trend.
- Labels are added at crossover points to mark significant trend changes.

This tool is helpful for traders looking to quickly identify and act on market trends based on simple moving average crossovers.

//version=5
indicator("Custom Trend Indicator", overlay=true)

// Input settings for moving averages
length_fast = input.int(9, minval=1, title="Fast Moving Average Length")
length_slow = input.int(21, minval=1, title="Slow Moving Average Length")

// Calculate moving averages
ma_fast = ta.sma(close, length_fast)
ma_slow = ta.sma(close, length_slow)

// Determine trend conditions
bullish_trend = ma_fast > ma_slow
bearish_trend = ma_fast < ma_slow

// Plot moving averages
plot(ma_fast, color=color.new(color.green, 0), title="Fast MA")
plot(ma_slow, color=color.new(color.red, 0), title="Slow MA")

// Highlight the background for trends
bgcolor(bullish_trend ? color.new(color.green, 90) : na, title="Bullish Trend Background")
bgcolor(bearish_trend ? color.new(color.red, 90) : na, title="Bearish Trend Background")

// Add labels for trend changes
var label bullish_label = na
var label bearish_label = na

if ta.crossover(ma_fast, ma_slow)
label.delete(bearish_label)
bullish_label := label.new(bar_index, high, "Bullish", style=label.style_label_up, color=color.new(color.green, 0))

if ta.crossunder(ma_fast, ma_slow)
label.delete(bullish_label)
bearish_label := label.new(bar_index, low, "Bearish", style=label.style_label_down, color=color.new(color.red, 0))
Trend Analysis

Açık kaynak kodlu komut dosyası

Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının yazarı komut dosyasını açık kaynak olarak yayınlamıştır, böylece yatırımcılar betiği anlayabilir ve doğrulayabilir. Yazar çok yaşa! Ücretsiz olarak kullanabilirsiniz, ancak bu kodun yayında yeniden kullanımı Ev kurallarına tabidir. Bir grafikte kullanmak için favorilere ekleyebilirsiniz.

Bu komut dosyasını bir grafikte kullanmak ister misiniz?

Feragatname