Strategy · Pine Script v5 · On the chart

EMA+BB+ADX+AO

by mr-s8

This strategy plots four EMAs (5, 21, 50 and 200), a Bollinger Band ratio, Awesome Oscillator and ADX on the price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code96
Settings13inputs
LicenceGPL-2.0
Last update2 years ago10 Mar 2024

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

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.

Details

Published by

mr-s8 on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Moving averages, Volatility & bands, Oscillators & momentum, Trend

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
Take-Profitfloat1.0takeprofit
Stop-Lossfloat2.0stoploss
EMA fastestint5ema5_len
EMA fastint21ema21_len
EMA slowint50ema50_len
EMA slowestint200ema200_len
BB Oversoldfloat0.25bboversold
BB Overbroughtfloat0.75bboverbrought
A0 Below for Shortsfloat-2.00aooversold
AO Above for longsfloat2.00aooverbrought
ADX LEVEL TO STAY ABOVEint15adxvalue
(ADX Smoothing)int14adxlen
Show all 13 settings
SettingTypeDefaultVariable
(DI Length)int14dilen
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

106 stars

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

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 3 x EMA + Stochastic RSI + ATR

Momentum Rider DAILY FINAL

by greenpeas007
58 stars

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

Strategy v6 TrendOscillators & momentum Repaints
Updated 4 months ago · Custom licence GitHub repository of Momentum Rider DAILY FINAL

CombinedBinHAndClucV6

by viktors1982
36 stars

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

Strategy v4 Volatility & bandsOscillators & momentum Repaints
Updated 2 years ago · None stated GitHub repository of CombinedBinHAndClucV6

BB Swing

by benso87
24 stars

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

Strategy v5 Volatility & bandsOscillators & momentum
Updated 4 years ago · MPL-2.0 GitHub repository of BB Swing

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

Strategy v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ruckard ABCBitcoin TradingLatino A010

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