Crypto Strategy Script

Bollinger Band Strategy!
  • 1st I inform ChatGPT about Bollinger Band
Bollinger Bands Explained with Formula And Strategy
Bollinger Bands is similar to price envelopes like ATR Bands. It is one of the most widely used indicators in technical analysis. Though it includes various rules, the application procedure is quite simple. Before stepping forward let’s have some word about the creator of Bollinger Bands. The famous financial analyst and a contributor to the field of technical analysis John Bollinger developed Bollinger Bands in 1980. The statistical chart helps to indicates the price and volatility of the stock by using the formulaic methods of John Bollinger.
Bollinger Bands FAQ
How are Bollinger bands calculated?

In the Bollinger Bands indicator, by default, the middle band is a 20-period simple moving average. Then lines are plotted at specific standard deviation levels from the middle band. The default standard deviation levels are 2. There is also a mid-band besides the upper and lower band. If the standard deviation is 2, then the upper band is at +2 SD and the lower band is at -2 SD and middle band at zero.
How does the Bollinger band work?

As we know Bollinger Bands consists of three lines, a centre line and two outer, overall looks like a band. There is a tendency of the price level to come toward the centerline. The outer lines generally work as a support and resistance level. When the market is less volatile, the outer lines come towards the centerline. The reverse happens in the case of a more volatile market. There is another important technique for bands. The price level is low at the lower band and high at the higher band. The middle line mainly works as a base of the other two lines. The rule of thumb is that 90% of the price action will happen inside the bands.
How do you use Bollinger Bands?

The indicator works very well and is widely used in creating bullish or bearish positions. In general, when the Bollinger Bands indicator touches the lower band it denotes that the price reaches the oversold zone and can bounce back and similarly when the price touches the upper band it denotes that the price has reached the overbought zone and can correct from here. Bollinger Band Bounce Trading
Bollinger Bands Indicator Formula

To compute the particular technique you need to know Standard Deviation Calculation (to measure volatility) first.

Upper Band= 20-period SMA + (20-day Standard Deviation of price x 2)
Middle Band = 20-period SMA (Simple Moving Average)
Lower Band = 20-period SMA – (20-day Standard Deviation of price x 2)
The above script is GLENMARK’s 1-hour price chart, taken from Zerodha Kite. However, it shows the price is at a higher level in the upper band and low in the lower bands. The large gap between the upper and lower bands indicates more volatility in the market.
Few Thumb Rules of Trading with Bollinger Bands Indicator

Sharp price changes tend to occur after the bands tighten greatly due to a decrease in volatility.
If prices move outside the bands, we can expect that the price will continue in that direction.
If bottoms and tops are made outside the bands, followed by bottoms and tops inside the bands, price reversal is imminent.
After a reversal, the trend originates at one band and tends to finish at another band. We can use these observations to project price targets.

How to set up Bollinger Bands Indicator on charts?

From the MarketWatch select the stock you are going to trade.
Open its chart
From the Studies section go to BollingerBbands and click on it.
The default parameters window of the indicator will open.
By default, this indicator uses 20-day simple moving average and 2 standard deviations which we can change as per our own requirement.
You can also choose what type of moving average you want to use as the middle band. By default, it is a simple moving average.
You can also choose the color of the 3 bands as well as the channel fill color.
John Bollinger’s 22 Rules For Using Bollinger Bands

The developer John Bollinger has set 22 rules to trade the Bollinger Bands Indicator. We are listing these rules below:
Rule 01-11

Bollinger bands define the price level. Low price at the lower band and high price at the upper.
The bands considered as a comparison tool between price and indicator action to point out the buy-sell decision.
Momentum, volume, sentiment, open interest, inter-market data, etc are the important factors in this indicator.
In the case of more than one indicator, the indicators should not be directly related to one another.
In order to recognize price patterns such as “M” tops, “W” bottoms, momentum shifts, etc, BB can be used.
Tags in the bands are not considered as signals, like a tag of the upper band is not sell signal while tag in the lower band is not a buy signal.
In a trending market, volatility comes often. Hence, the price walks up to the upper band while down the lower band.
If price closes outside the BB, it doesn’t mean the trend reversal is going to appear soon. It means the current trend will continue.
For MA (Moving Average) and SD (Standard Deviation) calculation, set the default parameters at 20 periods.
The centerline of BB should not be the best one for crossover.
With the increase in average, the number of SD needs to be increased. From 2 to 20 periods to 2.1 to 50 periods. On the other hand, when we shorten the average, we also need to reduce the number of SD. From 2 at 20 to 1.9 at 10 periods.

Rule 12-22

Classical BB is depended upon an SMA (Simple Moving Average). The reason is SMA is used to calculate SD (Standard Deviation).
EBB (Exponential Bollinger Bands) avoids sudden changes in the width of the bands. A large price change causes this. The EA generally use in both the center band and in the calculation of SD.
Based on the use of the standard deviation calculation, it makes no statistical assumptions.
By using an adaption of the formula for Stochastic, the position within the bands is calculated.
In order to identify divergence, pattern, trends, BB is an important tool.
By eliminating fixed thresholds in the process, indicators can be normalized.
To find out the width of BB, you need to follow BandWidth. By using the center band, the raw width is normalized.
In order to identify the changing trend, bandwidth plays a significant role.
In the equity, indices, foreign exchange, future, options, commodity and bonds, BB can be used.
We can use BB in any time frame of bars, 5 min, one hour, daily, weekly, etc.
It helps to identify the odd one and don’t provide continuous advice.

Bollinger Bands Trading Strategy

There are many strategies to trade the Bollinger Bands. In fact, I personally use Bollinger Bands or BB for 2-3 different usage. Sometimes we use price moving out of the bands to be the overbought or oversold situation. Sometimes we use the formation and closure of two or consecutive bars out of the bands to indicate a strong trend. Let me discuss two of my favorite Bollinger Bands trading strategies here.
Bollinger Bands Trading Strategy #1
Using Multiple Bands

In this strategy, all you will have to take into consideration for that is that:

Sixty-eight percent of a typical price action lies between plus or minus of the same standard deviations.
Ninety-five percent of a typical price action lies between plus or minus 2 standard deviations.
Ninety-nine percent of a regular price action lies between plus or minus 3 standard deviations.

The setup for multiple Bollinger Bands trading strategy

So depending on this fact we can use multiple Bollinger Bands to create a complete trading strategy. I have described below is the complete setup you will have to put to your DAILY or intraday chart:

There are 6 Bollinger Bands, and that looks like the following, you can attach them in your Zerodha Kite charts. This is a simple strategy and you can also use other charting platforms like Metastock or AmiBroker or any other broker’s platform.

1st BB (20,1.5) Lime
2nd BB (20,2) Yellow
3rd BB (20,2.5) Orange
4th BB (20,3) Purple
5th BB (20,3.5) Red
And 6th BB (20,4) Blue

Additionally, add an Average True Range or ATR indicator with a parameter of 20. We can use the ATR to calculate our stop loss for the trades taken.

This is a counter-trend trade. So if you are not familiar with counter-trend trading, you first need to learn it. But believe me, counter-trend trades are one of the lowest risk high reward tradings. Because if you can identify the end of a trend you can ride the next and opposite trend with a small risk and high reward. Now watch the image below once again.
BB with ATR

I hope you like rainbows! Essentially, you have 13 lines. Each one is resistance or support in this Bollinger Bands trading strategy. I think the best way to show you this method is to show you a lot of examples, so eat your heart out. SO, the example above, let me show you when I would have entered and why.
  • 2nd I told ChatGPT to create the strategy script
Based on above information, write a strategy, pinescript v5 code that can be use to mine Crypto Currency in Bollinger Bands. Enter a long when the price closes above the bolliger band, and short when the price closes below the lower bolliger band. Close the long when the short condition is met, and close the short when the long condition met. Make the code complex to be used on any Crypto strategies.
ChatGPT: Sure! Here's an example of a Pine Script v5 code strategy that uses Bollinger Bands to enter long and short positions in a cryptocurrency, and closes the positions when the opposite condition is met:

Code:
//@version=5
indicator(title="Bollinger Bands RSI", shorttitle="BBRSI", overlay=true)

// Input parameters
length = input(20, title="Length", minval=1)
mult = input(2.0, title="Multiplier", type=input.float)

// Calculate Bollinger Bands
basis = sma(close, length)
dev = mult * stdev(close, length)
upper = basis + dev
lower = basis - dev

// Calculate RSI
rsi_length = input(14, title="RSI Length", minval=1)
rsi = rsi(close, rsi_length)

// Entry and exit conditions
longCondition = crossover(close, upper) and crossover(rsi, 30)
shortCondition = crossunder(close, lower) and crossunder(rsi, 70)
exitCondition = crossover(close, lower) and crossover(rsi, 50)

// Enter long position
if (longCondition)
    strategy.entry("Buy", strategy.long)

// Enter short position
if (shortCondition)
    strategy.entry("Sell", strategy.short)

// Exit long or short position
if (exitCondition)
    strategy.close("Buy/Sell")

// Plot Bollinger Bands and RSI
p1 = plot(basis, color=color.blue, linewidth=2, title="Basis")
p2 = plot(upper, color=color.red, linewidth=2, title="Upper")
p3 = plot(lower, color=color.green, linewidth=2, title="Lower")
fill(p2, p3, color=color.gray, transp=90, title="Background")
hline(30, "Oversold", color=color.gray)
hline(70, "Overbought", color=color.gray)

Note: This code defines a Bollinger Bands RSI strategy where a long position is entered when the price closes above the upper Bollinger Band and the RSI is below 30, and a short position is entered when the price closes below the lower Bollinger Band and the RSI is above 70. The strategy closes the long or short position when the price crosses below the lower Bollinger Band and the RSI is above 50. You can adjust the input parameters to suit your desired strategy and cryptocurrency market conditions. This is a basic example and does not take into account other factors such as slippage, fees, or risk management, which should be considered when implementing a live trading strategy.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Chat
Help Users
  • No one is chatting at the moment.
    There are no messages in the chat. Be the first one to say Hi!
    Back
    Top