OPEN-SOURCE SCRIPT

Custom MA Crossover with Volume

//version=5
indicator("Custom MA Crossover with Volume", overlay=true)

// User-defined moving average periods
fast_length = input.int(10, title="Fast MA Length")
slow_length = input.int(100, title="Slow MA Length")

// Calculate moving averages
fast_ma = ta.sma(close, fast_length)
slow_ma = ta.sma(close, slow_length)

// Calculate 10-day average volume
volume_avg = ta.sma(volume, 10)

// Define crossover conditions
bullish_crossover = ta.crossover(fast_ma, slow_ma) and volume > volume_avg
bearish_crossover = ta.crossunder(fast_ma, slow_ma) and volume > volume_avg

// Plot moving averages
plot(fast_ma, color=color.green, title="Fast MA")
plot(slow_ma, color=color.red, title="Slow MA")

// Plot buy and sell labels
if (bullish_crossover)
label.new(bar_index, na, "Buy", color=color.green, style=label.style_label_up, textcolor=color.white)

if (bearish_crossover)
label.new(bar_index, na, "Sell", color=color.red, style=label.style_label_down, textcolor=color.white)

// Display volume average for reference
plot(volume_avg, color=color.blue, title="10-Day Avg Volume", linewidth=1)
Cycles

Mã nguồn mở

Theo tinh thần TradingView thực sự, tác giả của tập lệnh này đã xuất bản dưới dạng nguồn mở để các nhà giao dịch có thể hiểu và xác minh. Chúc mừng tác giả! Bạn có thể sử dụng miễn phí. Tuy nhiên, bạn cần sử dụng lại mã này theo Quy tắc nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?

Thông báo miễn trừ trách nhiệm