Pretty Good Oscillator Theory & Chart Implementation

Article

Assisted by AI

Explore the Pretty Good Oscillator theory and learn how to integrate it into your software applications for advanced charting functionality.
Soroush Sohrabian

Ahmad Omid

Data Science Developer

LinkedIn icon
Pretty-Good-Oscillator-Cover

Introduction to the Pretty Good Oscillator

The Pretty Good Oscillator (PGO) is a momentum-based technical indicator developed by Mark Johnson. The name “Pretty Good” reflects the indicator’s ability to effectively identify buy and sell opportunities in financial markets, while also acknowledging that no indicator is perfect.

PGO is designed to measure the relative distance between the latest closing price and a moving average, standardizing this value using the Average True Range (ATR). This allows traders to identify price deviations in a structured manner.

The Pretty Good Oscillator has gained popularity among technical analysts due to its simplicity and effectiveness in spotting overbought and oversold market conditions. It is especially useful in trend-following strategies where traders seek confirmation signals before entering or exiting trades.

Importance in Trading

PGO serves as a useful tool for traders looking to gauge the strength and direction of a trend. By utilizing a moving average and normalizing the price distance with ATR, the indicator helps traders determine whether the current price level is significantly higher or lower than the historical average.

The Pretty Good Oscillator is widely used for:

  • Identifying trend strength and reversals.
  • Confirming buy and sell signals.
  • Enhancing risk management by detecting overbought and oversold conditions.
  • Filtering out noise in choppy markets by considering price volatility.

Formula

The Pretty Good Oscillator is calculated using the following formula:

Pretty-Good-Oscillator-Formula

Where:

  • Close = Latest closing price
  • MA(Close, N) = Moving Average of closing prices over N periods
  • ATR = Average True Range, which measures market volatility
  • MA(ATR, N) = Moving Average of the ATR over N periods
  • N = The chosen period length for calculation

The formula essentially normalizes the price deviation from its moving average by using a volatility measure (ATR). This ensures that the indicator adapts to market conditions, making it more dynamic and responsive.

Interpretation

The Pretty Good Oscillator is used to determine how much a price has deviated from its moving average, in relation to market volatility. The interpretation is as follows:

  • PGO > 0: The closing price is above the moving average, indicating bullish strength.
  • PGO < 0: The closing price is below the moving average, signaling bearish momentum.
  • PGO > 2: The asset may be overbought, suggesting a potential selling opportunity.
  • PGO < -2: The asset may be oversold, signaling a possible buying opportunity.

Calculation Example

Let’s assume a trader uses a 14-day period (N = 14) for calculating the Pretty Good Oscillator.

  1. Calculate the 14-day moving average of the closing price.
  2. Compute the 14-day ATR.
  3. Determine the moving average of the ATR over 14 periods.
  4. Apply the formula to find the PGO value.

For instance:

  • Close price today = 105
  • 14-day MA of Close = 100
  • 14-day ATR = 2
  • 14-day MA of ATR = 1.8
Pretty-Good-Oscillator-Calculation-Example

A PGO value of 2.78 suggests the asset is reaching overbought territory and may experience a price correction.

How to Create the Technical Indicator Using LC JS Trader

Step 1: Get LightningChart JS Trader

To begin, you’ll need access to LightningChart JS Trader. This library provides the tools necessary to create advanced technical indicators, including the Pretty Good Oscillator Indicator. Visit the LightningChart JS Trader page to download the required components and review the documentation.

Step 2: Review the Interactive Example

LightningChart JS Trader includes interactive examples that demonstrate how to create custom technical indicators. Start by reviewing the documentation, focusing on how to integrate the Pretty Good Oscillator Indicator into your chart setup. The interactive examples will guide you through the process of setting up the PGO Indicator, from importing the necessary modules to modify the chart settings.

Step 3: Code Explanation

In this step, we will break down the code that creates the chart with the Pretty Good Oscillator Indicator, as shown in the image, using LightningChart JS Trader. The code demonstrates how to initialize a trading chart, apply the PGO Indicator, and customize its appearance.

Pretty-Good-Oscillator-Chart

Here’s a detailed breakdown of each section:

A. Importing the Required Libraries:

   const lcjsTrader = require('@arction/lcjs-trader')
   const lcjs = require('@arction/lcjs')
   const { Themes } = lcjs
  • lcjsTrader: This library provides access to the LightningChart JS Trader functionalities, allowing you to create advanced financial charts.
  • lcjs: The main LightningChart JS library, used for general charting functionality.
  • Themes: A property within lcjs that provides access to pre-built themes. In this case, we are using the darkGold theme to style the chart.

B. Initializing the Trading Chart:

   lcjsTrader.trader(TRADER_LICENSE).then(async (trader) => {
    // Create a trading chart.
    const tradingChart = trader.tradingChart({ loadFromStorage: false, colorTheme: Themes.darkGold })
  • trader(TRADER_LICENSE): Initializes the LightningChart JS Trader with the provided license key (TRADER_LICENSE). This is required to access the charting functionalities for financial data.

Note you can request a LightningChart JS Trader trial license, which is free.

  • tradingChart(): This function creates a trading chart with certain options.
  • loadFromStorage: false: This disables the loading of previously stored chart data from local storage, ensuring a fresh chart setup.
  • colorTheme: Themes.darkGold: This applies the darkGold theme to the chart, which influences the background color, gridlines, and other visual elements.

C. Adding and Customizing the Indicator

// Add a Pretty Good Oscillator indicator 
    const pgo = tradingChart.indicators().addPrettyGoodOscillator()
    pgo.setPeriodCounts(14, 14)
    pgo.setMovingAverageTypes(2, 0)
    pgo.setSource(3)
    pgo.setLineColor('#47FF14')
    pgo.setLineWidth(3)
  • addPrettyGoodOscillator(): It measures the distance between the latest close value and the moving average of the price. The result is then divided by a moving average of the Average True Range.
  • pgo.setPeriodCounts(14, 14): Sets the number of time periods (n) used to calculate the indicator (periodCountMA, periodCountATR).
  • **pgo.setMovingAverageTypes(2, 0): Sets the types of moving averages used in the Pretty Good Oscillator calculations. In this case, 2 represents the Simple Moving Average (SMA); and 0 represents the Exponential Moving Average (EMA) that could be changed to another moving average types.
  • ***pgo.setSource(3): Sets which values the indicator calculations are based on. In this case, calculations based on Close values.
  • pgo.setLineColor('#47FF14'): Changes the color of the indicator line to green.
  • pgo.setLineWidth(3): Sets the line thickness of the indicator to 3 pixels. This makes the line more prominent and easier to observe during analysis.

D. Loading Data from a CSV File

    // Reading data from a file.
    await fetch(`${document.head.baseURI}examples/assets/0000/Alphabet Inc (GOOGL).csv`).then((res) => res.text()).then((text) => {
        tradingChart.readCsvString(text, 'Alphabet Inc (GOOGL)')
    })
  • fetch(): This function retrieves a CSV file containing historical data for Alphabet Inc. (GOOGL). The CSV file includes pricing information for the company’s stock, which is plotted on the chart.
  • readCsvString(): This function reads the CSV data and interprets it as pricing data for Alphabet Inc. The second argument (‘Alphabet Inc (GOOGL)’) sets the label for the chart, as seen at the top of the chart image.

E. Setting the Currency for the Chart

    tradingChart.setCurrency('USD')
   })
  • setCurrency('USD'): This sets the currency of the chart to USD, ensuring that the pricing data is interpreted and displayed in US dollars.

** Enumeration of Moving Average Types in LC JS Trader:

  • Exponential Moving Average (EMA): 0
  • None: 1 (No moving average applied)
  • Simple Moving Average (SMA): 2
  • Time Series Moving Average (TSMA): 3
  • Triangular Moving Average (TMA): 4
  • Variable Moving Average (VMA): 5
  • Variable Index Dynamic Average (VIDYA): 6
  • Volume Weighted Moving Average (VWMA): 7
  • Weighted Moving Average (WMA): 8
  • Welles Wilder’s Smoothing (WWS): 9

** Enumeration Source in LC JS Trader:

To select which values the indicator calculations are based on.

Moving-Average-Convergence-Table

Advantages and Limitations of the Indicator

Advantages

  • Simple yet Effective: The Pretty Good Oscillator is easy to calculate and interpret, making it accessible to traders of all levels.
  • Incorporates Volatility: By using ATR, PGO adjusts to market conditions, making it more reliable in dynamic environments.
  • Identifies Momentum Reversals: PGO helps traders detect shifts in momentum, offering early signals for potential trend changes.
  • Works Well with Other Indicators: The PGO can be combined with moving averages, RSI, or MACD to refine trade signals and confirm trends.

Limitations

  • False Signals in Ranging Markets: In sideways or choppy markets, the PGO may generate misleading signals, requiring additional filters.
  • Lagging Nature: Since it relies on moving averages, PGO can be somewhat lagging, meaning traders may miss the very early stages of trend reversals.
  • Parameter Sensitivity: The choice of period (N) affects the indicator’s sensitivity, requiring traders to fine-tune settings based on market conditions.

Conclusion

The Pretty Good Oscillator is a valuable technical indicator that helps traders assess price deviations relative to volatility. By normalizing the price difference from a moving average using ATR, PGO provides insightful buy and sell signals. While it excels in trend-following strategies, traders should be aware of its limitations and consider combining it with other indicators for better accuracy.

For practical implementation, traders can use LightningChart JS Trader to visualize PGO in real-time, experiment with different period settings, and analyze historical performance. By mastering the Pretty Good Oscillator, traders can enhance their decision-making process and improve their overall trading strategy.

Continue learning with LightningChart