RAVI Pivot Points High Low Breakout

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7
At a glance
Powered by AI
The document describes a Pivot Points High Low Breakout indicator that identifies significant price levels based on pivot highs and lows. It determines patterns like higher highs and lower lows to identify potential breakouts.

The Pivot High and Pivot Low indicators identify significant high and low prices based on a look back period. They are used to determine patterns in price action and potential support and resistance levels.

Higher Highs are prices above the previous Pivot High. Lower Highs are prices below the previous Pivot High. Similarly, Higher Lows are above the previous Pivot Low and Lower Lows are below it. The indicators use logic to determine when each pattern occurs.

//@version=4

study(title="RAVI Pivot Points High Low Breakout ", shorttitle="PP Breakout", overlay=true,
max_labels_count=500)

//INPUTS

gr1="Source / Length Left / Length Right"

srcH = input(high, title="Pivot High", inline="Pivot High", group=gr1)

leftLenH = input(title="", type=input.integer, defval=3, minval=1, inline="Pivot High",group=gr1)

rightLenH = input(title="/", type=input.integer, defval=3, minval=1, inline="Pivot High",group=gr1)

colorH = input(title="", defval=color.new(#0000FF,20), inline="Pivot High",group=gr1)

srcL = input(low, title="Pivot Low ", inline="Pivot Low", group=gr1)

leftLenL = input(title="", type=input.integer, defval=3, minval=1, inline="Pivot Low", group=gr1)

rightLenL = input(title="/", type=input.integer, defval=3, minval=1, inline="Pivot Low",group=gr1)

colorL = input(title="", defval=color.new(#FF00FF,20), inline="Pivot Low",group=gr1)

gr2="Options"

ShowHHLL = input(true, title="Show HH, LL, LH, HL markers on candles",group=gr2)

ShowPrice = input(true, title="Show HH, LL, LH, HL price on candles",group=gr2)

ShowSRLevels = input(true, title="Show S/R Level Extensions",group=gr2)

maxLvlLen = input(0, minval=0, title="Maximum S/R Level Extension Length (0 = Max)",group=gr2)

ShowChannel = input(false, title="Show Levels as a Fractal Chaos Channel",group=gr2)

ShowFB = input(true, title="Show fractal Break out/down symbols",group=gr2)

// Get High and Low Pivot Points

ph = pivothigh(srcH, leftLenH, rightLenH)

pl = pivotlow(srcL, leftLenL, rightLenL)

// Higher Highs, Lower Highs, Higher Lows, Lower Lows

valuewhen_1 = valuewhen(ph, srcH[rightLenH], 1)


valuewhen_2 = valuewhen(ph, srcH[rightLenH], 0)

higherhigh = na(ph) ? na : valuewhen_1 < valuewhen_2 ? ph : na

valuewhen_3 = valuewhen(ph, srcH[rightLenH], 1)

valuewhen_4 = valuewhen(ph, srcH[rightLenH], 0)

lowerhigh = na(ph) ? na : valuewhen_3 > valuewhen_4 ? ph : na

valuewhen_5 = valuewhen(pl, srcL[rightLenL], 1)

valuewhen_6 = valuewhen(pl, srcL[rightLenL ], 0)

higherlow = na(pl) ? na : valuewhen_5 < valuewhen_6 ? pl : na

valuewhen_7 = valuewhen(pl, srcL[rightLenL], 1)

valuewhen_8 = valuewhen(pl, srcL[rightLenL ], 0)

lowerlow = na(pl) ? na : valuewhen_7 > valuewhen_8 ? pl : na

drawLabel(_offset, _pivot, _style, _yloc, _color, _text) =>

if not na(_pivot)

label.new(bar_index[_offset], _pivot, text = _text+tostring(_pivot, format.mintick)+"]",


style=_style, yloc=_yloc, color=_color, textcolor=_color)

drawLabel(rightLenH, ShowPrice ? higherhigh : na, label.style_none, yloc.abovebar, colorH, "[")

drawLabel(rightLenH, ShowPrice ? higherlow : na, label.style_none, yloc.belowbar, colorL, "[")

drawLabel(rightLenH, ShowPrice ? lowerhigh : na, label.style_none, yloc.abovebar, colorH, "[")

drawLabel(rightLenH, ShowPrice ? lowerlow : na, label.style_none, yloc.belowbar, colorL, "[")

plotshape(ShowHHLL ? higherhigh : na, title='HH', style=shape.triangledown,


location=location.abovebar, color=colorH, text="HH", textcolor=colorH, offset=-rightLenH)

plotshape(ShowHHLL ? higherlow : na, title='HL', style=shape.triangleup, location=location.belowbar,


color=colorL, text="HL", textcolor=colorL, offset=-rightLenH)

plotshape(ShowHHLL ? lowerhigh : na, title='LH', style=shape.triangledown,


location=location.abovebar, color=colorH, text="LH", textcolor=colorH, offset=-rightLenL)

plotshape(ShowHHLL ? lowerlow : na, title='LL', style=shape.triangleup, location=location.belowbar,


color=colorL, text="LL", textcolor=colorL, offset=-rightLenL)
//Count How many candles for current Pivot Level, If new reset.

countH = 0

countL = 0

countH := na(ph) ? nz(countH[1]) + 1 : 0

countL := na(pl) ? nz(countL[1]) + 1 : 0

pvtH = 0.0

pvtL = 0.0

pvtH := na(ph) ? pvtH[1] : srcH[rightLenH]

pvtL := na(pl) ? pvtL[1] : srcL[rightLenL]

HpC = pvtH != pvtH[1] ? na : colorH

LpC = pvtL != pvtL[1] ? na : colorL

// Show Levels if Selected

plot(ShowSRLevels and not ShowChannel and (maxLvlLen == 0 or countH < maxLvlLen) ? pvtH : na,
color=colorH, offset=-rightLenH , title="Top Levels
HH,LH",style=plot.style_line,linewidth=2,transp=0)

plot(ShowSRLevels and not ShowChannel and (maxLvlLen == 0 or countL < maxLvlLen) ? pvtL : na,
color=colorL, offset=-rightLenL , title="Bottom Levels
LL,HL",style=plot.style_line,linewidth=2,transp=0)

// Show Levels as a Fractal Chaos Channel

plot(ShowSRLevels and ShowChannel ? pvtH : na, color=colorH, style=plot.style_stepline, title="Top


Chaos Channel",offset=-rightLenH)

plot(ShowSRLevels and ShowChannel ? pvtL : na, color=colorL, style=plot.style_stepline,


title="Bottom Chaos Channel", offset=-rightLenL)

// // Add Optional Fractal Break Alerts

buy = false

sell = false

buy := close>pvtH and open<=pvtH

sell := close<pvtL and open>=pvtL


plotshape(ShowFB and buy?1:na, title="Breakout Bar", text="B", style=shape.triangleup, location
=location.belowbar, color=#004d40, textcolor=#004d40, size=size.small, transp=0)

plotshape(ShowFB and sell?-1:na, title="Breakdown Bar",text="S",


style=shape.triangledown,location=location.abovebar, color=#b71c1c, textcolor=#b71c1c,
size=size.small, transp=0)

// Alerts

alertcondition(buy or sell,title="Fractal Break Arrow",message="Alert")

alertcondition(buy,title="Fractal Break Long",message="Long")

alertcondition(sell,title="Fractal Break Short",message="Short")

//candle Volume

length1 = input(20 , title="length")

lowV = input(0.5, title="Low Volume")

highV = input(2.0, title="High Volume")

paintCandle = input(false,

title="paint the candles entirely?",

tooltip="to be visible you will have to right click on the candlesticks on the chart, go in visual order,
and click send to bottom")

avrg = sma(volume, length1)

highVol = avrg * highV

lowVol = avrg * lowV

color_volume = if volume >= highVol and close > open

color_volume = #004d40

if volume >= lowVol and volume < highVol and close > open

color_volume := #00FF00

if volume < lowVol and close > open

color_volume := #b2dfdb
if volume >= highVol and close < open

color_volume := #b71c1c

if volume >= lowVol and volume < highVol and close < open

color_volume := #FF00FF

if volume < lowVol and close < open

color_volume := #ef9a9a

barcolor(color_volume, title="Bar Colors")

o1 = paintCandle ? open : na

h1 = paintCandle ? high : na

l1 = paintCandle ? low : na

c1 = paintCandle ? close : na

//BB Blast

src = close, len = input(9, minval=1, title="Length")

up = rma(max(change(src), 0), len)

down = rma(-min(change(src), 0), len)

rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

wmaLength = input(21, title="WMA")

emaLength = input(3, title="EMA")

wma = wma(rsi, wmaLength)

ema = ema(rsi, emaLength)

source = input(close)

MAType = input(title="Moving Average Type", defval="sma", options=["ema", "sma", "hma", "rma",


"vwma", "wma"])

Length = input(20, step=10)

StdDev = input(2, step=0.5, minval=0.5)


f_getMovingAverage(source, MAType, length)=>

ma1 = sma(source, length)

if(MAType == "ema")

ma1 := ema(source,length)

if(MAType == "hma")

ma1 := hma(source,length)

if(MAType == "rma")

ma1 := rma(source,length)

if(MAType == "vwma")

ma1 := vwma(source,length)

if(MAType == "wma")

ma1 := wma(source,length)

ma1

f_getCustomBB(source,MAType,Length,StdDev)=>

ma1 = f_getMovingAverage(source, MAType, Length)

up1 = ma1 + stdev(source, Length)*StdDev

down1 = ma1 - stdev(source, Length)*StdDev

[ma1, up1, down1]

[ma1, up1, down1] = f_getCustomBB(source,MAType,Length,StdDev)

height=input(title="Arrow height",type=input.integer,defval=20)

arrowPlot = (rsi>60 and source>up1 and ema>wma )? 1:(rsi<40 and ema<wma and
down1>source )?-1:na

plotarrow(series=arrowPlot, colordown=color.red, colorup=color.green,maxheight=height,transp=0)

//bb

//HigherTimeFrame = period == '1' ? '5' : (period == '3' ? '5' : (period == '5' ? '15' : (period == '15' ?
'60' : (period == '30' ? '60' : (period == '45' ? '60' : (period == '60' ? '240' : (period == '120' ? '240' :
(period == '180' ? '240' : (period == '240' ? 'D' : (period == 'D' ? 'W' : 'W'))))))))))

HigherTimeFrame = input(title="Higher time frame", type= input.resolution, defval='60')


smooth = input(true, title = "Smoothing")

bblength = input(20, title="Length", minval=1)

sdtspm = input(2.0, title="Mult", minval=1.0)

basis = sma(close, bblength)

dev = sdtspm * stdev(close, bblength)

upper = basis + dev

lower = basis - dev

L1 = plot(upper, color = color.purple,title="BB Upper Band",transp=30)

L2 = plot(lower, color = color.purple,title="BB Lower Band",transp=50)

B1=plot(basis, color = color.purple,title="BB Mid Band",transp=30)

fill(L1, B1, color = color.purple, transp=85)

altmid = smooth ? sma(security(syminfo.tickerid, HigherTimeFrame, basis[1], lookahead = true), 8) :


security(syminfo.tickerid, HigherTimeFrame, basis[1], lookahead = true)

altupper = smooth ? sma(security(syminfo.tickerid, HigherTimeFrame, upper[1], lookahead = true),


8) : security(syminfo.tickerid, HigherTimeFrame, upper[1], lookahead = true)

altlower = smooth ? sma(security(syminfo.tickerid, HigherTimeFrame, lower[1], lookahead = true), 8)


: security(syminfo.tickerid, HigherTimeFrame, lower[1], lookahead = true)

B2=plot(altmid, color = color.blue, title="BB Alt Mid Band",linewidth=2,transp=0)

LA1 = plot(altupper, color = color.blue, title="BB Alt Upper Band",linewidth=2,transp=0)

LA2 = plot(altlower, color = color.blue, title="BB Alt Lower Band",linewidth=2,transp=0)

fill(LA1,B2, color = color.lime, transp=95)

You might also like