PSAR X
betaDescription
This is my working and (i think) correct interpretation of 'PSAR X' indicator on TradingView made by RafaelZioni.
I will upgrade it into CMD soon.
HaasScript
--Haas interpretation author: HashSwingBagHolder
--Inspired by: 'PSAR X' on TV by RafaelZioni
start = 0.2
increment = 0.2
maximum = 0.8
len = 14
off= 0
dev= 1.9
OptimizedForInterval(0,
function()
function PSAR(start, increment, maximum, src, len, off, dev)
function pine_linreg(src, len , offset)
intercept = LINEARREG(src, len, LR_Intercept)
slope = LINEARREG(src, len, LR_Slope)
return intercept + slope * (len - 1 - offset)
end
bar_index = Load('bar_index', 0)
Save('bar_index', bar_index + 1)
close = ClosePrices()
high = HighPrices()
low = LowPrices()
c = close
psar = SAR(high, low, increment, maximum)
cp = psar
lreg = pine_linreg(cp, len, off)
lreg_x = pine_linreg(cp, len, off+1)
b = bar_index
s = lreg - lreg_x
intr = lreg - b*s
dS = 0.0
for i=1 , len do
dS = dS + Pow(cp[i]-(s*(b-i)+intr), 2)
end
de = Sqrt(dS/(len))
up = (-de*dev) + psar
down= (de*dev) + psar
prev_up_t = Load('prev_up_t', c)
prev_down_t = Load('prev_down_t', c)
up_t = c[2] > prev_up_t and Max(up, prev_up_t) or up
down_t = c[2] < prev_down_t and Min(down, prev_down_t) or down
Save('prev_up_t', up_t)
Save('prev_down_t', down_t)
prev_trend= Load('prev_trend', nil)
trend = c > prev_down_t and 1 or c < prev_up_t and -1 or (prev_trend != nil and prev_trend or 1)
Save('prev_trend', trend)
r_line = trend ==1 and up_t or down_t
return r_line
end
r_line = PSAR(start, increment, maximum, c, len, off, dev)
Plot(0,"r_line1",r_line)
end
)
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!