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
96 lines of Pine Script v5 from crypto/ema-bb-adx-ao/strat.pine, published under GPL-2.0. Keep the author's credit and licence lines when you reuse it.
strat.pine
//@version=5
//https://github.com/mr-s8
strategy("ema+bb%b+adx+ao", overlay=true, initial_capital=1000, default_qty_value=10, default_qty_type= strategy.percent_of_equity)
//inputs
takeprofit=input.float(defval = 1.0 , title = "Take-Profit", minval = 0.1 , maxval = 4 , step = 0.1 )/100
stoploss=input.float(defval = 2.0 , title = "Stop-Loss", minval = 0.1 , maxval = 4 , step = 0.1 )/100
ema5_len=input(5,title="EMA fastest")
ema21_len=input(21,title="EMA fast")
ema50_len=input(50,title="EMA slow")
ema200_len=input(200,title="EMA slowest")
bboversold=input(0.25, title="BB Oversold")
bboverbrought = input(0.75, title="BB Overbrought")
aooversold=input(-2.00,title="A0 Below for Shorts")
aooverbrought=input(2.00,title="AO Above for longs")
adxvalue=input(15,title="ADX LEVEL TO STAY ABOVE")
//not that important:
adxlen = input(14, title="(ADX Smoothing)")
dilen = input(14, title="(DI Length)")
//Indicator code
//4 Ema's
ema5=ta.ema(close,ema5_len)
ema21=ta.ema(close,ema21_len)
ema50=ta.ema(close,ema50_len)
ema200=ta.ema(close,ema200_len)
// BB (code from tradingview)
basis=ta.sma(close,20)
dev = 2 * ta.stdev(close,20)
upper=basis+dev
Lower=basis-dev
bbr=(close - Lower)/(upper - Lower)
// AO (code from tradingview)
ao = ta.sma(hl2,5) - ta.sma(hl2,34)
// ADX (code from tradingview)
dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
// End of ADX and DI Code
//End of Indicators
//Plotting
plot(ema5,title="EMA5",color=color.blue)
plot(ema21,title="EMA21",color=color.purple)
plot(ema50,title="EMA50",color=color.yellow)
plot(ema200,title="EMA200",color=color.white)
plot(ao, title="ao value")
plot(sig, color=color.red, title="ADX")
plot(bbr,title="BB Value", color=color.green, linewidth=2, style=plot.style_line)
//logic
aolong=ao > aooverbrought
aoshort=ao < aooversold
bblong = bbr > bboverbrought
bbshort = bbr < bboversold
ema_long = ema5>ema21 and ema50>ema200
ema_short = ema5<ema21 and ema50<ema200
adxlongshort=sig >adxvalue
notintrade=strategy.position_size<=0
//execution
if ema_long and bblong and aolong and adxlongshort and notintrade
strategy.entry("long", strategy.long)
strategy.exit(id="tpsllong", from_entry="long", limit = strategy.position_avg_price*(1+takeprofit), stop =strategy.position_avg_price*(1-stoploss))
if ema_short and bbshort and aoshort and adxlongshort and notintrade
strategy.entry("short", strategy.short)
strategy.exit("exit", "short", limit = strategy.position_avg_price*(1-takeprofit), stop =strategy.position_avg_price*(1+stoploss))
Overview
EMA+BB+ADX+AO generates long entries when EMA alignment, BB expansion, AO strength and ADX trend strength align, then exits using a percentage-based take profit and stop loss relative to the average entry price. Short signals follow the opposite conditions. Main settings adjust EMA lengths, BB overbought/oversold levels, AO thresholds, ADX filter value and smoothing parameters. It draws directly on the price chart and limits positions to one at a time.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Take-Profit
float
1.0
takeprofit
Stop-Loss
float
2.0
stoploss
EMA fastest
int
5
ema5_len
EMA fast
int
21
ema21_len
EMA slow
int
50
ema50_len
EMA slowest
int
200
ema200_len
BB Oversold
float
0.25
bboversold
BB Overbrought
float
0.75
bboverbrought
A0 Below for Shorts
float
-2.00
aooversold
AO Above for longs
float
2.00
aooverbrought
ADX LEVEL TO STAY ABOVE
int
15
adxvalue
(ADX Smoothing)
int
14
adxlen
Show all 13 settings
Setting
Type
Default
Variable
(DI Length)
int
14
dilen
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.
This strategy overlays a trend moving average and Supertrend bands directly on the price chart while calculating Stochastic RSI values internally. Long positions trigger when price exceeds the moving average, Supertrend signals bullish momentum, and the StochR
This trading strategy combines three Exponential Moving Averages (8, 14, and 50 periods by default) with Stochastic RSI and Average True Range (ATR). It enters a long position when EMA 1 is above EMA 2, EMA 2 is above EMA 3, and the Stochastic RSI %K line cros
This strategy combines exponential moving averages (EMA 9, 21, 50), RSI, MACD, and Supertrend indicators to enter long positions. It triggers trades using six dynamic setups based on momentum breakouts, EMA crossovers, and pullbacks. Position sizing is compute
CombinedBinHAndClucV6 is a trading strategy based on the popular BinHV45 and ClucMay72018 algorithms. It calculates dual Bollinger Bands, Exponential Moving Averages, Relative Strength Index, Average True Range, and volume metrics across primary and one-hour h
This strategy calculates Bollinger Bands, a configurable moving average slope, Stochastic RSI, ATR, and ADX directly on the price chart. It evaluates trend bias and momentum conditions to generate long and short swing entries using percent-of-equity sizing. Th
This strategy trades long and short on the price chart using a multi-timeframe TradingLatino setup. It requires EMA 10 to cross or sit above or below EMA 55 on the one-hour, four-hour, and daily charts, together with a positive ADX slope, a directional monitor