Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 1, 2025

Adds Williams %R (Williams Percent Range), a momentum indicator measuring overbought/oversold levels on a -100 to 0 scale. Readings near 0 indicate overbought conditions, readings near -100 indicate oversold.

Implementation

  • Formula: %R = (Highest High - Close) / (Highest High - Lowest Low) × -100
  • Optimization: Single-pass loop for finding highest/lowest values (O(n) vs O(2n))
  • Edge cases: Returns -100 when price range is zero (prevents division by zero)

Usage

import {WilliamsR} from 'trading-signals';

const willR = new WilliamsR(14); // 14-period lookback

willR.add({close: 44.00, high: 44.50, low: 43.00});
willR.add({close: 43.50, high: 44.25, low: 42.75});
// ... add more candles

if (willR.isStable) {
  const value = willR.getResult(); // e.g., -23.5
}

Verification

Test suite confirms Williams %R is arithmetically equivalent to the inverted Stochastic %K oscillator (using parameters 5, 1, 1 for raw %K without smoothing): Williams %R = Stochastic %K - 100

Original prompt

This section details on the original issue you should resolve

<issue_title>Williams %R indicator?</issue_title>
<issue_description>Could you please implement "Williams %R" indicator?</issue_description>

<agent_instructions>Implement the Williams %R (Williams Percent Range) indiactor along with some test cases. The %R indicator is arithmetically exactly equivalent to the %K stochastic oscillator, mirrored at the 0%-line, when using the same time interval. Verify that as well in a test case by using the "StochasticOscillator" already provided by the "trading-signals" library.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@bennycode @netandreus are you referring to [Williams Percent Range](https://en.wikipedia.org/wiki/Williams_%25R)?

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 1, 2025 23:01
Co-authored-by: bennycode <469989+bennycode@users.noreply.github.com>
Co-authored-by: bennycode <469989+bennycode@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement Williams %R indicator with test cases Implement Williams %R momentum indicator Nov 1, 2025
Copilot AI requested a review from bennycode November 1, 2025 23:07
Copilot finished work on behalf of bennycode November 1, 2025 23:07
@bennycode bennycode marked this pull request as ready for review November 2, 2025 00:32
@bennycode bennycode merged commit 3ab4afc into main Nov 2, 2025
3 checks passed
@bennycode bennycode deleted the copilot/implement-williams-r-indicator branch November 2, 2025 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Williams %R indicator?

2 participants