OPEN-SOURCE SCRIPT

ATR Band Exit Strategy

//version=5
strategy("ATR Band Exit Strategy", overlay=true)

// Define input parameters
atrLength = input(14, title="ATR Length")
atrMultiplier = input(2.0, title="ATR Multiplier")
maLength = input(50, title="Moving Average Length")

// Calculate ATR and moving average
atrValue = ta.atr(atrLength)
maValue = ta.sma(close, maLength)

// Calculate upper and lower ATR bands
upperBand = close + atrMultiplier * atrValue
lowerBand = close - atrMultiplier * atrValue

// Plot ATR bands
plot(upperBand, title="Upper ATR Band", color=color.red, linewidth=2)
plot(lowerBand, title="Lower ATR Band", color=color.green, linewidth=2)

// Entry condition (for demonstration: long if price above moving average)
longCondition = ta.crossover(close, maValue)
if (longCondition)
strategy.entry("Long", strategy.long)

// Exit conditions (exit if price crosses the upper or lower ATR bands)
if (close >= upperBand)
strategy.close("Long", comment="Exit on Upper ATR Band")
if (close <= lowerBand)
strategy.close("Long", comment="Exit on Lower ATR Band")

// Optional: Plot the moving average for reference
plot(maValue, title="Moving Average", color=color.blue)
Bill Williams IndicatorsBreadth Indicators

オープンソーススクリプト

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。

チャートでこのスクリプトを利用したいですか?

免責事項