Implementing Swing High and Swing Low Indicators in ProBuilder

21 Jan 2021
0 comment
0 attachment

This code snippet demonstrates how to identify and visually represent swing highs and swing lows in a trading chart using the ProBuilder programming language. These indicators are useful for traders to understand potential reversal points in the market.


xPeriod = 20
If High[1] = Highest[xPeriod](High) and High[2] < High[1] and High < High[1] then
    SwingHigh = High[1]
    DrawArrowUP(BarIndex-1,High[1]+10) Coloured(0,255,0)
    DrawText("#SwingHigh#", BarIndex-1, High[1]+30,Dialog,Bold,15) Coloured(0,255,0)
EndIf
If Low[1] = Lowest[xPeriod](Low) and Low[2] > Low[1] and Low > Low[1] then
    SwingLow = Low[1]
    DrawArrowDown(BarIndex-1,Low[1]-10) Coloured(255,0,0)
    DrawText("#SwingLow#", BarIndex-1, Low[1]-30,Dialog,Bold,15) Coloured(255,0,0)
EndIf
Return

The code snippet above is structured to detect and mark swing highs and swing lows based on the price movements over a specified period. Here’s a step-by-step explanation:

  • Setting the Period: The variable xPeriod is set to 20, which defines the number of bars (or periods) to look back to find the highest high and the lowest low.
  • Identifying Swing High: The condition checks if the high of the previous bar (High[1]) equals the highest high of the last 20 bars (Highest[xPeriod](High)) and if it is greater than the highs of the bars immediately before and after it. If true, it marks this as a swing high.
  • Visual Representation for Swing High: If a swing high is identified, a green upward arrow is drawn at the bar, slightly above the high price. Additionally, the text “#SwingHigh#” is displayed above the arrow.
  • Identifying Swing Low: Similarly, the code checks for the lowest low in the same manner as the swing high but in the opposite direction. It ensures the low of the previous bar (Low[1]) is the lowest of the past 20 bars and is lower than the lows of the bars immediately before and after it.
  • Visual Representation for Swing Low: For swing lows, a red downward arrow is drawn at the bar, slightly below the low price. The text “#SwingLow#” is displayed below the arrow.

This implementation can be particularly useful for traders looking to automate the detection of potential pivot points in price charts, aiding in decision-making processes related to entries and exits in trades.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/text-above-candles/#post-200655

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.
JS Senior
I usually let my code do the talking, which explains why my bio is as empty as a newly created file. Bio to be initialized...
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...