OPEN-SOURCE SCRIPT

MKD 1

//version=5
indicator("Buy and Sell Indicator with Bar Labels", overlay=true)

// Define short and long period for moving averages
shortPeriod = input.int(9, title="Short Period SMA")
longPeriod = input.int(21, title="Long Period SMA")

// Calculate the moving averages
shortSMA = ta.sma(close, shortPeriod)
longSMA = ta.sma(close, longPeriod)

// Plot the moving averages
plot(shortSMA, color=color.blue, linewidth=2, title="Short Period SMA")
plot(longSMA, color=color.red, linewidth=2, title="Long Period SMA")

// Generate Buy and Sell signals based on crossover
buySignal = ta.crossover(shortSMA, longSMA)
sellSignal = ta.crossunder(shortSMA, longSMA)

// Create labels for buy and sell signals on bars
if buySignal
label.new(bar_index, low, "BUY", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small, yloc=yloc.belowbar)

if sellSignal
label.new(bar_index, high, "SELL", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small, yloc=yloc.abovebar)

// Add alerts for Buy and Sell signals
alertcondition(buySignal, title="Buy Signal Alert", message="Buy Signal Triggered!")
alertcondition(sellSignal, title="Sell Signal Alert", message="Sell Signal Triggered!")
Candlestick analysis

開源腳本

在真正的TradingView精神中,這個腳本的作者以開源的方式發佈,這樣交易員可以理解和驗證它。請向作者致敬!您可以免費使用它,但在出版物中再次使用這段程式碼將受到網站規則的約束。 您可以收藏它以在圖表上使用。

想在圖表上使用此腳本?

免責聲明