Indicator · Pine Script v6 · Own pane

Rectified Linear Unit (ReLU)

by mihakralj

This indicator applies the rectified linear unit to the difference between the selected source and a 20-period simple moving average.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code24
Settings1inputs
LicenceApache-2.0
Last update4 weeks ago27 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

24 lines of Pine Script v6 from lib/numerics/relu/relu.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

relu.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Rectified Linear Unit (ReLU)", "ReLU", overlay=false, precision=6)

//@function Applies the Rectified Linear Unit (ReLU) activation function to a series.
// ReLU returns the input directly if it is positive, otherwise, it returns zero.
//@param src The source series.
//@returns The ReLU transformed series.
relu(series float src) =>
    math.max(0, src)

// ---------- Main loop ----------

// Inputs
i_source = input.source(close, "Source")

// Calculation of relu on SMA(source)-source
reluDn = -relu(ta.sma(i_source,20)-i_source)
reluUp = relu(i_source-ta.sma(i_source,20))

// Plot
plot(reluUp, "ReLU", color=color.green, linewidth=2)
plot(reluDn, "ReLU", color=color.red, linewidth=2)

Overview

Positive deviations plot in green and negative deviations plot in red in a separate pane. The only input changes the price series used for both the average and the residual. The period is fixed in the code, and the script does not generate trade entries, exits, or risk levels.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Moving averages, AI / machine learning

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Sourcesourceclosei_source
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

AI Trend Navigator

by hasnocool
106 stars

This indicator calculates a trend direction and smoothed moving average using a k-nearest neighbours (k-NN) classification algorithm directly on the main price chart. Users can select input price types, target values, neighborhood size, and smoothing periods.

Indicator v5 AI / machine learningTrend
Updated 2 years ago · GPL-3.0 GitHub repository of AI Trend Navigator
948 stars

The Derivative Oscillator calculates a double-exponentially smoothed Relative Strength Index (RSI) and subtracts its Simple Moving Average (SMA) to form the main oscillator line. A secondary signal line is plotted using an SMA of the main oscillator values. Th

Indicator v4 Oscillators & momentumMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Derivative Oscillator

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

MACD

by Alorse
330 stars

This indicator calculates and plots the standard Moving Average Convergence Divergence oscillator in a separate pane. It computes the difference between a fast and slow moving average, derives a signal line through smoothing, and plots a histogram representing

Indicator v4 Oscillators & momentumMoving averages
Updated 2 months ago · None stated GitHub repository of MACD
318 stars

Calculates and plots moving averages on selected VIX volatility terms (VIX9D, VIX, VIX3M, or VIX6M) in a separate pane. The script computes user-defined short and long moving averages using EMA or SMA. It shades the background red when the short-term moving av

Indicator v5 Volatility & bandsMoving averages
Updated 2 months ago · MIT GitHub repository of [TVT] VIX Short Term Danger

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers