Bollinger Bands EMA 9
This code is written in Pine Script, which is used for customizing charts on the TradingView platform. It seems to define a scalping strategy using Bollinger Bands and a 9 period EMA (Exponential Moving Average). Let…
This code is written in Pine Script, which is used for customizing charts on the TradingView platform. It seems to define a scalping strategy using Bollinger Bands and a 9 period EMA (Exponential Moving Average). Let me break down some crucial parts for you.
EMA calculation and plotting:
ema9 = ta.ema(close, 9) plot(ema9)
This produces a line chart of the 9-day EMA.
- Bollinger Bands calculation and strategy definition:
strategy("Bollinger Bands + EMA 9", overlay=true) length = input.int(20, minval=1) src = input(close, title="Source") mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev") basis = ta.sma(src, length) dev = mult * ta.stdev(src, length) upper = basis + dev lower = basis - dev offset = input.int(0, "Offset", minval = -500, maxval = 500) p1 = plot(upper, "Upper", color=#2962FF, offset = offset) p2 = plot(lower, "Lower", color=#2962FF, offset = offset) fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))
It calculates the upper and lower Bollinger Bands, plots them and fills the area in-between.
Defines when to enter and exit a long trade:
Exit = close >= ema9 Long = (close[1] <lower) strategy.entry("Long",strategy.long, 1000, when =Long) strategy.close("Long", when=add)
This part enters a LONG position when the closing price breaches the lower band and exits when the closing price is equal to or above the 9-day EMA.
Please note that you need to adjust this script according to your personal risk tolerance and preferences. Also, its performance in live trading environments may vary. Always backtest any trading strategies before you proceed to real trading.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | 20 | length |
| v_input_1_close | 0 | Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
| v_input_float_1 | 2 | StdDev |
| v_input_int_2 | false | Offset |
Source Pine Script
/*backtest
start: 2022-09-01 00:00:00
end: 2023-09-07 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © D499
//@version=5
//EMA
ema9 = ta.ema(close, 9)
plot(ema9)
//BB
strategy("Bollinger Bands + EMA 9", overlay=true)
length = input.int(20, minval=1)
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500)
p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))
Exit = close >= ema9
Long = (close[1] < lower)
strategy.entry("Long",strategy.long, 1, when = Long)
strategy.close("Long", when = Exit)Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-08. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Bollinger-Bands-EMA-9.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- 20Bitcoin and Gold 5 Minute Scalping Strategy 20Pine Script · Scalping · 1h
- Bollinger Awesome Alert R1Pine Script · Scalping · 1h
- Joanne on Crypto Dual Moving Average with MACD Scalping StrategyPine Script · Scalping · 1h
- Vitalik ScalpePine Script · Scalping
- Bollinger Bands Heiken Ashi Short term Trading StrategyPine Script · Scalping · 1d
- Scalping EMA ADX RSI with Buy SellPine Script · Scalping · 5m