Implementing TTM Squeeze Indicator with Color-Coded Histogram Bars in ProBuilder

19 May 2016
0 comment
0 attachment

This code snippet demonstrates how to implement a TTM Squeeze indicator in ProBuilder, which is used to identify periods of low volatility in a market. It includes logic to color-code histogram bars based on their relation to zero, helping to visually identify market transitions.

//PRC_TTM Squeeze for PRT v10.3| indicator - 27.04.2017 - Nicolas @ www.prorealcode.com
// lengthKC = 20
value = (Highest[lengthKC](high)+Lowest[lengthKC](low)+average[lengthKC](close))/3
val = linearregression[lengthKC](close-value)
BlueBar = 0
YellowBar = 0
Crossing = 0
if val>0 and valval[1] then //YELLOW
  YellowBar = 1
endif
Crossing = Val CROSSES OVER 0
Result = (BlueBar AND Not BlueBar[1]) OR (YellowBar AND Not YellowBar[1]) OR Crossing
SCREENER[Result] (Val AS "Histo")

Explanation of the code:

  • Variable Initialization: The ‘value’ variable is calculated as the average of the highest high, the lowest low, and the average close over a specified period (‘lengthKC’ set to 20).
  • Linear Regression Calculation: ‘val’ is computed as the linear regression of the difference between the close price and the ‘value’ over the same period.
  • Color-Coding Logic: Two variables, ‘BlueBar’ and ‘YellowBar’, are initialized to zero. These are set to 1 based on the direction of ‘val’ relative to its previous value (‘val[1]’). If ‘val’ is positive and decreasing, ‘BlueBar’ is set to 1 (indicating a potential upward momentum losing strength). Conversely, if ‘val’ is negative and increasing, ‘YellowBar’ is set to 1 (indicating a potential downward momentum losing strength).
  • Crossing Detection: The ‘Crossing’ variable checks if ‘val’ crosses over zero, which can be a significant market signal.
  • Result Calculation: The ‘Result’ variable combines these signals to determine if there has been a significant change in the indicator that should be highlighted on a screener. It checks for transitions from non-blue to blue, non-yellow to yellow, or any crossing of zero.
  • Screener Output: The ‘SCREENER’ function outputs the ‘Result’, displaying ‘val’ as “Histo” which represents the histogram on the chart.

This code is a practical example of how to implement and visually represent the TTM Squeeze indicator, which can be useful for traders looking to understand market volatility dynamics.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/ttm-squeeze-screener-help/#post-99404

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...