0% found this document useful (0 votes)
7 views1 page

Bollinger Bands Trendbars Strategy

This document outlines a trading strategy using Bollinger Bands in Pine Script version 5. It includes calculations for upper, middle, and lower bands, as well as conditions for entering and exiting trades based on price movements relative to these bands. The strategy visually plots the Bollinger Bands on the chart with color coding to indicate bullish or bearish trends.

Uploaded by

Yacine Amalou
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Bollinger Bands Trendbars Strategy

This document outlines a trading strategy using Bollinger Bands in Pine Script version 5. It includes calculations for upper, middle, and lower bands, as well as conditions for entering and exiting trades based on price movements relative to these bands. The strategy visually plots the Bollinger Bands on the chart with color coding to indicate bullish or bearish trends.

Uploaded by

Yacine Amalou
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//@version=5

strategy("Bollinger Band Trendbars Strategy", overlay=true)

// Inputs for Bollinger Bands


length = [Link](20, minval=1, title="Length")
mult = [Link](2.0, minval=0.1, title="Standard Deviation Multiplier")

// Bollinger Bands Calculation


basis = [Link](close, length)
deviation = [Link](close, length)
upper_band = basis + mult * deviation
lower_band = basis - mult * deviation

// Trend Logic for Upper Band


isUpperBullish = close > upper_band
isUpperBearish = close < upper_band
upperColor = isUpperBullish ? [Link] : isUpperBearish ? [Link] : [Link]

// Trend Logic for Middle Band


isMiddleBullish = close > basis
isMiddleBearish = close < basis
middleColor = isMiddleBullish ? [Link] : isMiddleBearish ? [Link] :
[Link]

// Trend Logic for Lower Band


isLowerBullish = close > lower_band
isLowerBearish = close < lower_band
lowerColor = isLowerBullish ? [Link] : isLowerBearish ? [Link] : [Link]

// Entry Conditions
longCondition = (middleColor == [Link] or upperColor == [Link])
shortCondition = (middleColor == [Link] or lowerColor == [Link])

// Exit Conditions
exitCondition = (strategy.position_size > 0 and shortCondition) or
(strategy.position_size < 0 and longCondition) or
(upperColor == [Link] or lowerColor == [Link])

// Execute Trades
if longCondition
[Link]("Long", [Link])
if shortCondition
[Link]("Short", [Link])
if exitCondition
[Link]("Long")
[Link]("Short")

// Plot Bollinger Bands


plot(upper_band, color=upperColor, title="Upper Band", linewidth=2)
plot(basis, color=middleColor, title="Middle Band", linewidth=2)
plot(lower_band, color=lowerColor, title="Lower Band", linewidth=2)

You might also like