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

Script open-source

Dans le plus pur esprit TradingView, l'auteur de ce script l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par nos Règles. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Vous voulez utiliser ce script sur un graphique ?

Clause de non-responsabilité