Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study(title="SR, MAs, VWAP, Pivots", shorttitle="SR, MAs, VWAP, Pivots", overlay=true, max_labels_count=500)
- // ***************************************************
- // SUPPORT/RESISTANCE LINES
- // ***************************************************
- groupSR = "--- SUPPORT/RESISTANCE LINES ---"
- s1 = input(title="S1", type=input.float, defval=0.0,group=groupSR)
- s2 = input(title="S2", type=input.float, defval=0.0,group=groupSR)
- s3 = input(title="S3", type=input.float, defval=0.0,group=groupSR)
- s4 = input(title="S4", type=input.float, defval=0.0,group=groupSR)
- r1 = input(title="R1", type=input.float, defval=0.0,group=groupSR)
- r2 = input(title="R2", type=input.float, defval=0.0,group=groupSR)
- r3 = input(title="R3", type=input.float, defval=0.0,group=groupSR)
- r4 = input(title="R4", type=input.float, defval=0.0,group=groupSR)
- hline(s1, "S1", color=color.rgb(255,0,0,50), linestyle=hline.style_dashed, linewidth=1, editable=true)
- hline(s2, "S2", color=color.rgb(255,0,0,50), linestyle=hline.style_dashed, linewidth=1, editable=true)
- hline(s3, "S3", color=color.rgb(255,0,0,50), linestyle=hline.style_dashed, linewidth=1, editable=true)
- hline(s4, "S4", color=color.rgb(255,0,0,50), linestyle=hline.style_dashed, linewidth=1, editable=true)
- hline(r1, "R1", color=color.rgb(0,255,0,50), linestyle=hline.style_dashed, linewidth=1, editable=true)
- hline(r2, "R2", color=color.rgb(0,255,0,50), linestyle=hline.style_dashed, linewidth=1, editable=true)
- hline(r3, "R3", color=color.rgb(0,255,0,50), linestyle=hline.style_dashed, linewidth=1, editable=true)
- hline(r4, "R4", color=color.rgb(0,255,0,50), linestyle=hline.style_dashed, linewidth=1, editable=true)
- // ***************************************************
- // PIVOTS
- // ***************************************************
- groupPivots = "--- PIVOTS ---"
- leftLenH = input(title="Pivot High", type=input.integer, defval=10, minval=1, inline="Pivot High",group=groupPivots)
- rightLenH = input(title="/", type=input.integer, defval=10, minval=1, inline="Pivot High",group=groupPivots)
- colorH = input(title="Background High", defval=color.rgb(0,0,0,0), group=groupPivots)
- textH = input(title="Text High", type=input.color, defval=color.rgb(255,255,0,0), group=groupPivots)
- leftLenL = input(title="Pivot Low", type=input.integer, defval=10, minval=1, inline="Pivot Low", group=groupPivots)
- rightLenL = input(title="/", type=input.integer, defval=10, minval=1, inline="Pivot Low", group=groupPivots)
- colorL = input(title="Background Low", defval=color.rgb(0,0,0,0), group=groupPivots)
- textL = input(title="Text Low", type=input.color, defval=color.rgb(255,255,0,0), group=groupPivots)
- ph = pivothigh(leftLenH, rightLenH)
- pl = pivotlow( leftLenL, rightLenL)
- drawLabel(_offset, _pivot, _style, _yloc, _color) =>
- if not na(_pivot)
- label.new(bar_index[_offset], _pivot, tostring(_pivot, format.mintick), style=_style, yloc=_yloc, color=_color, textcolor= (_pivot==ph ? textH : textL) )
- drawLabel(rightLenH, ph, label.style_label_down, yloc.abovebar, colorH)
- drawLabel(rightLenL, pl, label.style_label_up, yloc.belowbar, colorL)
- // ***************************************************
- // VWAP
- // ***************************************************
- groupVWAP="--- VWAP ---"
- computeVWAP(src, isNewPeriod, stDevMultiplier) =>
- 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 calculates the dividend of the equation that is later used to calculate the standard deviation
- sumSrcSrcVol := isNewPeriod ? volume * pow(src, 2) : volume * pow(src, 2) + sumSrcSrcVol[1]
- _vwap = sumSrcVol / sumVol
- variance = sumSrcSrcVol / sumVol - pow(_vwap, 2)
- variance := variance < 0 ? 0 : variance
- stDev = sqrt(variance)
- lowerBand = _vwap - stDev * stDevMultiplier
- upperBand = _vwap + stDev * stDevMultiplier
- [_vwap, lowerBand, upperBand]
- hideonDWM = input(false, title="Hide VWAP on 1D or Above", group=groupVWAP)
- var anchor = input(defval = "Session", title="Anchor Period", type=input.string,
- options=["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century", "Earnings", "Dividends", "Splits"], group=groupVWAP)
- src = input(title = "Source", type = input.source, defval = hlc3, group=groupVWAP)
- offset = input(0, title="Offset", group=groupVWAP)
- showBands = input(true, title="Calculate Bands", group="Standard Deviation Bands Settings")
- stdevMult = input(1.0, title="Bands Multiplier", group="Standard Deviation Bands Settings")
- timeChange(period) =>
- change(time(period))
- new_earnings = earnings(syminfo.tickerid, earnings.actual, barmerge.gaps_on, barmerge.lookahead_on)
- new_dividends = dividends(syminfo.tickerid, dividends.gross, barmerge.gaps_on, barmerge.lookahead_on)
- new_split = splits(syminfo.tickerid, splits.denominator, barmerge.gaps_on, barmerge.lookahead_on)
- isNewPeriod = anchor == "Earnings" ? new_earnings :
- anchor == "Dividends" ? new_dividends :
- anchor == "Splits" ? new_split :
- na(src[1]) ? true :
- anchor == "Session" ? timeChange("D") :
- anchor == "Week" ? timeChange("W") :
- anchor == "Month" ? timeChange("M") :
- anchor == "Quarter" ? timeChange("3M") :
- anchor == "Year" ? timeChange("12M") :
- anchor == "Decade" ? timeChange("12M") and year % 10 == 0 :
- anchor == "Century" ? timeChange("12M") and year % 100 == 0 :
- false
- float vwapValue = na
- float std = na
- float upperBandValue = na
- float lowerBandValue = na
- if not (hideonDWM and timeframe.isdwm)
- [_vwap, bottom, top] = computeVWAP(src, isNewPeriod, stdevMult)
- vwapValue := _vwap
- upperBandValue := showBands ? top : na
- lowerBandValue := showBands ? bottom : na
- plot(vwapValue, title="VWAP",color=color.rgb(255,255,0,15), style=plot.style_line, linewidth=3, offset=offset)
- ////upperBand = plot(upperBandValue, title="Upper Band", color=color.green, offset=offset)
- ////lowerBand = plot(lowerBandValue, title="Lower Band", color=color.green, offset=offset)
- ////fill(upperBand, lowerBand, title="Bands Fill", color= showBands ? color.new(color.green, 95) : na)
- // ***************************************************
- // MOVING AVERAGES
- // ***************************************************
- groupMA="--- MOVING AVERAGES ---"
- // === INPUTS ===
- emasrc = input(close)
- ema1 = input(8,title='EMA 8', group=groupMA)
- ema2 = input(21,title='EMA 21', group=groupMA)
- ema3 = input(34,title='EMA 34', group=groupMA)
- pema1 = ema(emasrc, ema1)
- pema2 = ema(emasrc, ema2)
- pema3 = ema(emasrc, ema3)
- sma1 = input(50,title='SMA 50', group=groupMA)
- psma1 = sma(emasrc, sma1)
- sma2 = input(100,title='SMA 100', group=groupMA)
- psma2 = sma(emasrc, sma2)
- sma3 = input(200,title='SMA 200', group=groupMA)
- psma3 = sma(emasrc, sma3)
- ema1plot = plot(pema1, color=color.rgb(255,0,0,15), style=plot.style_line, linewidth=2, title='EMA 8')
- ema2plot = plot(pema2, color=color.rgb(255,255,255,15), style=plot.style_line, linewidth=2, title='EMA 21')
- ema3plot = plot(pema3, color=color.rgb(0,0,255,15), style=plot.style_line, linewidth=2, title='EMA 34')
- sma1plot = plot(psma1, color=color.rgb(128,0,128,15), style=plot.style_line, linewidth=2, title='SMA 50')
- sma2plot = plot(psma2, color=color.rgb(0,255,255,15), style=plot.style_line, linewidth=2, title='SMA 100')
- sma3plot = plot(psma3, color=color.rgb(255,0,255,15), style=plot.style_line, linewidth=2, title='SMA 200')
Advertisement
Add Comment
Please, Sign In to add comment