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.