Implementing and Visualizing Support Lines in ProBuilder

18 Apr 2024
0 comment
0 attachment

This ProBuilder script is designed to identify and draw support lines on a price chart until they are broken by subsequent price action. The code determines potential support levels based on specific candlestick patterns and then visually represents these levels with lines until the price breaks through them.

defparam drawonlastbaronly=true

REM Measure the length of real body, lower shadow, and upper shadow for white and black candles
IF OPEN < CLOSE THEN REM white candle realbody = CLOSE – OPEN lowershadow = OPEN – LOW uppershadow = HIGH – CLOSE ELSIF OPEN > CLOSE THEN REM black candle
realbody = OPEN – CLOSE
lowershadow = CLOSE – LOW
uppershadow = HIGH – OPEN
ENDIF

REM Store support
IF ((lowershadow / realbody) >= 2 AND (realbody/uppershadow) >= 2) AND NOT(OPEN = CLOSE) THEN
$support[i]=low
$bar[i]=barindex
i=i+1
ENDIF

REM check support line
if islastbarupdate and i>1 then
for j = 0 to i-1
checklow = $support[j]
bars = max(1,barindex-$bar[j])
check=0
for z = 1 to bars
if low[z] check=1
break
endif
next
if check=0 then
drawray($bar[j],$support[j],barindex,$support[j]) coloured(0,255,0)
endif
next
endif

RETURN

Explanation of the code:

  • Initial Setup: The script starts by setting drawonlastbaronly to true, ensuring that drawing operations are performed only on the last available bar to optimize performance.
  • Candlestick Analysis: It measures the real body, lower shadow, and upper shadow of candles. Different calculations are performed based on whether the candle is bullish (white) or bearish (black).
  • Support Identification: The script identifies potential support levels by checking if the lower shadow is at least twice the length of the real body and the real body is at least twice the length of the upper shadow, excluding doji candles (where open equals close).
  • Storing Support Data: When a potential support is identified, its price level and the corresponding bar index are stored in arrays $support and $bar, respectively.
  • Support Line Drawing: On the last update of the bar, the script checks each stored support level to see if it has been broken by any subsequent low prices. If not broken, a green ray (line) is drawn from the bar where the support was identified to the current bar.

This script is useful for traders and analysts who use technical analysis to visually identify and track support levels on price charts.

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