Identifying a Ranging Market with Multiple Technical Indicators

15 Jul 2020
0 comment
0 attachment

This code snippet demonstrates how to identify a ranging market using multiple technical indicators in ProBuilder language. The indicators used include Bollinger Bands, Keltner Channels, Moving Averages, and the Average Directional Index (ADX). The code checks for conditions such as the containment of Bollinger Bands within Keltner Channels and the ADX value being below a certain threshold, which are common techniques to determine market range.


// Define the period and the multiplier for the indicators
n = 20
multiplier = 2

// Calculate Bollinger Bands
average = average[20](close)
deviation = std[20](close)
upperBB = average + multiplier * deviation
lowerBB = average - multiplier * deviation

// Calculate Keltner Channels
atr = average[10](trueRange)
upperKC = average + multiplier * atr
lowerKC = average - multiplier * atr

// Calculate ADX
adxValue = adx[14]

// Check if Bollinger Bands are within Keltner Channels
bbInsideKC = (upperBB < upperKC) and (lowerBB > lowerKC)

// Check if ADX is below 25
lowAdx = (adxValue < 25)

// Output if the market is ranging
rangingMarket = bbInsideKC and lowAdx

Explanation of the Code:

  • Lines 2-3: Set the number of periods (n) and the multiplier used in the calculation of the Bollinger Bands and Keltner Channels.
  • Lines 6-8: Calculate the Bollinger Bands. The middle band is the simple moving average of the last 20 closes. The upper and lower bands are calculated by adding and subtracting the product of the standard deviation and the multiplier from the middle band.
  • Lines 11-13: Calculate the Keltner Channels. These are similar to Bollinger Bands but use the Average True Range (ATR) instead of standard deviation to set the channel width.
  • Line 16: Calculate the Average Directional Index (ADX) which measures the strength of a trend. A low ADX value typically indicates a lack of trend (ranging market).
  • Line 19: Determine if the Bollinger Bands are entirely within the Keltner Channels, a common indication of a ranging market.
  • Line 22: Check if the ADX value is below 25, reinforcing the indication of a ranging market.
  • Line 25: Combine the checks into a single boolean (rangingMarket) that indicates if the market is ranging based on the criteria set.

This code snippet is a practical example of how to combine different technical indicators to assess market conditions, specifically to identify when a market is ranging.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/flat-marked-code/#post-106659

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.
robertogozzi Master
Roberto https://www.ots-onlinetradingsoftware.com
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...