Strategy · Pine Script v5 · Own pane

ATR Volatility Power Strategy

by hayashi19· code credited to HayashiHitsuji

This strategy uses the same smoothed ATR-above-its-low measure as the matching indicator, shown in a separate pane.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code61
Settings4inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago10 Jan 2022

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

61 lines of Pine Script v5 from strategy/STRATEGY ATR Volatility Power (林19).pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

STRATEGY ATR Volatility Power (林19).pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HayashiHitsuji

//@version=5
strategy("STRATEGY: ATR Volatility Power (林19)", shorttitle = "ATR Volatility Power (林19)", overlay = false, format = format.price, pyramiding = 0, default_qty_type = strategy.cash, default_qty_value = 100, currency = currency.USD, slippage = 1, process_orders_on_close = true, initial_capital = 100)

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// INDICATOR INPUT =============================================================
atr_period  = input.int(14, "ATR Value")
atr_low     = input.int(200, "ATR Lowest Value")
atr_smooth  = input.int(9, "ATR Smooth")
break_per   = input.int(9, "ATR Breakout Value")
// ========================================================================== //

// INDICATOR CALCULATION =======================================================
atr         = ta.atr(atr_period)
atr_lowest  = ta.lowest(atr, atr_low)
atr         := ta.sma(atr - atr_lowest, atr_smooth)

atr_break   = ta.lowest(atr, break_per)
// ========================================================================== //

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// INDICATOR CONDITION & COLOR =================================================
atr_color   = atr[1] < atr ? color.lime : color.red
break_color = atr == atr_break ? color.blue : color.white
// ========================================================================== //

// INDICATOR PLOT ==============================================================
plot(atr, color = atr_color, style = plot.style_columns)
plot(atr_break, color = break_color, style = plot.style_circles, linewidth = 2)
// ========================================================================== //

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Strategy Algo
long_entry  = close[1] < close[2] and close[0] > close[1] and atr[0] > atr[1] //and close > ta.ema(close, 200)
short_entry = close[1] > close[2] and close[0] < close[1] and atr[0] > atr[1] //and close < ta.ema(close, 200)

long_tp     = close[1] > close[2] and close[0] < close[1] and atr[0] > atr[1]
short_tp    = close[1] < close[2] and close[0] > close[1] and atr[0] > atr[1]

// long_sl     = ta.crossunder(rsi, rsi_sl_long)
// short_sl    = ta.crossover(rsi, rsi_sl_short)

// Strategy Execution
strategy.entry("enter long", strategy.long, when = long_entry)
strategy.entry("enter short", strategy.short, when = short_entry)

// strategy.exit("exit long", "enter long", profit = 50000)
// strategy.exit("exit short", "enter short", profit = 50000)

strategy.close("enter long", when = long_tp, qty_percent = 100, comment = "take profit slong")
strategy.close("enter short", when = short_tp, qty_percent = 100, comment = "take profit short")

// strategy.close("enter long", when = rsi_stop ? long_sl : na, qty_percent = 100, comment = "stop loss slong")
// strategy.close("enter short", when = rsi_stop ? short_sl : na, qty_percent = 100, comment = "stop loss short")

// bgcolor(buy_sell ? color.new(long_entry ? color.green : short_entry ? color.red : na, 85) : na)

Overview

ATR Volatility Power Strategy opens a long when the close turns up after a down close while the volatility value is rising, and a short when the close turns down after an up close under the same rising condition. It closes the position on the opposite close pattern with rising volatility. The stop loss and fixed profit lines in the code are commented out, so exits rely only on those rules.

Details

Published by

hayashi19 on GitHub

Code credit

HayashiHitsuji, as written in the script's header

Type

Strategy, Pine Script v5

Draws

Separate pane below the chart

Category

Volatility & bands, Breakout

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
ATR Valueint14atr_period
ATR Lowest Valueint200atr_low
ATR Smoothint9atr_smooth
ATR Breakout Valueint9break_per
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

6 stars

This strategy identifies high-volatility expansion bars by comparing the high-low range to a moving average plus standard deviation threshold. When range expansion occurs, it checks momentum over a specified lookback period. It opens a long position if the cur

Strategy v5 Volatility & bandsOscillators & momentum
Updated 1 year ago · None stated GitHub repository of TradersPost High-Low Range Strategy
257 stars

This strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry

Strategy v6 Volatility & bandsSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of V1.6 ES - Futures 1M No Repaint
218 stars

This strategy detects price breakouts above rolling highest highs or below lowest lows over a customizable lookback period. It includes optional volume spike and ATR volatility threshold filters, along with bar confirmation rules. Positions are taken upon conf

Strategy v6 BreakoutVolatility & bands
Updated 3 months ago · None stated GitHub repository of Breakout Strategy Template

Bollinger Breakout

by hackingthemarkets
189 stars

This price-chart strategy plots a simple moving average and upper and lower bands built from the standard deviation of close, scaled by separate offset inputs. It enters a fixed quantity long when close crosses above the upper band and a fixed quantity short w

Strategy v4 Volatility & bandsBreakout
Updated 3 years ago · None stated GitHub repository of Bollinger Breakout

2 Candles Inside ATR

by hasnocool
106 stars

2 Candles Inside ATR is an overlay script that measures volatility compression across two consecutive candles. It calculates a smoothed Average True Range (ATR) and compares it against the combined high and low range of the current and previous bars. When the

Strategy v4 Volatility & bandsBreakout
Updated 2 years ago · GPL-3.0 GitHub repository of 2 Candles Inside ATR

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers