Strategy · Pine Script v4 · On the chart

Bollinger Band with Fib Golden Ratio (0.618)

by hasnocool· code credited to mohanee

This strategy combines Volume Weighted Moving Average (VWMA) Bollinger Bands with 200-period and 50-period Exponential Moving Averages (EMAs).

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code31
Settings4inputs
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

31 lines of Pine Script v4 from Bollinger Band with Fib Golden Ratio (0.618).pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Bollinger Band with Fib Golden Ratio (0.618).pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mohanee
//@version=4
strategy(title="Bollinger Band with Fib Golden Ratio (0.618)",  shorttitle="Bollinger Band with Fib Golden Ratio" , overlay=true, pyramiding=1,     default_qty_type=strategy.percent_of_equity,  default_qty_value=20, initial_capital=10000, currency=currency.USD)  
length = input(50,title="BB Length" , minval=1)
src1 = input(hlc3, title="Source")
//mult1 = input(1.33, minval=0.001, maxval=50)
mult = input(1.5,title="multplier", minval=0.001, maxval=50)
stopLoss=input(5,title="Stop Loss",minval=1)
basis = vwma(src1, length)
dev = mult * stdev(src1, length)
//dev3 = mult3 * stdev(src, length)
upper_618= basis + (0.618*dev)
lower_618= basis - (0.618*dev)
//lower_618_dev3= basis - (0.618*dev3)
plot_upper618= plot(upper_618, color=color.purple, linewidth=2, title="0.618")
plot(basis, color=color.purple,style=plot.style_circles,  linewidth=2)
plot_lower618= plot(lower_618, color=color.purple, linewidth=2, title="0.618 entry")
//plot_lower618_dev3= plot(lower_618_dev3, color=color.red, linewidth=1, title="0.618 stop")
//plot_lower618= plot(lower_618, color=color.purple, linewidth=1, title="0.618 entry")
ema200=ema(close,200)
ema50=ema(close,50)
plot (ema200, title="ema200", color=color.orange, linewidth=2)
plot (ema50, title="ema50", color=color.blue , linewidth=2)
longCondition= ema50 > ema200
strategy.entry(id="BB_Fib618", long=true, when = longCondition and ( close < lower_618  or  low <= lower_618)  )
strategy.close(id="BB_Fib618",  comment="points="+tostring(close - strategy.position_avg_price,  "###.##") , when = strategy.position_size >= 1  and crossover(close,upper_618 )) 
//stoploss exit
stopLossVal = strategy.position_size>=1 ?  strategy.position_avg_price * ( 1 - (stopLoss/100) ) : 0.00
strategy.close(id="BB_Fib618", comment="SL="+tostring(close - strategy.position_avg_price,  "###.##"), when=abs(strategy.position_size)>=1 and close < stopLossVal ) //and close > strategy.position_avg_price )
Expand (51 lines)

Overview

Bollinger Band with Fib Golden Ratio (0.618) identifies long trade opportunities when the 50 EMA is above the 200 EMA and price falls to or below the lower Fibonacci 0.618 Bollinger Band. Positions are exited when price crosses above the upper Fibonacci 0.618 band or hits a percentage-based stop loss. Plotted directly on the price chart, user settings control the BB length, multiplier, source, and stop loss percentage.

Details

Published by

hasnocool on GitHub

Code credit

mohanee, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Trend, Volatility & bands, Moving averages, Mean reversion

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
BB Lengthint50length
Sourcesourcehlc3src1
multplierfloat1.5mult
Stop Lossint5stopLoss
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

This mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner PRO [Alorse]

Bollinger Bands Strategy

by cklose2000
105 stars

This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po

Strategy v5 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Strategy
5 stars

This strategy identifies shorting opportunities by calculating Fear and Greed zones based on price extremums relative to moving averages and standard deviation bands. It measures price deviation from recent highs or lows to detect extreme market conditions and

Strategy v4 Volatility & bandsMean reversion
Updated 3 years ago · Apache-2.0 GitHub repository of Fear + Greed Reversal Short Strategy
257 stars

This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades

Strategy v6 Moving averagesVolatility & bands
Updated 6 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint

STRG-BBForce

by harryguiacorn
219 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce

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