Detecting Flat Lines in Kijun and Senkou Span B Using ProBuilder

29 May 2016
0 comment
0 attachment

This code snippet demonstrates how to detect flat lines in the Kijun and Senkou Span B indicators, which are part of the Ichimoku Kinko Hyo system, using the ProBuilder programming language. The code identifies periods where these lines remain relatively unchanged, indicating a flat or stable market condition, and highlights these lines on a chart.


flatPeriod = 5
maxPercent = 0.0001 //percent difference
// ----------
maxPercent = maxPercent / 100

Kijun = (highest[26](high)+lowest[26](low))/2
isKijunFlat = summation[flatPeriod](kijun=kijun[1] or (kijun/kijun[1]<=1+maxPercent and kijun/kijun[1]>=1-maxPercent))=flatPeriod
if isKijunFlat then
  drawhline(kijun) coloured(200,200,0)
endif

SSpanB = (highest[52](high)+lowest[52](low))/2
isSSpanBFlat = summation[flatPeriod](sspanb=sspanb[1] or (sspanb/sspanb[1]<=1+maxPercent and sspanb/sspanb[1]>=1-maxPercent))=flatPeriod
if isSSpanBFlat then
  drawhline(sspanb) coloured(0,200,200)
endif

return

Explanation of the Code:

  • Initialization: The variables flatPeriod and maxPercent are set to define the number of periods to check for flatness and the maximum percentage difference between values to still consider the line flat, respectively.
  • Calculation of Kijun and SSpanB: The Kijun and Senkou Span B (SSpanB) values are calculated using typical Ichimoku formulas, which involve the highest and lowest prices over specific periods.
  • Detection of Flatness: The summation function is used to count how many times in the last flatPeriod periods the value of Kijun or SSpanB has changed within the specified maxPercent. If the count equals flatPeriod, the line is considered flat.
  • Conditional Drawing: If a flat line is detected, a horizontal line (drawhline) is drawn at the level of Kijun or SSpanB. The color of the line is set to yellow-orange for Kijun and sky blue for SSpanB, making them visually distinct.

This code is useful for traders or analysts who use technical analysis to understand market stability and potential breakout points.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/code-lent/#post-145632

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.
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Search Snippets

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

Snippets Categories

global
33
indicator
132
strategy
171

Recent Snippets

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) [...]
Calculating Break-Even Points in ProBuilder
strategy
This ProBuilder code snippet demonstrates how to calculate the break-even point for a trading position. The break-even [...]
Implementing Time and Day Restrictions in Trading Algorithms
strategy
This code snippet demonstrates how to set restrictions on trading activities based on specific days of the week and [...]
Implementing Partial Position Closure Based on Price Retracement in ProBuilder
strategy
This code snippet demonstrates how to partially close a trading position when the price retraces to a certain level in [...]
Logo Logo
Loading...