Library · Pine Script v5 · Library

CommonSignals

by Yavuz365

CommonSignals is a Pine Script utility library providing standardized signal generation functions for technical analysis scripts.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code221
Settings0inputs
LicenceMIT
Last update9 months ago19 Jan 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 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

221 lines of Pine Script v5 from libraries/CommonSignals.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

CommonSignals.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
// © Yavuz365
// CommonSignals Library - Standardized Signal Generation Utilities

//@version=5
// @description Standardized signal generation library for consistent indicator output.
// Signals are normalized to: BUY=1, NEUTRAL=0, SELL=-1
// Provides signal aggregation, filtering, and confirmation utilities.
library("CommonSignals", overlay=true)

import TimeFrameUtils as TF

// ============================================================================
// SIGNAL DEFINITIONS & STANDARDIZATION
// ============================================================================

// Signal type: 1=Buy, 0=Neutral, -1=Sell
// Used consistently across all indicators for easy aggregation

// @function Generate RSI signal
// @param rsi RSI value
// @param overbought RSI overbought threshold (default: 70)
// @param oversold RSI oversold threshold (default: 30)
// @returns Signal: 1 (buy), 0 (neutral), -1 (sell)
export rsiSignal(series float rsi, simple float overbought = 70, simple float oversold = 30) =>
    if rsi > overbought
        -1  // Sell signal
    else if rsi < oversold
        1   // Buy signal
    else
        0   // Neutral

// @function Generate MACD signal
// @param macdLine MACD line
// @param signalLine MACD signal line
// @param histogram MACD histogram
// @returns Signal: 1 (buy), 0 (neutral), -1 (sell)
export macdSignal(series float macdLine, series float signalLine, series float histogram) =>
    if macdLine > signalLine and histogram > 0
        1   // Buy signal
    else if macdLine < signalLine and histogram < 0
        -1  // Sell signal
    else
        0   // Neutral

// @function Generate Stochastic signal
// @param k Stochastic K line
// @param d Stochastic D line
// @param overbought Overbought threshold (default: 80)
// @param oversold Oversold threshold (default: 20)
// @returns Signal: 1 (buy), 0 (neutral), -1 (sell)
export stochSignal(series float k, series float d, simple float overbought = 80, simple float oversold = 20) =>
    if k < oversold and k > d
        1   // Buy signal (K crosses above D from oversold)
    else if k > overbought and k < d
        -1  // Sell signal (K crosses below D from overbought)
    else if k > overbought
        -1  // Sell signal (overbought)
    else if k < oversold
        1   // Buy signal (oversold)
    else
        0   // Neutral

// @function Generate Moving Average signal
// @param price Current price
// @param fastMA Fast moving average (e.g., EMA10)
// @param slowMA Slow moving average (e.g., EMA20)
// @returns Signal: 1 (buy), 0 (neutral), -1 (sell)
export maSignal(series float price, series float fastMA, series float slowMA) =>
    if fastMA > slowMA and price > fastMA
        1   // Buy signal
    else if fastMA < slowMA and price < fastMA
        -1  // Sell signal
    else
        0   // Neutral

// @function Generate divergence signal
// @param bullishDiv Bullish divergence detected
// @param bearishDiv Bearish divergence detected
// @returns Signal: 1 (buy), 0 (neutral), -1 (sell)
export divergenceSignal(bool bullishDiv, bool bearishDiv) =>
    if bullishDiv
        1   // Buy signal
    else if bearishDiv
        -1  // Sell signal
    else
        0   // Neutral

// ============================================================================
// SIGNAL AGGREGATION & FILTERING
// ============================================================================

// @function Calculate confluence score from signal array
// @param signals Array of signals (1, 0, -1)
// @returns Confluence score: range from -n to +n
export confluenceScore(array<int> signals) =>
    score = 0
    for sig in signals
        score += sig
    score

// @function Get consensus signal from multiple signals
// @param signals Array of signals
// @returns Consensus: 1 (buy), 0 (neutral), -1 (sell)
export consensusSignal(array<int> signals) =>
    if array.size(signals) == 0
        0
    else
        score = confluenceScore(signals)
        if score > 0
            1
        else if score < 0
            -1
        else
            0

// @function Filter signal by confirmation
// @param signal Input signal
// @param confirmationCount Number of consecutive confirming signals needed
// @returns Filtered signal (returns na if not confirmed)
export confirmedSignal(series int signal, simple int confirmationCount = 2) =>
    if barstate.isconfirmed
        signal
    else
        na

// ============================================================================
// SIGNAL STRENGTH & CERTAINTY
// ============================================================================

// @function Calculate signal strength (0-100%)
// @param signals Array of signals
// @returns Strength percentage (0-100)
export signalStrength(array<int> signals) =>
    if array.size(signals) == 0
        0
    else
        score = confluenceScore(signals)
        maxScore = array.size(signals)
        strength = math.abs(score) / maxScore * 100
        strength

// @function Get signal color for visualization
// @param signal Signal value (1, 0, -1)
// @param buyColor Color for buy signal
// @param sellColor Color for sell signal
// @param neutralColor Color for neutral signal
// @returns Color based on signal
export signalColor(int signal, color buyColor = color.new(color.green, 0), color sellColor = color.new(color.red, 0), color neutralColor = color.new(color.gray, 70)) =>
    if signal == 1
        buyColor
    else if signal == -1
        sellColor
    else
        neutralColor

// ============================================================================
// SIGNAL TREND ANALYSIS
// ============================================================================

// @function Check if signal is trending (consecutive matching signals)
// @param signals Array of recent signals
// @param minLength Minimum length for trend confirmation
// @returns True if trending
export isTrendingSignal(array<int> signals, simple int minLength = 3) =>
    if array.size(signals) < minLength
        false
    else
        lastSignal = array.get(signals, array.size(signals) - 1)
        trendCount = 0
        for i = 1 to math.min(minLength, array.size(signals))
            idx = array.size(signals) - i
            if array.get(signals, idx) == lastSignal
                trendCount += 1
        trendCount >= minLength

// @function Get signal momentum (rate of signal change)
// @param currentSignal Current signal
// @param previousSignal Previous signal
// @returns Momentum: positive (strengthening), negative (weakening), 0 (no change)
export signalMomentum(int currentSignal, int previousSignal) =>
    if currentSignal == previousSignal
        0
    else if (currentSignal > previousSignal)
        1   // Signal strengthening (e.g., neutral to buy, or sell to neutral)
    else
        -1  // Signal weakening

// ============================================================================
// SIGNAL ALERT CONDITIONS
// ============================================================================

// @function Check for signal crossover (change from one signal to another)
// @param currentSignal Current bar signal
// @param previousSignal Previous bar signal
// @returns True if signal has changed
export isSignalCrossover(int currentSignal, int previousSignal) =>
    currentSignal != previousSignal

// @function Check for buy signal trigger
// @param signal Current signal
// @returns True if buy signal detected
export isBuySignal(int signal) =>
    signal == 1

// @function Check for sell signal trigger
// @param signal Current signal
// @returns True if sell signal detected
export isSellSignal(int signal) =>
    signal == -1

// @function Generate alert message
// @param signal Signal value
// @param symbol Trading symbol
// @param timeframe Current timeframe
// @returns Alert message string
export alertMessage(int signal, simple string symbol = "", simple string timeframe = "") =>
    signalType = signal == 1 ? "BUY" : signal == -1 ? "SELL" : "NEUTRAL"
    symbolStr = symbol != "" ? " " + symbol : ""
    tfStr = timeframe != "" ? " @ " + timeframe : ""
    "[" + signalType + "]" + symbolStr + tfStr

Overview

CommonSignals normalizes trade directions across diverse indicators into consistent integer values: 1 for buy, 0 for neutral, and -1 for sell. Exported routines assess market conditions using relative strength index thresholds, moving average convergence divergence crossovers, stochastic oscillator levels, moving average trend filters, and divergence detections. Designed to simplify signal aggregation and confluence scoring across indicators, it provides reusable building blocks without plotting standalone visual elements on charts.

Details

Published by

Yavuz365 on GitHub

Draws

Library (no plots)

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.

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

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

PositionSizing

by iamrichardD
57 stars

This Pine Script v6 library calculates trade position sizes and provides risk management functions for external scripts. It computes position sizes from account equity, percentage risk, and stop-loss distance, and offers dynamic sizing adjustments based on vol

Library v6
Updated 1 year ago · Apache-2.0 GitHub repository of PositionSizing

Chart Patterns

by deepentropy
13 stars

Chart Patterns is a Pine Script v6 library designed to scan for and render technical chart patterns directly on the price chart. It defines custom user-defined types to configure scanning parameters, such as Zigzag pivot offsets, error ratios, flat ratios, and

Library v6 Repaints
Updated 6 months ago · MIT GitHub repository of Chart Patterns

AuthLib

by alboogycOdR
6 stars

AuthLib is a Pine Script utility library providing access control and state management structures for technical indicators. It checks callers against a hardcoded array of authorized TradingView usernames before executing operations. The library exports user-de

Library v5 SMC / ICT / price actionSessions & time
Updated 7 months ago · None stated GitHub repository of AuthLib

WebhookMessageLibrary

by TradersPost
6 stars

WebhookMessageLibrary is a helper library designed to construct structured JSON payload messages for automated trading integrations like TradersPost. It defines custom exported types and constants for trade actions, market sentiments, quantities, limit prices,

Library v5
Updated 1 year ago · None stated GitHub repository of WebhookMessageLibrary

PineDraw

by 345-strategies
5 stars

PineDraw is a Pine Script v6 library that provides object primitives for drawing and updating price levels on the chart. It enables indicators and strategies to maintain lines, boxes, and labels in place by updating existing objects instead of deleting and rec

Library v6 Support & resistance
Updated 4 days ago · MPL-2.0 GitHub repository of PineDraw

More libraries

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers