feat: add new indicators (Decay, Edecay, MinusDi, MinusDm, PlusDi, PlusDm, Maxindex, Minindex, Sarext) and update pine scripts, core libs, validation tests, and python bindings
2026-03-09 13:45:46 -07:00
|
|
|
// Licensed under the Apache License, Version 2.0
|
2026-01-18 19:02:03 -08:00
|
|
|
// © 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)
|