0% found this document useful (0 votes)
23 views4 pages

p indicator

This document is a Pine Script code for a trading indicator named 'P indicator' that overlays on price charts. It includes various inputs for calculating moving averages, ATR, and signals for buy/sell actions based on crossings of price and moving averages. The script also implements alerts for significant price movements and visual indicators on the chart.

Uploaded by

katrin.k1394
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

p indicator

This document is a Pine Script code for a trading indicator named 'P indicator' that overlays on price charts. It includes various inputs for calculating moving averages, ATR, and signals for buy/sell actions based on crossings of price and moving averages. The script also implements alerts for significant price movements and visual indicators on the chart.

Uploaded by

katrin.k1394
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

//@version=5

indicator('P indicator', 'P indicator', overlay=true,timeframe = '',timeframe_gaps


= true)
src = input(hl2, title='Source')
Periods = input(title='ATR Length', defval=3)
Multiplier = input.float(title='ATR Multiplier', step=0.1, defval=1.0)
mav = input.string(title='Moving Average Type', defval='VAR', options=['SMA',
'EMA', 'WMA', 'TMA', 'VAR', 'WWMA', 'ZLEMA', 'TSF'])
length = input.int(3, 'Moving Average Length', minval=1)
changeATR = input(title='Change ATR Calculation Method ?', defval=false)
showsupport = input(title='Show Moving Average?', defval=true)
showsignalsk = input(title='Show Crossing Signals?', defval=true)
showsignalsc = input(title='Show Price/Pmax Crossing Signals?', defval=false)
highlighting = input(title='Highlighter On/Off ?', defval=true)
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
valpha = 2 / (length + 1)
vud1 = src > src[1] ? src - src[1] : 0
vdd1 = src < src[1] ? src[1] - src : 0
vUD = math.sum(vud1, 9)
vDD = math.sum(vdd1, 9)
vCMO = nz((vUD - vDD) / (vUD + vDD))
VAR = 0.0
VAR := nz(valpha * math.abs(vCMO) * src) + (1 - valpha * math.abs(vCMO)) *
nz(VAR[1])
wwalpha = 1 / length
WWMA = 0.0
WWMA := wwalpha * src + (1 - wwalpha) * nz(WWMA[1])
zxLag = length / 2 == math.round(length / 2) ? length / 2 : (length - 1) / 2
zxEMAData = src + src - src[zxLag]
ZLEMA = ta.ema(zxEMAData, length)
lrc = ta.linreg(src, length, 0)
lrc1 = ta.linreg(src, length, 1)
lrs = lrc - lrc1
TSF = ta.linreg(src, length, 0) + lrs
getMA(src, length) =>
ma = 0.0
if mav == 'SMA'
ma := ta.sma(src, length)
ma

if mav == 'EMA'
ma := ta.ema(src, length)
ma

if mav == 'WMA'
ma := ta.wma(src, length)
ma

if mav == 'TMA'
ma := ta.sma(ta.sma(src, math.ceil(length / 2)), math.floor(length / 2) +
1)
ma

if mav == 'VAR'
ma := VAR
ma
if mav == 'WWMA'
ma := WWMA
ma

if mav == 'ZLEMA'
ma := ZLEMA
ma

if mav == 'TSF'
ma := TSF
ma
ma

MAvg = getMA(src, length)


longStop = MAvg - Multiplier * atr
longStopPrev = nz(longStop[1], longStop)
longStop := MAvg > longStopPrev ? math.max(longStop, longStopPrev) : longStop
shortStop = MAvg + Multiplier * atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := MAvg < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ?
-1 : dir
PMax = dir == 1 ? longStop : shortStop
//plot(showsupport ? MAvg : na, color=color.new(#0585E1, 0), linewidth=2,
title='Moving Avg Line')
//pALL = plot(PMax, color=color.new(color.red, 0), linewidth=2, title='PMax')
alertcondition(ta.cross(MAvg, PMax), title='Cross Alert', message='PMax - Moving
Avg Crossing!')
alertcondition(ta.crossover(MAvg, PMax), title='Crossover Alarm', message='Moving
Avg BUY SIGNAL!')
alertcondition(ta.crossunder(MAvg, PMax), title='Crossunder Alarm', message='Moving
Avg SELL SIGNAL!')
alertcondition(ta.cross(src, PMax), title='Price Cross Alert', message='PMax -
Price Crossing!')
alertcondition(ta.crossover(src, PMax), title='Price Crossover Alarm',
message='PRICE OVER PMax - BUY SIGNAL!')
alertcondition(ta.crossunder(src, PMax), title='Price Crossunder Alarm',
message='PRICE UNDER PMax - SELL SIGNAL!')
buySignalk = ta.crossover(MAvg, PMax)
plotshape(buySignalk and showsignalsk ? PMax * 0.995 : na, title='Buy', text='Buy',
location=location.belowbar, style=shape.labelup, size=size.tiny,
color=color.new(color.green, 0), textcolor=color.new(color.white, 0))
sellSignallk = ta.crossunder(MAvg, PMax)
plotshape(sellSignallk and showsignalsk ? PMax * 1.005 : na, title='Sell',
text='Sell', location=location.abovebar, style=shape.labeldown, size=size.tiny,
color=color.new(color.red, 0), textcolor=color.new(color.white, 0))
buySignalc = ta.crossover(src, PMax)
// plotshape(buySignalc and showsignalsc ? PMax*0.995 : na, title="Buy",
text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny,
color=#0F18BF, textcolor=color.white, transp=0)
sellSignallc = ta.crossunder(src, PMax)
// plotshape(sellSignallc and showsignalsc ? PMax*1.005 : na, title="Sell",
text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny,
color=#0F18BF, textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0,
display=display.none)
longFillColor = highlighting ? MAvg > PMax ? color.green : na : na
shortFillColor = highlighting ? MAvg < PMax ? color.red : na : na
//fill(mPlot, pALL, title='UpTrend Highligter', color=color.new(longFillColor,90))
//fill(mPlot, pALL, title='DownTrend Highligter',
color=color.new(shortFillColor,90))

fast_length = input(title='Fast Length', defval=12)


slow_length = input(title='Slow Length', defval=26)
srcc = input(title='Source', defval=close)
signal_length = input.int(title='Signal Smoothing', minval=1, maxval=50, defval=9)
sma_source = input(title='Simple MA(Oscillator)', defval=true)
sma_signal = input(title='Simple MA(Signal Line)', defval=false)
//sar
start = input(0.02)
increment = input(0.03)
maximum = input(0.3)
var bool uptrend = na
var float EP = na
var float SAR = na
var float AF = start
var float nextBarSAR = na
if bar_index > 0
firstTrendBar = false
SAR := nextBarSAR
if bar_index == 1
float prevSAR = na
float prevEP = na
lowPrev = low[1]
highPrev = high[1]
closeCur = close
closePrev = close[1]
if closeCur > closePrev
uptrend := true
EP := high
prevSAR := lowPrev
prevEP := high
prevEP
else
uptrend := false
EP := low
prevSAR := highPrev
prevEP := low
prevEP
firstTrendBar := true
SAR := prevSAR + start * (prevEP - prevSAR)
SAR
if uptrend
if SAR > low
firstTrendBar := true
uptrend := false
SAR := math.max(EP, high)
EP := low
AF := start
AF
else
if SAR < high
firstTrendBar := true
uptrend := true
SAR := math.min(EP, low)
EP := high
AF := start
AF
if not firstTrendBar
if uptrend
if high > EP
EP := high
AF := math.min(AF + increment, maximum)
AF
else
if low < EP
EP := low
AF := math.min(AF + increment, maximum)
AF
if uptrend
SAR := math.min(SAR, low[1])
if bar_index > 1
SAR := math.min(SAR, low[2])
SAR
else
SAR := math.max(SAR, high[1])
if bar_index > 1
SAR := math.max(SAR, high[2])
SAR
nextBarSAR := SAR + AF * (EP - SAR)
nextBarSAR

// Calculating
fast_ma = sma_source ? ta.sma(srcc, fast_length) : ta.ema(srcc, fast_length)
slow_ma = sma_source ? ta.sma(srcc, slow_length) : ta.ema(srcc, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal

color1 = MAvg>PMax ? color.green : color.red

plotcandle(open,high,low,close,color=color1,wickcolor=color1,bordercolor=color1)

You might also like