1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
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
19 lines of Pine Script v4 from Av3.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
Av3.pine
//@version=4
strategy("Av3",overlay=true,default_qty_type=strategy.percent_of_equity,default_qty_value=100)
TrailingStop=input(defval=500,title="Trailing Stop (pips)",minval=1)
TakeProfit=input(defval=500,title="Take Profit ($)",minval=1)
atr=atr(7)[0]
atrav=((atr(7)[1]+atr(7)[2]+atr(7)[3]+atr(7)[4]+atr(7)[5])/5)
if(atr>atrav)
if (open>close[1])
strategy.order("BUY", strategy.long)
if (open<close[1])
strategy.order("SELL", strategy.short)
if(atr<atrav)
if (open<close[1])
strategy.order("BUY", strategy.long)
if (open>close[1])
strategy.order("SELL", strategy.short)
strategy.close_all(when=strategy.openprofit>TakeProfit,alert_message="Close- TakeProfit")
strategy.exit("TrailStop",trail_points=TrailingStop,trail_offset=1,alert_message="Close- TrailStop")
Expand (18 lines)
Overview
When ATR is above that average it buys if the open is above the prior close and sells if the open is below it; when ATR is below the average it reverses those conditions. It sizes each order at 100 percent of equity. A trailing stop and a take-profit close based on open profit manage exits. Conditions use the live bar, so signals can change before the bar closes.
Seven-period ATR versus five-bar ATR average
Long and short orders from open versus prior close
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Trailing Stop (pips)
int
500
TrailingStop
Take Profit ($)
int
500
TakeProfit
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.
Alert BB + RSI [Alorse] is a multi-symbol mean-reversion strategy designed for cryptocurrency trading. It evaluates Bollinger Bands and the Relative Strength Index (RSI) across up to 20 user-defined ticker symbols simultaneously. The strategy enters long posit
This overlay strategy offers two selectable entry modes: a Bollinger squeeze on typical price and a simple moving-average cross. It filters trades by weekday, session, date range, and an optional news window, and can restrict direction or invert the side. Risk
This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades
STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions
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
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