ComponentOne FinancialChart for UWP
Analytics / Indicators / Williams %R
In This Topic
    Williams %R
    In This Topic

    Williams %R indicator for the FinancialChart is a momentum indicator, which compares the current asset price to the highest price over the look back period. Its look-back is typically 14 periods. The indicator fluctuates between 0 and -100. It is the inverse of a fast Stochastic Oscillator.

    While the Williams %R displays the level of a stock's close relative to the highest high for the look-back period, the Stochastic Oscillator shows the level of a stock's close relative to the lowest low. Both the indicators show same lines, however scaling is different. It finds application in determining Overbought/Oversold levels, providing buy and sell signals, and momentum confirmations.

    To work with WilliamsR indicator, you need to create an instance of WilliamsR class. FinancialChart also enables you to fetch the calculated WilliamsR values at run-time using GetValues() method. This can help in creating alerts in application or maintaining logs while working with dynamic data.

    The following code snippet demonstrates how to work with Williams %R. Refer to Relative Strength Index to see the code for DataService.cs.

    Partial Public Class Indicators
        Inherits Page
        Private dataService As DataService = dataService.GetService()
        Private wi As New WilliamsR() With {
            .SeriesName = "Williams %R"
        }
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Public ReadOnly Property Data() As List(Of Quote)
            Get
                Return dataService.GetSymbolData("box")
            End Get
        End Property
    
        Public ReadOnly Property IndicatorType() As List(Of String)
            Get
                Return New List(Of String)() From {
                   
                    "Williams %R"
                }
            End Get
        End Property
    
    
        Sub OnIndicatorTypeSelectionChanged(sender As Object, e As SelectionChangedEventArgs)
            Dim ser As FinancialSeries = Nothing
    
            If cbIndicatorType.SelectedIndex = 3 Then
                ser = wi
            End If
    
            If ser IsNot Nothing AndAlso Not indicatorChart.Series.Contains(ser) Then
                indicatorChart.BeginUpdate()
                indicatorChart.Series.Clear()
                indicatorChart.Series.Add(ser)
                indicatorChart.EndUpdate()
            End If
        End Sub
    
        Sub OnCbPeriodValueChanged(sender As Object, e As PropertyChangedEventArgs(Of Double))
            wi.Period = 14
    
        End Sub
    
        Sub OnFinancialChartRendered(sender As Object, e As RenderEventArgs)
            If indicatorChart IsNot Nothing Then
                indicatorChart.AxisX.Min = (CType(financialChart.AxisX, IAxis)).GetMin()
                indicatorChart.AxisX.Max = (CType(financialChart.AxisX, IAxis)).GetMax()
            End If
        End Sub
    End Class
    
    public partial class Indicators : Page
    {
        DataService dataService = DataService.GetService();
        WilliamsR wr = new WilliamsR() { SeriesName = "Williams % R" };
    
        public Indicators()
        {
            InitializeComponent();
        }
    
        public List<Quote> Data
        {
            get
            {
                return dataService.GetSymbolData("box");
            }
        }
    
        public List<string> IndicatorType
        {
            get
            {
                return new List<string>()
                {
                    "Williams %R"
                };
            }
        }
    
        void OnIndicatorTypeSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            FinancialSeries ser = null;
            if (cbIndicatorType.SelectedIndex == 0)
                ser = wr;
    
            if (ser != null && !indicatorChart.Series.Contains(ser))
            {
                indicatorChart.BeginUpdate();
                indicatorChart.Series.Clear();
                indicatorChart.Series.Add(ser);
                indicatorChart.EndUpdate();
            }
        }
    
        void OnCbPeriodValueChanged(object sender, PropertyChangedEventArgs<double> e)
        {
            wr.Period = 14;
        }
    
        void OnFinancialChartRendered(object sender, RenderEventArgs e)
        {
            if (indicatorChart != null)
            {
                indicatorChart.AxisX.Min = ((IAxis)financialChart.AxisX).GetMin();
                indicatorChart.AxisX.Max = ((IAxis)financialChart.AxisX).GetMax();
            }
        }
    }