Strategy · Pine Script v4 · On the chart

ADX + BB %B + AO + EMA

by hasnocool

This strategy plots multiple exponential moving averages and a linear regression squeeze channel directly on the price chart.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code103
Settings17inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 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

103 lines of Pine Script v4 from ADX + BB -B + AO + EMA [Luca Massuda].pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

ADX + BB -B + AO + EMA [Luca Massuda].pine
//@version=4
//ADX + BB %B + AO + EMA
strategy("ADX + BB %B + AO + EMA", overlay=true, initial_capital=10000)
take_profit_perc = input(title="Take Profit %", type=input.integer, defval=10, minval=1, maxval=100)
stop_loss_perc = input(title="Stop Loss %", type=input.integer, defval=5, minval=1, maxval=100)
bb_overbought = input(title="BB %B Overbought", type=input.integer, defval=75, minval=1, maxval=100)
bb_oversold = input(title="BB %B Oversold", type=input.integer, defval=25, minval=1, maxval=100)
ao_value = input(title="Awesome Oscillator", type=input.integer, defval=2)
adx_value = input(title="ADX", type=input.integer, defval=15)
startDate = input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31)
startMonth = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12)
startYear = input(title="Start Year", type=input.integer, defval=2018, minval=2008, maxval=2200)
inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))
ema5 = ema(close, 5)
ema21 = ema(close, 21)
ema50 = ema(close, 50)
ema200 = ema(close, 200)
//BB %B
length = input(20, minval=1)
src = input(close, title="Source")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
bbr = (src - lower)/(upper - lower)
//Awesome Oscillator
ao = sma(hl2,5) - sma(hl2,34)
// ADX
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
dirmov(len) =>
    up = change(high)
    down = -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 = rma(tr, len)
    plus = fixnan(100 * rma(plusDM, len) / truerange)
    minus = fixnan(100 * rma(minusDM, len) / truerange)
    [plus, minus]
adx(dilen, adxlen) =>
    [plus, minus] = dirmov(dilen)
    sum = plus + minus
    adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
long_strategy = ema5>ema21 and ema50>ema200 and bbr>(bb_overbought/100) and ao>ao_value and sig>adx_value
short_strategy = ema5<ema21 and ema50<ema200 and bbr<(bb_oversold/100) and ao<-ao_value and sig>adx_value
plot(ema5, color=color.blue)
plot(ema21, color=color.aqua)
plot(ema50, color=color.purple)
plot(ema200, color=color.red)
bgcolor(color=long_strategy ? color.green : na, transp=80)
bgcolor(color=short_strategy ? color.purple : na, transp=80)
    
if inDateRange and long_strategy
    strategy.entry("long", strategy.long, 100)
    strategy.exit("exit", "long", stop=strategy.position_avg_price*(100-stop_loss_perc)/100, limit=strategy.position_avg_price*(100+take_profit_perc)/100)
if inDateRange and short_strategy
    strategy.entry("short", strategy.short, 100)
    strategy.exit("exit", "short", stop=strategy.position_avg_price*(100+stop_loss_perc)/100, limit=strategy.position_avg_price*(100-take_profit_perc)/100)
    
// Squeeze
sqsrc = close
sqlength = input(34)
sqmedian=0
sqmult=input(2.5)
sqoffset = input(20)
tr_custom() => 
    x1=high-low
    x2=abs(high-close[1])
    x3=abs(low-close[1])
    max(x1, max(x2,x3))
    
atr_custom(x,y) => 
    sma(x,y)
    
sqdev = (sqmult * stdev(sqsrc, sqlength))
sqbasis=linreg(sqsrc, sqlength, sqmedian)
ul = (sqbasis + sqdev)
ll = (sqbasis - sqdev)
tr_v = tr_custom()
acustom=(2*atr_custom(tr_v, sqlength))
uls=sqbasis+acustom
lls=sqbasis-acustom
// Plot stdev channel
plot(sqbasis, linewidth=1, color=color.navy, style=plot.style_line, linewidth=1, title="sqmedian")
lb=plot(ul, color=color.red, linewidth=1, title="BB+", style=plot.style_linebr)
tb=plot(ll, color=color.green, linewidth=1, title="BB-", style=plot.style_linebr)
fill(tb,lb, color.silver, title="Region fill")
// Plot ATR channel
plot(sqbasis, linewidth=2, color=color.navy, style=plot.style_line, linewidth=2, title="sqmedian")
ls=plot(uls, color=color.red, linewidth=1, title="Starc+", style=plot.style_circles)
ts=plot(lls, color=color.green, linewidth=1, title="Star-", style=plot.style_circles)
fill(ts,tb, color.green, title="Region fill")
fill(ls,lb, color.red, title="Region fill")
// Mark SQZ
plot_offs_high=2
plot_offs_low=2 
sqz_f=(uls>ul) and (lls<ll)
b_color=sqz_f ? color.teal : na
plot(sqz_f ? lls-plot_offs_low : na, color=b_color, style=plot.style_cross, linewidth=2)
plot(sqz_f ? uls+plot_offs_high : na, color=b_color, style=plot.style_cross, linewidth=2)
Expand (115 lines)

Overview

ADX + BB %B + AO + EMA executes 100-unit long and short trades by combining four EMA trend alignments, Bollinger Bands %B extremes, Awesome Oscillator momentum thresholds, and minimum ADX trend strength filters. Positions exit using percentage-based stop loss and take profit limits relative to the average entry price. Configurable settings adjust indicator periods, signal thresholds, backtest start dates, and exit percentages. It uses a fixed contract size without dynamic position sizing.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

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

Markets

Crypto

Timeframes

M1-M5

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.

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
Take Profit %int10take_profit_perc
Stop Loss %int5stop_loss_perc
BB %B Overboughtint75bb_overbought
BB %B Oversoldint25bb_oversold
Awesome Oscillatorint2ao_value
ADXint15adx_value
Start Dateint1startDate
Start Monthint1startMonth
Start Yearint2018startYear
lengthint20length
Sourcesourceclosesrc
StdDevfloat2.0mult
Show all 17 settings
SettingTypeDefaultVariable
ADX Smoothingint14adxlen
DI Lengthint14dilen
sqlengthint34sqlength
sqmultfloat2.5sqmult
sqoffsetint20sqoffset
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

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