Implementing a Bollinger Band-Based Force Indicator

10 Jun 2015
0 comment
0 attachment

This code snippet demonstrates how to create a “Force” indicator using Bollinger Bands in the ProBuilder programming language. The indicator assigns a force value based on the position of the close price relative to multiple levels of Bollinger Bands.


// CLOSE > BOLLUP
i1= close > Average[t1](close) + 1*std[t1](close)
i2= close > Average[t1](close) + 1.5*std[t1](close)
i3= close > Average[t1](close) + 2*std[t1](close)
i4= close > Average[t1](close) + 2.5*std[t1](close)
i5= close > Average[t1](close) + 3*std[t1](close)

// CLOSE < BOLLDOWN
y1= close < Average[t1](close) - 1*std[t1](close)
y2= close < Average[t1](close) - 1.5*std[t1](close)
y3= close < Average[t1](close) - 2*std[t1](close)
y4= close < Average[t1](close) - 2.5*std[t1](close)
y5= close < Average[t1](close) - 3*std[t1](close)

if i1 and i2 and i3 and i4 and i5 then 
force = 5 
endif
if i1 and i2 and i3 and i4 and (not i5) then 
force = 4 
endif
if i1 and i2 and i3 and (not i4 and not i5) then 
force = 3 
endif
if i1 and i2 and (not i3 and not i4 and not i5) then 
force = 2 
endif
if i1 and (not i2 and not i3 and not i4 and not i5) then 
force = 1 
endif
if (not i1 and not i2 and not i3 and not i3 and not i4 and not i5 and not y1 and not y2 and not y3 and not y4 and not y5) then 
force = 0 
endif
if y1 and y2 and y3 and y4 and y5 then 
force =-5 
endif
if y1 and y2 and y3 and y4 and (not y5) then 
force =-4 
endif
if y1 and y2 and y3 and (not y5 and not y4) then 
force =-3 
endif
if y1 and y2 and (not y5 and not y4 and not y3) then 
force =-2 
endif
if y1 and (not y5 and not y4 and not y3 and not y2) then 
force =-1 
endif

return force
//Set T1 to 20 or whatever u want.

This code calculates a “force” value based on the relationship between the closing price and multiple Bollinger Bands thresholds:

  • Variables i1 to i5 are defined to check if the close price is above increasing multiples of the standard deviation above the moving average.
  • Variables y1 to y5 check if the close price is below decreasing multiples of the standard deviation below the moving average.
  • The force variable is then assigned a value from -5 to 5 based on which conditions are met. Positive values indicate the close is above the upper Bollinger Bands, and negative values indicate it is below the lower Bollinger Bands.
  • The return statement outputs the force value, which can be used as an indicator of the strength of the current price movement relative to the volatility represented by the Bollinger Bands.

This indicator can be useful for traders looking to gauge the strength of price movements or as part of a larger trading strategy.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/higher-timeframes-bollinger-filter/#post-93803

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
jebus89 Master
Code artist, my biography is a blank page waiting to be scripted. Imagine a bio so awesome it hasn't been coded yet.
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...