OPEN-SOURCE SCRIPT

2-Hour Signal with Profit/Stop Levels

//version=5
indicator("2-Hour Signal with Profit/Stop Levels", overlay=true)

// User Inputs
atrLength = input.int(14, "ATR Length for Stop/Profit", minval=1)
atrMultiplier = input.float(1.5, "ATR Multiplier for Levels", minval=0.1)
volumeMaLength = input.int(20, "Volume MA Length", minval=1)
volumeMultiplier = input.float(1.2, "Volume Multiplier", minval=0.1)

// Fetch 2-hour data
high_2hr = request.security(syminfo.tickerid, "120", high)
low_2hr = request.security(syminfo.tickerid, "120", low)
close_2hr = request.security(syminfo.tickerid, "120", close)
volume_2hr = request.security(syminfo.tickerid, "120", volume)

// ATR for Stop-Loss and Take-Profit levels
atr = request.security(syminfo.tickerid, "120", ta.atr(atrLength))

// Volume analysis
volumeMA = ta.sma(volume_2hr, volumeMaLength)
highVolume = volume_2hr > (volumeMA * volumeMultiplier)

// Buy/Sell Signal Logic
buySignal = close_2hr > ta.highest(high_2hr, 5) and highVolume // Breakout with high volume
sellSignal = close_2hr < ta.lowest(low_2hr, 5) and highVolume // Breakdown with high volume

// Take-Profit and Stop-Loss Levels
buyStopLoss = close_2hr - (atr * atrMultiplier)
buyTakeProfit = close_2hr + (atr * atrMultiplier)
sellStopLoss = close_2hr + (atr * atrMultiplier)
sellTakeProfit = close_2hr - (atr * atrMultiplier)

// Plot Signals
plotshape(buySignal, style=shape.labelup, location=location.belowbar, color=color.green, text="Buy", size=size.small)
plotshape(sellSignal, style=shape.labeldown, location=location.abovebar, color=color.red, text="Sell", size=size.small)

// Plot Stop-Loss and Take-Profit Levels
plot(buySignal ? buyStopLoss : na, title="Buy Stop-Loss", color=color.red, linewidth=1)
plot(buySignal ? buyTakeProfit : na, title="Buy Take-Profit", color=color.blue, linewidth=1)
plot(sellSignal ? sellStopLoss : na, title="Sell Stop-Loss", color=color.green, linewidth=1)
plot(sellSignal ? sellTakeProfit : na, title="Sell Take-Profit", color=color.orange, linewidth=1)

// Background Highlight
bgcolor(buySignal ? color.new(color.green, 90) : sellSignal ? color.new(color.red, 90) : na, title="Signal Highlight")

// Debug: Plot volume for reference
plot(volume_2hr, title="2-Hour Volume", color=color.gray, style=plot.style_histogram)
Bands and ChannelsCandlestick analysisChart patterns

開源腳本

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

想在圖表上使用此腳本?

免責聲明