Detecting Highs and Lows in Market Trends Using ProBuilder

14 Mar 2017
0 comment
0 attachment

This code snippet demonstrates how to identify higher highs (HH), lower highs (LH), higher lows (HL), and lower lows (LL) in market trends, which are fundamental concepts in Dow Theory. These points are crucial for understanding market directions and trend reversals.


once hh = 0
once lh = 0
once hl = 0
once ll = 0

if high > high[1] and high[1] > high[2] then
    hh = hh + 1
endif

if high < high[1] and high[1] > high[2] then
    lh = lh + 1
endif

if low > low[1] and low[1] > low[2] then
    hl = hl + 1
endif

if low < low[1] and low[1] < low[2] then
    ll = ll + 1
endif

Explanation of the Code:

  • The code starts by initializing four variables: hh (higher highs), lh (lower highs), hl (higher lows), and ll (lower lows) to zero. These variables will count the occurrences of each pattern.
  • The if conditions check for specific patterns in the price highs and lows over three consecutive periods (current, previous, and the one before the previous).
  • if high > high[1] and high[1] > high[2]: This condition checks if the current high is greater than the previous high, and the previous high is greater than the high before it, indicating a Higher High (HH).
  • if high < high[1] and high[1] > high[2]: This checks if the current high is less than the previous high but the previous high is greater than the high before it, indicating a Lower High (LH).
  • if low > low[1] and low[1] > low[2]: This condition checks for a Higher Low (HL) where the current low is higher than the previous low, and the previous low is higher than the low before it.
  • if low < low[1] and low[1] < low[2]: This checks for a Lower Low (LL) where the current low is lower than the previous low, and the previous low is lower than the low before it.

This code is useful for traders and analysts who want to automate the detection of critical trend reversal points in financial markets.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/conversion-tradingview-to-prorealtime-higher-highs-and-lower-lows/

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