garyprinting.com

Creating a Technical Indicator from Scratch in TradingView

Written on

Chapter 1: Understanding the Stochastic Oscillator

The Stochastic Oscillator is a widely utilized tool in technical analysis, providing insights into whether a market is overbought or oversold. In this piece, we will delve into coding a variant known as the Stochastic Smoothing Oscillator using TradingView’s Pine Script.

I recently published a new book following the success of my last one. This edition includes advanced indicators and strategies for trend following, with a dedicated GitHub page for ongoing code updates. Additionally, it features original colors optimized for printing costs. If this piques your interest, you can check out the Amazon link below, or reach out to me on LinkedIn for the PDF version.

The Stochastic Smoothing Oscillator

The Stochastic Oscillator is familiar in technical analysis, but its variant, the Stochastic Smoothing Oscillator, offers additional smoothing. Let’s first review the Stochastic Oscillator with EURGBP displayed in one panel, and the Stochastic Oscillator in another.

The normalization technique confines values between 0 and 1 (or 0 and 100 if you prefer). This involves subtracting the minimum value from the current value over a specific lookback period and dividing it by the difference between the maximum and minimum values in that same period.

The Stochastic Oscillator identifies overbought and oversold conditions by using highs and lows through the normalization formula. An overbought zone indicates extreme bullishness, suggesting a likely consolidation, whereas an oversold zone signals extreme bearishness, hinting at a potential bounce. Thus, the Stochastic Oscillator serves as a contrarian tool, highlighting reactions to significant market movements.

Now, let's transition to TradingView to code the Stochastic Smoothing Oscillator. Why should we code this ourselves when it’s available in the platform’s indicators? Learning to create our own technical indicators on a reputable charting platform is a foundational step. By grasping the basics of Pine Script, we’ll eventually gain the expertise to develop personalized indicators and strategies.

Consider joining Medium through my referral link; it’s a treasure trove of fascinating reads.

Creating the Stochastic Smoothing Oscillator in TradingView

To plot the Stochastic Smoothing Oscillator on EURGBP values in TradingView, you need to create an account, which is free. Begin by selecting the Chart option on the homepage and choose any asset for indicator calculation. Then, locate the Pine Editor at the bottom of your screen and prepare to code.

The first step is to set the Pine Script version. In our case, we’ll use version 4.

//@version=4

Next, declare the name of the indicator (script):

study("Stochastic Smoothing Oscillator")

Now, we can define the parameters for our oscillator. The Stochastic Smoothing Oscillator applies exponential moving averages to the highs, lows, and closing prices, utilizing the stochastic normalization function. We need to establish two lookback periods: 2 and 13. The 2-period lookback corresponds to the exponential moving average on HLC data, while the 13-period lookback refers to the normalization window.

lookback = 13

ema_lookback = 2

Next, we’ll smooth the HLC data using the built-in ema() function, which computes the exponential moving average based on our closing price and defined lookback periods.

SSO_low = ema(low, ema_lookback)

SSO_high = ema(high, ema_lookback)

SSO_close = ema(close, ema_lookback)

Now, we will apply the SSO formula, which mirrors the Stochastic Oscillator’s formula. We can utilize the highest() and lowest() functions to find the maximum and minimum values over the specified lookback period.

SSO = (SSO_close - lowest(SSO_low, lookback)) / (highest(SSO_high, lookback) - lowest(SSO_low, lookback)) * 100

Finally, we will plot the indicator alongside the chart using the plot() function, which specifies a source and color.

plot(SSO, color=color.red)

hline(10, color=color.gray, linestyle=hline.style_dashed)

hline(90, color=color.gray, linestyle=hline.style_dashed)

The full code is as follows:

//@version=4

study("Stochastic Smoothing Oscillator")

lookback = 13

ema_lookback = 2

SSO_low = ema(low, ema_lookback)

SSO_high = ema(high, ema_lookback)

SSO_close = ema(close, ema_lookback)

SSO = (SSO_close - lowest(SSO_low, lookback)) / (highest(SSO_high, lookback) - lowest(SSO_low, lookback)) * 100

plot(SSO, color=color.red)

hline(10, color=color.gray, linestyle=hline.style_dashed)

hline(90, color=color.gray, linestyle=hline.style_dashed)

The SSO operates similarly to the Stochastic Oscillator: a bullish bias emerges when the SSO is low, while a bearish bias occurs when it is high.

If you're interested in more technical indicators and strategies, my book may be right for you.

One Last Word

I have recently launched an NFT collection aimed at supporting various humanitarian and medical initiatives. "The Society of Light" comprises limited collectibles, with a portion of every sale directed to the associated charity. Here are some advantages of purchasing these NFTs:

  • High-Potential Gains: By focusing on marketing and promoting "The Society of Light," I aim to maximize their secondary market value. Remember, trading in the secondary market also means that royalties will be donated to the same charity.
  • Art Collection and Portfolio Diversification: Owning avatars that represent good deeds is fulfilling. Investing can be about more than just personal gain; it can also be a way to support others and appreciate art.
  • Flexible Donations: This is an adaptable means of contributing to your chosen causes.
  • Free Book in PDF: Buyers of any NFT will receive a complimentary copy of my latest book, linked in this article.

Click here to purchase Ron and support his cause for the elderly.

This video offers a comprehensive tutorial on creating indicators from scratch using TradingView.

In this video, learn how to customize indicators in TradingView for enhanced trading strategies.

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

Embrace the Courage to Be Disliked: A Guide to Authentic Living

Discover how to cultivate courage and authenticity in a society that often discourages uniqueness.

Monthly Inspiration: February 2023

Discover insights from

The Bob Phenomenon: A Deep Dive into Wall Street's Culture

Exploring the implications of

Navigating Self-Employment: A Guide to Your New Journey

Discover insights and tips for transitioning to self-employment and making it a rewarding venture.

Mastering Queues: A Practical Guide to Data Structures in Python

Explore the concept of queues in programming and their applications, from task scheduling to graph algorithms.

Elon Musk's Twitter Poll: A Turning Point for the Platform?

Elon Musk's Twitter poll raises questions about his leadership and the platform's future amid growing user concerns.

Understanding Prototype Chains and Classes in JavaScript

Discover the fundamentals of prototype chains and classes in JavaScript's object-oriented programming through a unique approach.

# Understanding the Justification Behind the $10 Billion James Webb Telescope

An exploration of the James Webb Space Telescope's purpose and costs, highlighting its potential impact on science and technology.