Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
25 views6 pages

Indicator

This document is a Pine Script code for a trading indicator that combines various technical analysis tools including VWAP, SMA, EMA, and CPR levels. It allows users to customize settings such as the source for VWAP calculations, display options for various moving averages, and the visibility of support and resistance levels. The script is designed to plot these indicators on a trading chart for better market analysis.

Uploaded by

Muraw Amarjeet
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)
25 views6 pages

Indicator

This document is a Pine Script code for a trading indicator that combines various technical analysis tools including VWAP, SMA, EMA, and CPR levels. It allows users to customize settings such as the source for VWAP calculations, display options for various moving averages, and the visibility of support and resistance levels. The script is designed to plot these indicators on a trading chart for better market analysis.

Uploaded by

Muraw Amarjeet
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/ 6

//@version=5

vwapAnchor = input.string("Session", "VWAP Anchor", options=["Session", "Week",


"Month", "Quarter", "Year"])
vwapSrc = input(hlc3, "VWAP Source")
showVWAP = input(true, "Show VWAP")
showVWAPBands = input(true, "Show VWAP Bands")
vwapStdevMult = input.float(2.0, "VWAP Stdev Multiplier", step=0.1)
pivotWidth = input.int(2, "Pivot Lines Width", minval=1)
showCPR = input(true, "Show CPR Levels")
showSR = input(true, "Show S/R Levels")
showPrevCPR = input(true, "Show Previous CPR", group="CPR Settings")
showCurrentCPR = input(true, "Show Current CPR", group="CPR Settings")
showNextCPR = input(true, "Show Next CPR", group="CPR Settings")
cprLineLength = input.int(3, "CPR Line Length (days)", minval=1, maxval=7,
group="CPR Settings")
showSR1to3 = input(true, "Show S/R 1-3")
showSR4to5 = input(false, "Show S/R 4-5")
cprColor = input.color(color.new(#4262ba, 0), "CPR Color", group="CPR Colors")
prevCprColor = input.color(color.new(#4262ba, 50), "Previous CPR Color", group="CPR
Colors")
nextCprColor = input.color(color.new(#4262ba, 30), "Next CPR Color", group="CPR
Colors")
tcColor = input.color(color.new(#fa8072, 0), "TC Color", group="CPR Colors")
prevTcColor = input.color(color.new(#fa8072, 50), "Previous TC Color", group="CPR
Colors")
nextTcColor = input.color(color.new(#fa8072, 30), "Next TC Color", group="CPR
Colors")
bcColor = input.color(color.new(#9ef2e8, 0), "BC Color", group="CPR Colors")
prevBcColor = input.color(color.new(#9ef2e8, 50), "Previous BC Color", group="CPR
Colors")
nextBcColor = input.color(color.new(#9ef2e8, 30), "Next BC Color", group="CPR
Colors")
rColor = input.color(color.new(#e91e63, 0), "Resistance Color")
sColor = input.color(color.new(#26a69a, 0), "Support Color")
showSMA9 = input(true, "Show 9 SMA")
showSMA20 = input(true, "Show 20 SMA")
showEMA50 = input(true, "Show 50 EMA")
sma9Color = input.color(color.purple, "9 SMA Color")
sma20Color = input.color(color.orange, "20 SMA Color")
ema50Color = input.color(color.teal, "50 EMA Color")
showFractals = input(true, "Show Fractal Chaos Bands")
jawColor = input.color(color.new(color.blue, 85), "Jaw Color")
teethColor = input.color(color.new(color.red, 85), "Teeth Color")
lipsColor = input.color(color.new(color.green, 85), "Lips Color")
showPD = input(true, "Show Previous Day Pivots")
showPW = input(true, "Show Previous Week Pivots")
showPM = input(true, "Show Previous Month Pivots")
pdColor = input.color(color.new(color.blue, 70), "PD Color")
pwColor = input.color(color.new(color.purple, 70), "PW Color")
pmColor = input.color(color.new(color.orange, 70), "PM Color")
f_drawLineX(_x1, _y1, _x2, _y2, _xloc, _extend, _color, _style, _width) =>
var id = line.new(_x1, _y1, _x2, _y2, _xloc, _extend, _color, _style, _width)
if _y1 > 0 and _y2 > 0
line.set_xy1(id, _x1, _y1)
line.set_xy2(id, _x2, _y2)
line.set_color(id, _color)
else
line.set_xy1(id, _x1, close)
line.set_xy2(id, _x2, close)
line.set_color(id, #ffffff00)
f_drawLabelX(_x, _y, _text, _xloc, _yloc, _color, _style, _textcolor, _size,
_textalign, _tooltip) =>
var id = label.new(_x, _y, _text, _xloc, _yloc, _color, _style, _textcolor,
_size, _textalign, _tooltip)
label.set_text(id, _text)
label.set_tooltip(id, _tooltip)
if _y > 0
label.set_xy(id, _x, _y)
label.set_textcolor(id, _textcolor)
else
label.set_xy(id, _x, close)
label.set_textcolor(id, #00000000)
f_vwap(src, isNewPeriod) =>
var float sumSrcVol = na
var float sumVol = na
var float sumSrcSrcVol = na
sumSrcVol := isNewPeriod ? src * volume : src * volume + sumSrcVol[1]
sumVol := isNewPeriod ? volume : volume + sumVol[1]
sumSrcSrcVol := isNewPeriod ? volume * math.pow(src, 2) : volume *
math.pow(src, 2) + sumSrcSrcVol[1]
_vwap = sumSrcVol / sumVol
variance = sumSrcSrcVol / sumVol - math.pow(_vwap, 2)
variance := variance < 0 ? 0 : variance
stDev = math.sqrt(variance)
[_vwap, _vwap + stDev * vwapStdevMult, _vwap - stDev * vwapStdevMult]
isNewPeriod = switch vwapAnchor
"Session" => ta.change(time("D"))
"Week" => ta.change(time("W"))
"Month" => ta.change(time("M"))
"Quarter" => ta.change(time("3M"))
"Year" => ta.change(time("12M"))
=> false
[vwapValue, vwapUpper, vwapLower] = f_vwap(vwapSrc, isNewPeriod)
htf_high = request.security(syminfo.tickerid, "D", high[1])
htf_low = request.security(syminfo.tickerid, "D", low[1])
htf_close = request.security(syminfo.tickerid, "D", close[1])
pivot = math.avg(htf_high, htf_low, htf_close)
bc = math.avg(htf_high, htf_low)
tc = 2 * pivot - bc
prev_htf_high = request.security(syminfo.tickerid, "D", high[2])
prev_htf_low = request.security(syminfo.tickerid, "D", low[2])
prev_htf_close = request.security(syminfo.tickerid, "D", close[2])
prev_pivot = math.avg(prev_htf_high, prev_htf_low, prev_htf_close)
prev_bc = math.avg(prev_htf_high, prev_htf_low)
prev_tc = 2 * prev_pivot - prev_bc
indicator("AIO [VWAP, SMA, EMA, FRACTAL, CPR, S/R by PredatorsAJ]", overlay=true,
max_lines_count=500, max_bars_back=5000)
// Next Day CPR (projected) - Using current day's range extended
next_htf_high = htf_high + (htf_high - htf_low) * 0.5
next_htf_low = htf_low - (htf_high - htf_low) * 0.5
next_htf_close = htf_close
next_pivot = math.avg(next_htf_high, next_htf_low, next_htf_close)
next_bc = math.avg(next_htf_high, next_htf_low)
next_tc = 2 * next_pivot - next_bc
s1 = pivot * 2 - htf_high
s2 = pivot - (htf_high - htf_low)
s3 = htf_low - 2 * (htf_high - pivot)
s4 = s3 - (htf_high - htf_low)
s5 = s4 - (htf_high - htf_low)
r1 = pivot * 2 - htf_low
r2 = pivot + (htf_high - htf_low)
r3 = htf_high + 2 * (pivot - htf_low)
r4 = r3 + (htf_high - htf_low)
r5 = r4 + (htf_high - htf_low)
// Previous Day Pivots
pd_high = request.security(syminfo.tickerid, "D", high[1])
pd_low = request.security(syminfo.tickerid, "D", low[1])
pd_close = request.security(syminfo.tickerid, "D", close[1])
pw_high = request.security(syminfo.tickerid, "W", high[1])
pw_low = request.security(syminfo.tickerid, "W", low[1])
pw_close = request.security(syminfo.tickerid, "W", close[1])
pm_high = request.security(syminfo.tickerid, "M", high[1])
pm_low = request.security(syminfo.tickerid, "M", low[1])
pm_close = request.security(syminfo.tickerid, "M", close[1])
sma9 = ta.sma(close, 9)
sma20 = ta.sma(close, 20)
ema50 = ta.ema(close, 50)
jaw = ta.sma(hl2, 13)
teeth = ta.sma(hl2, 8)
lips = ta.sma(hl2, 5)
current_time = time
days_in_ms = 86400000
time_x1 = current_time - days_in_ms * cprLineLength
time_x2 = current_time
time_x1_prev = current_time - days_in_ms * (cprLineLength + 1)
time_x2_prev = current_time - days_in_ms
time_x1_next = current_time + days_in_ms
time_x2_next = current_time + days_in_ms * (cprLineLength + 1)
plot(showVWAP ? vwapValue : na, "VWAP", color.blue, 2)
upperBand = plot(showVWAP and showVWAPBands ? vwapUpper : na, "VWAP Upper",
color.blue, 1)
lowerBand = plot(showVWAP and showVWAPBands ? vwapLower : na, "VWAP Lower",
color.blue, 1)
fill(upperBand, lowerBand, color.new(color.blue, 90), "VWAP Bands Fill")
if showCPR and showCurrentCPR
f_drawLineX(time_x1, pivot, time_x2, pivot, xloc.bar_time, extend.none,
cprColor, line.style_solid, pivotWidth)
f_drawLineX(time_x1, tc, time_x2, tc, xloc.bar_time, extend.none, tcColor,
line.style_dotted, pivotWidth)
f_drawLineX(time_x1, bc, time_x2, bc, xloc.bar_time, extend.none, bcColor,
line.style_dotted, pivotWidth)
if showCPR and showPrevCPR
f_drawLineX(time_x1_prev, prev_pivot, time_x2_prev, prev_pivot, xloc.bar_time,
extend.none, prevCprColor, line.style_solid, pivotWidth)
f_drawLineX(time_x1_prev, prev_tc, time_x2_prev, prev_tc, xloc.bar_time,
extend.none, prevTcColor, line.style_dotted, pivotWidth)
f_drawLineX(time_x1_prev, prev_bc, time_x2_prev, prev_bc, xloc.bar_time,
extend.none, prevBcColor, line.style_dotted, pivotWidth)
if showCPR and showNextCPR
f_drawLineX(time_x1_next, next_pivot, time_x2_next, next_pivot, xloc.bar_time,
extend.none, nextCprColor, line.style_solid, pivotWidth)
f_drawLineX(time_x1_next, next_tc, time_x2_next, next_tc, xloc.bar_time,
extend.none, nextTcColor, line.style_dotted, pivotWidth)
f_drawLineX(time_x1_next, next_bc, time_x2_next, next_bc, xloc.bar_time,
extend.none, nextBcColor, line.style_dotted, pivotWidth)
if showSR
if showSR1to3
f_drawLineX(time_x1, r1, time_x2, r1, xloc.bar_time, extend.none, rColor,
line.style_solid, pivotWidth)
f_drawLineX(time_x1, r2, time_x2, r2, xloc.bar_time, extend.none, rColor,
line.style_solid, pivotWidth)
f_drawLineX(time_x1, r3, time_x2, r3, xloc.bar_time, extend.none, rColor,
line.style_solid, pivotWidth)
f_drawLineX(time_x1, s1, time_x2, s1, xloc.bar_time, extend.none, sColor,
line.style_solid, pivotWidth)
f_drawLineX(time_x1, s2, time_x2, s2, xloc.bar_time, extend.none, sColor,
line.style_solid, pivotWidth)
f_drawLineX(time_x1, s3, time_x2, s3, xloc.bar_time, extend.none, sColor,
line.style_solid, pivotWidth)
if showSR4to5
f_drawLineX(time_x1, r4, time_x2, r4, xloc.bar_time, extend.none,
color.new(rColor, 50), line.style_solid, pivotWidth)
f_drawLineX(time_x1, r5, time_x2, r5, xloc.bar_time, extend.none,
color.new(rColor, 50), line.style_solid, pivotWidth)
f_drawLineX(time_x1, s4, time_x2, s4, xloc.bar_time, extend.none,
color.new(sColor, 50), line.style_solid, pivotWidth)
f_drawLineX(time_x1, s5, time_x2, s5, xloc.bar_time, extend.none,
color.new(sColor, 50), line.style_solid, pivotWidth)
if showPD
f_drawLineX(time_x1, pd_high, time_x2, pd_high, xloc.bar_time, extend.none,
pdColor, line.style_dashed, 1)
f_drawLineX(time_x1, pd_low, time_x2, pd_low, xloc.bar_time, extend.none,
pdColor, line.style_dashed, 1)
f_drawLineX(time_x1, pd_close, time_x2, pd_close, xloc.bar_time, extend.none,
pdColor, line.style_dotted, 1)
if showPW
f_drawLineX(time_x1, pw_high, time_x2, pw_high, xloc.bar_time, extend.none,
pwColor, line.style_dashed, 1)
f_drawLineX(time_x1, pw_low, time_x2, pw_low, xloc.bar_time, extend.none,
pwColor, line.style_dashed, 1)
f_drawLineX(time_x1, pw_close, time_x2, pw_close, xloc.bar_time, extend.none,
pwColor, line.style_dotted, 1)
if showPM
f_drawLineX(time_x1, pm_high, time_x2, pm_high, xloc.bar_time, extend.none,
pmColor, line.style_dashed, 1)
f_drawLineX(time_x1, pm_low, time_x2, pm_low, xloc.bar_time, extend.none,
pmColor, line.style_dashed, 1)
f_drawLineX(time_x1, pm_close, time_x2, pm_close, xloc.bar_time, extend.none,
pmColor, line.style_dotted, 1)
plot(showSMA9 ? sma9 : na, "9 SMA", sma9Color, 2)
plot(showSMA20 ? sma20 : na, "20 SMA", sma20Color, 2)
plot(showEMA50 ? ema50 : na, "50 EMA", ema50Color, 2)
jawPlot = plot(showFractals ? jaw : na, "Jaw", jawColor, 2)
teethPlot = plot(showFractals ? teeth : na, "Teeth", teethColor, 2)
lipsPlot = plot(showFractals ? lips : na, "Lips", lipsColor, 2)
fill(jawPlot, teethPlot, color.new(color.blue, 85), "Jaw-Teeth Fill")
fill(teethPlot, lipsPlot, color.new(color.red, 85), "Teeth-Lips Fill")
if barstate.islast
if showCPR and showCurrentCPR
f_drawLabelX(time_x2, pivot, "CPR", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, cprColor, size.normal, text.align_left, "Central Pivot
Range: " + str.tostring(pivot, format.mintick))
f_drawLabelX(time_x2, tc, "TC", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, tcColor, size.normal, text.align_left, "Top Central: " +
str.tostring(tc, format.mintick))
f_drawLabelX(time_x2, bc, "BC", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, bcColor, size.normal, text.align_left, "Bottom Central: " +
str.tostring(bc, format.mintick))
if showCPR and showPrevCPR
f_drawLabelX(time_x2_prev, prev_pivot, "Prev CPR", xloc.bar_time,
yloc.price, #00000000, label.style_label_left, prevCprColor, size.normal,
text.align_left, "Previous CPR: " + str.tostring(prev_pivot, format.mintick))
f_drawLabelX(time_x2_prev, prev_tc, "Prev TC", xloc.bar_time, yloc.price,
#00000000, label.style_label_left, prevTcColor, size.normal, text.align_left,
"Previous TC: " + str.tostring(prev_tc, format.mintick))
f_drawLabelX(time_x2_prev, prev_bc, "Prev BC", xloc.bar_time, yloc.price,
#00000000, label.style_label_left, prevBcColor, size.normal, text.align_left,
"Previous BC: " + str.tostring(prev_bc, format.mintick))
if showCPR and showNextCPR
f_drawLabelX(time_x2_next, next_pivot, "Next CPR", xloc.bar_time,
yloc.price, #00000000, label.style_label_left, nextCprColor, size.normal,
text.align_left, "Next CPR: " + str.tostring(next_pivot, format.mintick))
f_drawLabelX(time_x2_next, next_tc, "Next TC", xloc.bar_time, yloc.price,
#00000000, label.style_label_left, nextTcColor, size.normal, text.align_left, "Next
TC: " + str.tostring(next_tc, format.mintick))
f_drawLabelX(time_x2_next, next_bc, "Next BC", xloc.bar_time, yloc.price,
#00000000, label.style_label_left, nextBcColor, size.normal, text.align_left, "Next
BC: " + str.tostring(next_bc, format.mintick))
if showSR
if showSR1to3
f_drawLabelX(time_x2, r1, "R1", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, rColor, size.normal, text.align_left, "Resistance 1: " +
str.tostring(r1, format.mintick))
f_drawLabelX(time_x2, r2, "R2", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, rColor, size.normal, text.align_left, "Resistance 2: " +
str.tostring(r2, format.mintick))
f_drawLabelX(time_x2, r3, "R3", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, rColor, size.normal, text.align_left, "Resistance 3: " +
str.tostring(r3, format.mintick))
f_drawLabelX(time_x2, s1, "S1", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, sColor, size.normal, text.align_left, "Support 1: " +
str.tostring(s1, format.mintick))
f_drawLabelX(time_x2, s2, "S2", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, sColor, size.normal, text.align_left, "Support 2: " +
str.tostring(s2, format.mintick))
f_drawLabelX(time_x2, s3, "S3", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, sColor, size.normal, text.align_left, "Support 3: " +
str.tostring(s3, format.mintick))
if showSR4to5
f_drawLabelX(time_x2, r4, "R4", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, color.new(rColor, 50), size.normal, text.align_left,
"Resistance 4: " + str.tostring(r4, format.mintick))
f_drawLabelX(time_x2, r5, "R5", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, color.new(rColor, 50), size.normal, text.align_left,
"Resistance 5: " + str.tostring(r5, format.mintick))
f_drawLabelX(time_x2, s4, "S4", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, color.new(sColor, 50), size.normal, text.align_left,
"Support 4: " + str.tostring(s4, format.mintick))
f_drawLabelX(time_x2, s5, "S5", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, color.new(sColor, 50), size.normal, text.align_left,
"Support 5: " + str.tostring(s5, format.mintick))
if showPD
f_drawLabelX(time_x2, pd_high, "PDH", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, pdColor, size.normal, text.align_left, "Previous Day High:
" + str.tostring(pd_high, format.mintick))
f_drawLabelX(time_x2, pd_low, "PDL", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, pdColor, size.normal, text.align_left, "Previous Day Low: "
+ str.tostring(pd_low, format.mintick))
f_drawLabelX(time_x2, pd_close, "PDC", xloc.bar_time, yloc.price,
#00000000, label.style_label_left, pdColor, size.normal, text.align_left, "Previous
Day Close: " + str.tostring(pd_close, format.mintick))
if showPW
f_drawLabelX(time_x2, pw_high, "PWH", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, pwColor, size.normal, text.align_left, "Previous Week High:
" + str.tostring(pw_high, format.mintick))
f_drawLabelX(time_x2, pw_low, "PWL", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, pwColor, size.normal, text.align_left, "Previous Week Low:
" + str.tostring(pw_low, format.mintick))
f_drawLabelX(time_x2, pw_close, "PWC", xloc.bar_time, yloc.price,
#00000000, label.style_label_left, pwColor, size.normal, text.align_left, "Previous
Week Close: " + str.tostring(pw_close, format.mintick))
if showPM
f_drawLabelX(time_x2, pm_high, "PMH", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, pmColor, size.normal, text.align_left, "Previous Month
High: " + str.tostring(pm_high, format.mintick))
f_drawLabelX(time_x2, pm_low, "PML", xloc.bar_time, yloc.price, #00000000,
label.style_label_left, pmColor, size.normal, text.align_left, "Previous Month Low:
" + str.tostring(pm_low, format.mintick))
f_drawLabelX(time_x2, pm_close, "PMC", xloc.bar_time, yloc.price,
#00000000, label.style_label_left, pmColor, size.normal, text.align_left, "Previous
Month Close: " + str.tostring(pm_close, format.mintick))
if ta.cross(close, pivot)
alert("Price crossing CPR level: " + str.tostring(pivot, format.mintick),
alert.freq_once_per_bar_close)

You might also like