OPEN-SOURCE SCRIPT

Buy/Sell Signals for Natural Gas Futures

//version=5
indicator("Buy/Sell Signals for Natural Gas Futures", overlay=true)

// Input for Moving Averages
emaShortLength = input.int(20, title="Short EMA Length")
emaLongLength = input.int(50, title="Long EMA Length")

// Input for ATR (Stop-Loss, Take-Profit)
atrLength = input.int(14, title="ATR Length")
atrMultiplier = input.float(1.5, title="ATR Multiplier")
riskRewardRatio = input.float(2.0, title="Risk-Reward Ratio")

// Calculate Moving Averages
emaShort = ta.ema(close, emaShortLength)
emaLong = ta.ema(close, emaLongLength)

// Trend Detection
isUptrend = emaShort > emaLong
isDowntrend = emaShort < emaLong

// Average True Range (ATR) for Volatility-based Stop-Loss/Take-Profit
atr = ta.atr(atrLength)

// Breakout/Breakdown Levels (5-bar high/low for breakout/fall)
breakoutLevel = ta.highest(high, 5)
breakdownLevel = ta.lowest(low, 5)

// Buy Signal Condition
buySignal = close > breakoutLevel and isUptrend

// Sell Signal Condition
sellSignal = close < breakdownLevel and isDowntrend

// Stop-Loss and Take-Profit Levels (using ATR)
stopLossLong = close - (atr * atrMultiplier)
takeProfitLong = close + (atr * atrMultiplier * riskRewardRatio)
stopLossShort = close + (atr * atrMultiplier)
takeProfitShort = close - (atr * atrMultiplier * riskRewardRatio)

// Plot Buy/Sell Signals
plotshape(series=buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// Plot Stop-Loss and Take-Profit Levels for Buy and Sell
plotshape(series=buySignal ? stopLossLong : na, title="Stop-Loss Long", color=color.red, style=shape.triangledown, location=location.absolute, offset=-1, size=size.small)
plotshape(series=buySignal ? takeProfitLong : na, title="Take-Profit Long", color=color.green, style=shape.triangleup, location=location.absolute, offset=-1, size=size.small)

plotshape(series=sellSignal ? stopLossShort : na, title="Stop-Loss Short", color=color.red, style=shape.triangledown, location=location.absolute, offset=-1, size=size.small)
plotshape(series=sellSignal ? takeProfitShort : na, title="Take-Profit Short", color=color.green, style=shape.triangleup, location=location.absolute, offset=-1, size=size.small)

// Highlight the trend on the background (green for uptrend, red for downtrend)
bgcolor(isUptrend ? color.new(color.green, 90) : isDowntrend ? color.new(color.red, 90) : na)

// Alerts for Buy/Sell Signals
alertcondition(buySignal, title="Buy Signal Alert", message="Buy Signal Detected: Price has broken above resistance in an uptrend.")
alertcondition(sellSignal, title="Sell Signal Alert", message="Sell Signal Detected: Price has broken below support in a downtrend.")
Chart patterns

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?

면책사항