Skip to main content

Pivot Points Indicator

Overview

Pivot Points are key support and resistance levels calculated from previous period's price data. This implementation will include multiple calculation methods (Standard, Fibonacci, Camarilla) and dynamic level strength analysis.

Status

  • Domain Model Design
  • Core Implementation
  • API Integration
  • Testing
  • Documentation

Components

1. Domain Model

interface PivotPointData {
// Core Values
pivot: number; // Main pivot point
support_levels: number[]; // Support levels
resistance_levels: number[]; // Resistance levels

// Analysis
current_zone: PivotZone; // Current price zone
level_strength: LevelStrength[]; // Strength of each level
next_level: number; // Next significant level

// Signals
signal: SignalType; // Trading signal
signal_strength: number; // Signal confidence (0-1)
}

enum PivotZone {
ABOVE_R3 = 'above_r3',
R2_R3 = 'r2_r3',
R1_R2 = 'r1_r2',
P_R1 = 'p_r1',
S1_P = 's1_p',
S2_S1 = 's2_s1',
S3_S2 = 's3_s2',
BELOW_S3 = 'below_s3',
}

enum PivotMethod {
STANDARD = 'standard',
FIBONACCI = 'fibonacci',
CAMARILLA = 'camarilla',
WOODIE = 'woodie',
DEMARK = 'demark',
}

interface LevelStrength {
level: number;
strength: number; // 0-1 scale
hits: number; // Times level was tested
type: 'support' | 'resistance';
}

2. Configuration

interface PivotPointSettings {
calculation_method: PivotMethod; // Calculation method to use
levels_count: number; // Number of S/R levels (default: 3)
strength_lookback: number; // Periods for strength calculation
zone_threshold: number; // % distance for zone detection
}

3. API Endpoints

REST API

  • GET /v1/pivot-points
    • Parameters:
      • symbol: Trading pair
      • timeframe: Candle timeframe
      • method: Calculation method
      • levels: Number of levels

WebSocket

  • Channel: pivot_points
    • Updates: Level values and current zone
    • Frequency: On period close

Technical Implementation

1. Core Calculation

def compute_pivot_points(
df: pd.DataFrame,
settings: PivotPointSettings
) -> pd.DataFrame:
"""
Calculate Pivot Points using specified method.

Args:
df: DataFrame with OHLCV data
settings: Pivot Points calculation settings

Returns:
DataFrame with Pivot Points calculations
"""
# Get previous period's data
high = df['high'].shift(1)
low = df['low'].shift(1)
close = df['close'].shift(1)

if settings.calculation_method == PivotMethod.STANDARD:
# Standard pivot points
df['pivot'] = (high + low + close) / 3
df['r1'] = (2 * df['pivot']) - low
df['s1'] = (2 * df['pivot']) - high
df['r2'] = df['pivot'] + (high - low)
df['s2'] = df['pivot'] - (high - low)
df['r3'] = high + 2 * (df['pivot'] - low)
df['s3'] = low - 2 * (high - df['pivot'])

elif settings.calculation_method == PivotMethod.FIBONACCI:
# Fibonacci pivot points
df['pivot'] = (high + low + close) / 3
df['r1'] = df['pivot'] + 0.382 * (high - low)
df['s1'] = df['pivot'] - 0.382 * (high - low)
df['r2'] = df['pivot'] + 0.618 * (high - low)
df['s2'] = df['pivot'] - 0.618 * (high - low)
df['r3'] = df['pivot'] + 1.000 * (high - low)
df['s3'] = df['pivot'] - 1.000 * (high - low)

elif settings.calculation_method == PivotMethod.CAMARILLA:
# Camarilla pivot points
df['pivot'] = (high + low + close) / 3
df['r1'] = close + 1.1 * (high - low) / 12
df['s1'] = close - 1.1 * (high - low) / 12
df['r2'] = close + 1.1 * (high - low) / 6
df['s2'] = close - 1.1 * (high - low) / 6
df['r3'] = close + 1.1 * (high - low) / 4
df['s3'] = close - 1.1 * (high - low) / 4

return df

2. Analysis Functions

def analyze_current_zone(
price: float,
levels: Dict[str, float],
threshold: float
) -> PivotZone:
"""Determine current price zone."""
# Implementation details

def calculate_level_strength(
df: pd.DataFrame,
level: float,
lookback: int
) -> float:
"""Calculate strength of a pivot level."""
# Implementation details

def find_next_level(
price: float,
levels: Dict[str, float],
direction: str
) -> float:
"""Find next significant pivot level."""
# Implementation details

def generate_signal(
zone: PivotZone,
level_strengths: List[LevelStrength],
price_action: Dict
) -> Tuple[SignalType, float]:
"""Generate trading signal and strength."""
# Implementation details

3. Integration Points

  • Price action confirmation
  • Support/Resistance validation
  • Trend analysis integration
  • Multi-timeframe analysis

Configuration

TIMEFRAME_SETTINGS: Dict[str, PivotPointSettings] = {
"1h": PivotPointSettings(
calculation_method=PivotMethod.STANDARD,
levels_count=3,
strength_lookback=20,
zone_threshold=0.001
),
"4h": PivotPointSettings(...),
"1d": PivotPointSettings(...)
}

Development Guidelines

1. Performance Optimization

  • Efficient level calculation
  • Smart zone detection
  • Optimized strength analysis
  • Cached level validation

2. Testing Strategy

def test_pivot_calculation():
"""Test pivot point calculations."""

def test_zone_detection():
"""Test price zone classification."""

def test_level_strength():
"""Test level strength calculation."""

def test_signal_generation():
"""Test trading signal generation."""

def test_level_validation():
"""Test support/resistance validation."""

3. Error Handling

  • Handle missing data
  • Validate calculation inputs
  • Handle timezone issues
  • Manage period transitions

Dependencies

  • NumPy: Numerical operations
  • Pandas: Data manipulation
  • FastAPI: REST endpoints
  • TimeZone handling library

Future Enhancements

  1. Dynamic calculation method selection
  2. Historical level analysis
  3. Volume-weighted pivot points
  4. Machine learning validation

References

  1. Pivot Points
  2. Fibonacci Pivots
  3. Support and Resistance