Psychological Line (PSY)
Summary
Psychological Line (PSY) measures the percentage of bars in a trailing window that closed strictly higher than the previous bar. Bounded in [0, 100], it tracks short-term buying sentiment: readings above 75 are commonly treated as overbought and readings below 25 as oversold.
Chart
Chart metadata i
Inputs
inReal:positive·negative·zero
Outputs
outReal:line·zero·positive·levels: 25, 75
Formula
with = optInTimePeriod.
Notes
- A flat bar (
x[i] == x[i-1]) is not counted as an up bar. - Because each comparison uses the previous bar, the first output requires
optInTimePeriod + 1input values.
Inputs
inReal— Source price series
Outputs
outReal— Psychological Line value in [0, 100]
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 12 | 1–100000 | Number of trailing bar-to-bar changes counted |
Properties
Numerical Stability: Start-Independent
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ☐ Uses Transcendental |
Example
C
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double series[252]; /* your data, oldest first */
double out[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_PSY( 0, n - 1, series, 12, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d: [%.4f, ..., %.4f]\n", outNBElement, outBegIdx, out[0], out[outNBElement - 1] );Rust
use ta_lib::Core;
let series = vec![0.0; 252]; // your data, oldest first
let mut out = vec![0.0; 252];
let core = Core::new();
let range = core.psy(0, series.len() - 1, &series, 12, &mut out)?;
println!("{} values from bar {}: [{:.4}, ..., {:.4}]", range.count, range.beg_idx, out[0], out[range.count - 1]);Java
import io.github.talib.Core;
import io.github.talib.OutRange;
import java.util.Locale;
double[] series = new double[252]; // your data, oldest first
double[] out = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.psy(0, series.length - 1, series, 12, out);
System.out.printf(Locale.ROOT, "%d values from bar %d: [%.4f, ..., %.4f]%n", r.count(), r.begIdx(), out[0], out[r.count() - 1]);C#
using System;
using TALib;
var series = new double[252]; // your data, oldest first
var outReal = new double[252];
var core = Core.Default;
OutRange r = core.Psy(0, series.Length - 1, series, 12, outReal);
Console.WriteLine(FormattableString.Invariant($"{r.Count} values from bar {r.BegIdx}: [{outReal[0]:F4}, ..., {outReal[r.Count - 1]:F4}]"));TypeScript
import { psy } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, values } = psy(series, { timePeriod: 12 });
console.log(values.length + ' values from bar ' + begIdx + ': [' + values[0]?.toFixed(4) + ', ..., ' + values[values.length - 1]?.toFixed(4) + ']');Go
import (
"fmt"
"log"
talib "ta-lib.github.io/go"
)
series := make([]float64, 252) // your data, oldest first
out := make([]float64, 252)
core := talib.NewCore()
r, err := core.PSY(0, len(series)-1, series, 12, out)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d values from bar %d: [%.4f, ..., %.4f]\n", r.NBElement, r.BegIdx, out[0], out[r.NBElement-1])Implementation
Added in 0.8.4.
TA-Lib Definition: psy.c · psy.yaml
| Native | File |
|---|---|
| C | ta_PSY.c |
| Rust | psy.rs |
| Java | Core_PSY.java |
| C# | Core_PSY.cs |
| TypeScript | psy.ts |
| Go | psy.go |
Python: talib.PSY, see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
Psychological Line, PSL