3 Secret Custom Indicators You Can Create Using Pine Script – moneymatteronlie

3 Secret Custom Indicators You Can Create Using Pine Script

In this guide, you’ll learn how to create your own custom trading indicators with zero programming or math experience. By the end of this tutorial, you’ll be equipped with simple steps to build three custom indicators using basic concepts and a powerful tool: TradingView’s Pine Script.

3 Secret Custom Indicators You Can Create Using Pine Script

 

Getting Started with Pine Script

Pine Script is TradingView’s programming language for creating custom technical analysis indicators. Best of all, it’s free to use. To begin, make sure you sign up for TradingView if you haven’t already; there’s a link in the description to help you get started.

Opening Pine Script Editor:

  1. Open a chart on TradingView. The type of security doesn’t matter for this tutorial, as we just need a chart to apply the indicator to.
  2. At the bottom of the window, find the “Pine Editor” tab and click on it. This opens the Pine Script editor where you’ll write your custom code.
  3. To make the editor easier to work with, click on the three dots at the top-right corner of the editor and select “Open in a new window.”

Understanding the Basics: When you start, you’ll see default lines in the editor. The line indicator("My Script") is always there and should not be removed. This line sets the name of your custom indicator. The default line plot(close) is a function that plots the closing prices of the security on the chart.

Creating Your First Indicator: EMA

To create a simple Exponential Moving Average (EMA), we can use Pine Script’s built-in functions. A function in programming is like a pre-built tool that does complex work for you; you just need to tell it what to do.

Forex trading and check  by mobile

 

Building the EMA Indicator:

  1. Replace plot(close) with the following code:
    pinescript
    ema1 = ta.ema(close, 20)
    plot(ema1)
    • ta.ema() is the built-in function for calculating the EMA. The first parameter, close, refers to the source data (closing prices), and 20 is the length of the EMA.
    • ema1 is a variable that stores the calculated EMA.
  2. Click “Add to Chart,” and you’ll see the EMA plotted over your chart.

Explanation: Using built-in functions like ta.ema() saves you from needing to understand the underlying math. You simply input the source data and the length, and the function outputs the EMA.

Creating a More Complex Indicator: EMA Difference

Next, we’ll create an indicator that shows the difference between two EMAs, a technique similar to the MACD. This type of indicator helps identify trends and potential reversals.

Steps to Create EMA Difference:

  1. Define a second EMA with a longer length:
    pinescript
    ema2 = ta.ema(close, 100)
  2. Calculate the difference between the two EMAs:
    pinescript
    ema_diff = ema1 - ema2
  3. Plot the difference:
    pinescript
    plot(ema_diff)

Explanation: ema_diff will show an oscillating line, moving above and below zero as the short-term EMA crosses over the long-term EMA. This is similar to how the MACD works, and it can signal bullish or bearish trends.

Creating an Indicator to Identify Market Choppiness

Understanding whether a market is trending or choppy can be crucial for traders. We’ll create an indicator to help identify when the market is choppy.

Steps to Build a Choppiness Indicator:

  1. Set up a simple moving average (SMA) with an adjustable length:
    pinescript
    ma_length = input.int(150, title="SMA Length")
    moving_average = ta.sma(close, ma_length)
    • The input.int() function allows you to set a default value for the SMA length (150) and provides a title for the setting.
  2. Use the ta.crossover() function to detect when the price crosses above the moving average:
    pinescript
    cross_ma = ta.crossover(close, moving_average)
  3. Count the number of bars since the last crossover:
    pinescript
    bars_since = ta.barssince(cross_ma)
  4. Plot the result:
    pinescript
    plot(bars_since, color=color.red, style=plot.style_stepline)

Explanation: This bars_since variable tells you how many bars have passed since the last time the price crossed the moving average. Large values indicate strong trends, while small values suggest choppy markets.

Adding Customizable Inputs to Indicators

Customizable inputs make your indicators more flexible. Here’s how to create inputs that can be changed without altering the code:

Adding an Input for Length: Replace the hard-coded length with:

pinescript
sma_length = input.int(150, title="SMA Length")

Benefits of Custom Inputs: This change allows you to adjust the SMA length directly from the chart settings without modifying the code itself.

Creating a Momentum Indicator with True Strength Index (TSI)

For a momentum indicator, we’ll use the built-in TSI function. This will help identify the strength and direction of a trend.

Business growth concept in allusive graph chart showing marketing sales profit

 

Steps to Build a TSI Indicator:

  1. Create input variables for short and long lengths:
    pinescript
    short_length = input.int(5, title="Short Length")
    long_length = input.int(10, title="Long Length")
  2. Create the TSI variable:
    pinescript
    tsi = ta.tsi(close, short_length, long_length)
  3. Create an EMA of the TSI line:
    pinescript
    ema_length = input.int(50, title="EMA Length")
    ema_tsi = ta.ema(tsi, ema_length)
  4. Plot the TSI and EMA TSI lines:
    pinescript
    plot(tsi, color=color.gray, title="TSI")
    plot(ema_tsi, color=color.yellow, title="EMA of TSI")

Adding Color and Conditional Coloring: To differentiate between the lines, we can set colors, and to fill the space between them, we use the fill() function:

pinescript
fill(plot1, plot2, color=color.green, transp=80)

 

Conclusion

By understanding these basic Pine Script concepts and using built-in functions, you can create a wide range of custom trading indicators without needing any programming or math expertise. Start simple, experiment with different functions, and build more complex indicators over time. This opens up a new level of customization in your trading strategy.

Leave a Comment