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.