Finding Higher Highs, Lower Lows, Lower Highs, and Higher Lows with Python

Step 1

                    import pandas as pd
import numpy as np

# Sample price data (replace with your own dataset)
data = {
    'Date': ['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05'],
    'Close': [100, 110, 105, 115, 112]
}

# Create a DataFrame
df = pd.DataFrame(data)

# Calculate higher highs and lower lows
df['HH'] = np.where(df['Close'] > df['Close'].shift(1), True, False)
df['LL'] = np.where(df['Close'] < df['Close'].shift(1), True, False)

print(df)
                    

Step 2

                    # Calculate lower highs and higher lows
df['LH'] = np.where(df['Close'] < df['Close'].shift(1), True, False)
df['HL'] = np.where(df['Close'] > df['Close'].shift(1), True, False)

print(df)
                    
Madra David
Madra David
2 minute read
TFT

Share this article

Next Post

Buy and sell signals with the Directional Change Algorithm in Python

Previous Post

The Volatility Contraction Pattern (VCP)

I send out tips on how to improve your website's performance

I send out tips on how to improve your website's performance

user-image

Published novembre 14 2023

by Madra David