DEMA and Bollinger Bands trading strategy
Strategy template description
This strategy template is a great starting point for a swing trader. It can be used on multiple timeframes but it works best on 4h. It is a good addition to manual trades if you want to automate part of the work. The template is set to work on a 4h timeframe by default.
The strategy has a few entry points determined by the moves of the Price above DEMA, DEMA crossovers, or Bollinger Bands getting broken. It comes with no Stop Loss or Take Profit safeties but it is highly recommended you tune it according to your risk profile and manage the risk for your portfolio size.
Step 1: Login and click on Create Strategy
Once you're logged in to the Vestinda app, click on Create Strategy from the left menu.
Step 2: Use a strategy Template
Click on Use a Strategy Template from the overlay.
Find the template in the list and click on the "Use this Template" button.
The template name inside the Vestinda app is Template - DEMA and Bollinger Bands. You can find it on the Templates page here: https://app.vestinda.com/templates
✅ Everyone has access to templates. You can use it to create trading strategies without coding skills and jump-start learning.
Step 3: Learn how the strategy works
Once you reach the template page, you have the entire strategy code ready to be used.
You can see the parameters for each indicator, but also modify the timeframe and all parameters.
Step 4: Backtest strategy or Demo Trade
Before any execution, backtesting the strategy is the best place to start from. You can do it on thousands of assets and many years of historical data.
This is helping you learn how to use these indicators, in what market conditions they work best, and what assets to trade using this strategy and indicators. Read more about Backtesting.
Demo Trading is another way to simulate the strategy without risking real money. This allows you to start using the strategy on the market moving forward on any available asset. Read more about Demo Trading.
Step 5: Results
With a simple strategy like this, we got an outcome that returned better than the benchmark.
Once you're confident enough, you can start Real Trading
Indicators in the strategy
DEMA (Double Exponential Moving Average)
DEMA (Double Exponential Moving Average) is a technical indicator used in financial markets analysis to track the price trend of an asset. It is a variation of the traditional Moving Average (MA) and calculates the moving average of an asset's price, with a greater weight given to recent data points.
Unlike a traditional MA, which calculates the average price over a specific period, DEMA calculates the average price over two different exponential moving averages. This is done by applying a smoothing factor to the original exponential moving average, which results in a smoother and more responsive indicator. The formula for DEMA is:
DEMA = 2 * EMA(n) - EMA(EMA(n))
Where:
- EMA(n) is the exponential moving average of the asset's price over n periods
- EMA(EMA(n)) is the exponential moving average of the EMA(n) over n periods
The DEMA technical indicator is commonly used in technical analysis to identify potential trends and reversals in the price of an asset. When the price of an asset is trading above its DEMA line, it is considered to be in an uptrend. Conversely, when the price is trading below the DEMA line, it is considered to be in a downtrend.
Traders and analysts also use DEMA crossovers, where the DEMA line crosses the price, as a signal for potential trend reversals. A bullish crossover occurs when the DEMA line crosses above the price, signaling a potential trend reversal from bearish to bullish. Conversely, a bearish crossover occurs when the DEMA line crosses below the price, signaling a potential trend reversal from bullish to bearish.
In summary, DEMA is a technical indicator that provides a smoothed moving average of an asset's price trend, and it is commonly used by traders and analysts to identify potential trends and reversals in the price of an asset.
Bollinger Bands
Bollinger Bands is a technical analysis tool developed by John Bollinger to measure the volatility of an asset's price relative to its moving average. Bollinger Bands consist of three lines plotted on a price chart: a simple moving average (SMA) in the middle, and two standard deviation (SD) lines above and below the SMA.
The standard deviation lines are plotted at a distance of ±(SD x multiplier) from the SMA. The most commonly used multiplier is 2, meaning that the upper and lower bands are set at 2 standard deviations above and below the SMA, respectively.
The formula for Bollinger Bands is:
Middle Band = n-period simple moving average Upper Band = Middle Band + (k x n-period standard deviation) Lower Band = Middle Band - (k x n-period standard deviation)
Where:
- n is the number of periods used for the SMA and standard deviation calculation
- k is the number of standard deviations from the SMA to plot the upper and lower bands.
Bollinger Bands are often used by traders to identify potential trading opportunities. When the price of an asset is trading near the upper band, it is considered overbought and a potential sell signal. Conversely, when the price is trading near the lower band, it is considered oversold and a potential buy signal. Traders also look for breakouts above or below the bands as a signal of a potential trend reversal.
Bollinger Bands are also used in conjunction with other technical indicators, such as the Relative Strength Index (RSI), to confirm trading signals. When a price reaches the upper band and the RSI is overbought, it may suggest that the asset is due for a correction or a trend reversal.
In summary, Bollinger Bands is a technical indicator used in financial market analysis to measuring the volatility of an asset's price relative to its moving average. It is commonly used by traders to identify potential trading opportunities and confirm trading signals from other technical indicators.
Congrats! 🎉
In just a few minutes you can build and automate a strategy with Vestinda.
The alternative is to write hundreds of lines of code in TradingView and connect that to an automation platform for the execution.
If you still want to tryout this strategy in TradingView also, here is the pinescript code:
//@version=5
strategy("Bollinger Bands Strategy", "Bollinger Bands Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_value = 0.1)
showT = input.bool(false, 'Plot TP/SL')
showBollingerBands = input.bool(true, "Plot Bollinger Bands")
length = input.int(188, minval=1, title='DEMA Length 1')
length2 = input.int(39, minval=1, title="DEMA Length 2")
src = input(close, title="Source")
e1 = ta.ema(src, length)
e2 = ta.ema(e1, length)
e3 = ta.ema(src, length2)
e4 = ta.ema(e3, length2)
dema = 2 * e1 - e2
dema2 = 2 * e3 - e4
plot(showBollingerBands ? dema : na, "DEMA LONG", color=#0DF3F3)
plot(showBollingerBands ? dema2 : na, "DEMA SHORT", color=#571996)
priceema = ta.ema(close,1)
length5 = input.int(41, minval=1, title='Bollinger Length')
mult = 2
basis = ta.sma(src, length5)
dev = ta.stdev(src, length5)
dev2 = mult * dev
upper1 = basis + dev
lower1 = basis - dev
upper2 = basis + dev2
lower2 = basis - dev2
//Style
colorBasis = src >= basis ? color.new(color=#0DF3F3, transp=100) : color.new(color=#571996, transp=100)
//Plots
plotBasis = plot(showBollingerBands ? basis : na, linewidth=2, color=colorBasis)
plotUpper1 = plot(showBollingerBands ? upper1 : na, color=color.new(color=#0DF3F3, transp=0), style=plot.style_circles)
plotUpper2 = plot(showBollingerBands ? upper2 : na, color=color.new(color=#0DF3F3, transp=0))
plotLower1 = plot(showBollingerBands ? lower1 : na, color=color.new(color=#571996, transp=0), style=plot.style_circles)
plotLower2 = plot(showBollingerBands ? lower2 : na, color=color.new(color=#571996, transp=0))
fill(plotBasis, plotUpper2, color=color.new(color=#0DF3F3, transp=80))
fill(plotUpper1, plotUpper2, color=color.new(color=#0DF3F3, transp=80))
fill(plotBasis, plotLower2, color=color.new(color=#571996, transp=80))
fill(plotLower1, plotLower2, color=color.new(color=#571996, transp=80))
import TradingView/Strategy/2 as css
//DATE RANGE FILTER {
strategy.risk.allow_entry_in(strategy.direction.long)
i_startTime = input.time(defval=timestamp('01 Jan 2021 00:00 +0000'), title='Start Time', group='Trade Filters')
i_endTime = input.time(defval=timestamp('01 Jan 2029 00:00 +0000'), title='End Time', group='Trade Filters')
inDateRange = time >= i_startTime and time <= i_endTime
//}
//SL TP PERCENT {
string sltp= "STOP/TAKE PROFIT"
usetpsl = input.bool(false, 'Use TP/SL', inline=sltp, group=sltp)
float percentStop = input.float(5, "Stop %", minval = 0.0, step = 0.1, group=sltp, inline='percent')
float percentTP = input.float(7, "Limit %", minval = 0.0, step = 0.1, group=sltp, inline='percent')
//}
float sl = css.ticksToStopLevel (css.percentToTicks (percentStop))
float tp = css.ticksToTpLevel (css.percentToTicks (percentTP))
exitPrice = strategy.closedtrades.exit_price(strategy.closedtrades-1)
bias = math.sign(strategy.position_size)
avg = strategy.position_avg_price
bool long = strategy.position_size > 0
bool enterLong = long and not long [1]
bool enter = enterLong
bool exit = strategy.position_size == 0 and not (strategy.position_size == 0)[1]
bool flat = strategy.position_size == 0
//STRATEGY PLOTS {
avgerage = plot(showT ? avg : na, "ENTRY", not enter ? color.new(color.white, 0) : na, 2, plot.style_linebr)
slp = plot(showT ? sl : na, "SL", not enter ? color.new(color.red, 60) : na, 4, plot.style_linebr)
tpp = plot(showT ? tp : na, "TP", not enter ? color.new(color.green, 60) : na, 4, plot.style_linebr)
fill(tpp, avgerage, color = color.new(color.green, 80), title='TP Background')
fill(avgerage, slp, color = color.new(color.red, 80) , title= 'SL Background')
//}
if usetpsl == true and long and src < upper1
css.exitPercent("exit long", percentStop, percentTP)
bool longCondition = ((priceema > dema and dema2>dema2[1]) or (dema2>dema and dema2>dema2[1]) or src>upper1)
bool shortCondition = ((priceema < dema and dema2<dema2[1]) or (dema2<dema and dema2<dema2[1]) or src<lower1)
// Strategy
if longCondition and inDateRange
strategy.entry("LONG", strategy.long)
if shortCondition and inDateRange
strategy.close("LONG", "Close Long")