Library · Pine Script v5 · Library

TrendChecker

by RobACurtis· code credited to djdrob

A Pine library that exports three functions, bullish, bearish and getTrend, which judge market direction on the current symbol and timeframe.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code100
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago20 Jan 2024

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 library, select all of the template text and paste. Press Save and give it a name.
  4. 4Publish or import itA library draws nothing. Publish it from the editor, then import its functions in your own scripts.

Source Code

100 lines of Pine Script v5 from libraries/TrendChecker.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

TrendChecker.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © djdrob

//@version=5

// @description This will check the direction of the market based on the current ticker and time.
// Use the bullish or bearish or getTrend function with its proper arguments to determine current trend.
library("TrendChecker", overlay = true)

// @function sets RSI parameters.
setRSI() =>
    rsi1 = ta.rsi(close, 15)
    kRed = ta.sma(ta.stoch(rsi1, rsi1, rsi1, 20), 4)
    dGreen = ta.sma(kRed, 4)
    [kRed, dGreen]

// @function sets MACD parameters
setMACD() =>
    fast_ma = ta.ema(close, 12)
    slow_ma = ta.ema(close, 26)
    macd = fast_ma - slow_ma
    signal = ta.ema(macd, 9)
    hist = macd - signal
    [macd, signal]

// @function sets up 2 and 3 sma
setSMA() =>
    red = ta.sma(close, 2)
    green = ta.sma(close, 3)
    [red, green]

// @returns boolean
checkRSICrossing() =>
    [k, d] = setRSI()
    result = (k > d) ? true : false
    result

// @returns boolean
checkMACDCrossing() =>
    [macd, signal] = setMACD()
    result = macd > signal ? true : false
    result

// @returns boolean
checkSMACrossing(int timeDelay) =>
    [red, green] = setSMA()
    result = red > green[timeDelay] ? true : false

// @function Checks if the chart is bullish
// @returns boolean
// @param this function take 3 booleans to decide which combination of indicators to check for direction
// and optional argument of time delay for the 3sma(green)
export bullish(bool RSI, bool MACD, bool SMA, int timeDelay = 2) =>
    bullishRSI = checkRSICrossing()
    bullishMACD = checkMACDCrossing()
    bullishSMA = checkSMACrossing(timeDelay)

    var bool _rsi = true
    var bool _sma = true
    var bool _macd = true
    if RSI
        _rsi := bullishRSI == true
    if MACD
        _macd := bullishMACD == true
    if SMA
        _sma := bullishSMA == true

    bullish = _rsi and _macd and _sma
    bullish

// @function Checks if the chart is bearish
// @returns boolean
// @param this function take 3 booleans to decide which combination of indicators to check for direction
// and optional argument of time delay for the 3sma(green)
export bearish(bool RSI, bool MACD, bool SMA, int timeDelay = 2) =>
    bearishRSI = checkRSICrossing()
    bearishMACD = checkMACDCrossing()
    bearishSMA = checkSMACrossing(timeDelay)

    var bool _rsi = true
    var bool _sma = true
    var bool _macd = true
    if RSI
        _rsi := bearishRSI == false
    if MACD
        _macd := bearishMACD == false
    if SMA
        _sma := bearishSMA == false

    bearish = _rsi and _macd and _sma
    bearish

// @function Get bull and bear trends
// @returns boolean
// @param this function take 3 booleans to decide which combination of indicators to check for direction
// and optional argument of time delay for the 3sma(green)
export getTrend(bool RSI, bool MACD, bool SMA, int timeDelay = 2) =>
    bullish = bullish(RSI, MACD, SMA, timeDelay)
    bearish = bearish(RSI, MACD, SMA, timeDelay)
    [bullish, bearish]

Overview

Each call takes three switches to include a Stochastic RSI cross, a MACD line versus signal check and a comparison of 2-bar and delayed 3-bar moving averages, plus an optional delay. The functions return booleans, or a bullish and bearish pair, for other scripts to import. It has no inputs of its own.

Details

Published by

RobACurtis on GitHub

Code credit

djdrob, as written in the script's header

Type

Library, Pine Script v5

Draws

Library (no plots)

Category

Trend, Oscillators & momentum

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

pinescripttradingtradingview

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

MirPapa_Lib_trend

by alvinng214
2 stars

MirPapa_Lib_trend is a Pine Script utility library providing trend and momentum calculation functions for other scripts. It features implementations for several moving average types, including the Hull Moving Average (HMA), Exponential Hull Moving Average (EHM

Library v6 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of MirPapa_Lib_trend

ta

by ivansoft
1 stars

Provides a collection of technical analysis calculation functions for use across Pine scripts. It exports implementations for various indicators and mathematical formulas, including oscillators like the Awesome Oscillator, Aroon, and Schaff Trend Cycle, moving

Library v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ta

FunctionLinearRegression

by ricardosantos79
261 stars

This Pine Script v5 library provides functions to calculate and plot linear regression channels using sample point arrays. It evaluates paired X and Y arrays to calculate the regression slope, intercept, fitted values, maximum deviation, minimum deviation, and

Library v5 Trend
Updated 4 years ago · None stated GitHub repository of FunctionLinearRegression

RSI Lib

by augustoerni
3 stars

This library exports a function that calculates the Relative Strength Index from the close price. It measures bar-to-bar change, separates gains and losses, smooths both with a running moving average, and returns the standard 100-scale RSI. Callers pass the lo

Library v5 Oscillators & momentum
Updated 2 years ago · None stated GitHub repository of RSI Lib
948 stars

The Adaptive RSI Moving Average (ARSIMA) is an overlay indicator that dynamically adjusts its smoothing factor based on the Relative Strength Index (RSI). When the RSI moves toward extreme overbought or oversold conditions, the smoothing factor increases to ma

Indicator v4 Moving averagesOscillators & momentum
Updated 11 days ago · GPL-3.0 GitHub repository of Adaptive RSI Moving Average

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup

More libraries

Trade Your Charts With a Regulated Broker

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

Compare brokers