TradingView
HPotter
Mar 6, 2018 6:01 AM

Psychological line 

E-mini S&P 500 FuturesCME

Description

Psychological line (PSY), as an indicator, is the ratio of the number of
rising periods over the total number of periods. It reflects the buying
power in relation to the selling power.

If PSY is above 50%, it indicates that buyers are in control. Likewise,
if it is below 50%, it indicates the sellers are in control. If the PSY
moves along the 50% area, it indicates balance between the buyers and
sellers and therefore there is no direction movement for the market.

Release Notes

Move to v5
Comments
juliestan0328
Hello! How to add PSY line?
HPotter
@juliestan0328, Add to favorite and looking for in your indicators list
KNMG
HPotter, Thank you for the Script.
I am getting the below error for the line mentioned.. could you please help to fix..

xPSY = math.sum(close > close[1],Length) / Length * 100
Compilation error. Line 21: Cannot call 'math.sum' with argument 'source'='call 'operator >' (series bool)'. An argument of 'series bool' type was used but a 'series float' is expected
HPotter
@Ramzan_Salman, You can`t use condition in the sum function. Only float values. It should be like: xPSY = math.sum(close,Length) / Length * 100
KNMG
@HPotter, Thank you. I have copied exact function you have given "xPSY = sum(close > close[1],Length) / Length * 100" it throws invalid sum.. then i used math.sum.. both fail..
moneygoon
//@version=5
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 06/03/2018
// Psychological line (PSY), as an indicator, is the ratio of the number of
// rising periods over the total number of periods. It reflects the buying
// power in relation to the selling power.
//
// If PSY is above 50%, it indicates that buyers are in control. Likewise,
// if it is below 50%, it indicates the sellers are in control. If the PSY
// moves along the 50% area, it indicates balance between the buyers and
// sellers and therefore there is no direction movement for the market.
////////////////////////////////////////////////////////////
indicator(title='Psychological line')
Length = input.int(20, minval=1)
xPSY = math.sum(close > close[1], Length) / Length * 100
clr = xPSY >= 50 ? color.green : color.red
p1 = plot(50, color=color.new(color.black, 0), title='0')
p2 = plot(xPSY, color=color.new(color.blue, 0), title='PSY')
fill(p1, p2, color=clr, transp=90)

it got converted to version 5 but when i try to add it to chart
it gives the following error Cannot call 'math.sum' with argument 'source'='call 'operator >' (series bool)'. An argument of 'series bool' type was used but a 'series float' is expected. for the following line xPSY = math.sum(close > close[1], Length) / Length * 100

how do i fix it
PS: I am new to coding.
HPotter
@moneygoon, The math.sum make sum numbers but close > close[1] returns bool value true or false. You should make sum yourself for get this value. I made update the script, you can see how I am do that.
moneygoon
@HPotter, thankyou very much really appreciate it.
HPotter
@moneygoon, You are welcome.
Stenio_ASAS
Hello! How can I convert this code into Pine Script version 5?
Thanks a lot!
More