Created
June 3, 2022 19:01
-
-
Save iCodeForBananas/09f9b43a422352f5e8af4f4124d44395 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //@version=5 | |
| indicator("VWAP Relative Strength", shorttitle="Relative VWAP Expansion") | |
| devUp1 = input(1.28, title="Stdev above (1)") | |
| devDn1 = input(1.28, title="Stdev below (1)") | |
| devUp2 = input(2.01, title="Stdev above (2)") | |
| devDn2 = input(2.01, title="Stdev below (2)") | |
| devUp3 = input(2.51, title="Stdev above (3)") | |
| devDn3 = input(2.51, title="Stdev below (3)") | |
| devUp4 = input(3.09, title="Stdev above (4)") | |
| devDn4 = input(3.09, title="Stdev below (4)") | |
| devUp5 = input(4.01, title="Stdev above (5)") | |
| devDn5 = input(4.01, title="Stdev below (5)") | |
| var float vwapsum = na | |
| var float v2sum = na | |
| var float volumesum = na | |
| price = input(close) | |
| start = request.security(syminfo.ticker, "D", time) | |
| newSession = ta.change(start) ? 1 : 0 | |
| vwapsum := newSession ? hl2*volume : vwapsum[1]+hl2*volume | |
| volumesum := newSession ? volume : volumesum[1]+volume | |
| v2sum := newSession ? volume*hl2*hl2 : v2sum[1]+volume*hl2*hl2 | |
| myvwap = vwapsum/volumesum | |
| dev = math.sqrt(math.max(v2sum/volumesum - myvwap*myvwap, 0)) | |
| myvwapu1= myvwap + devUp1 * dev | |
| myvwapd1= myvwap - devDn1 * dev | |
| myvwapu2= myvwap + devUp2 * dev | |
| myvwapu3= myvwap + devUp3 * dev | |
| myvwapd2= myvwap - devDn2 * dev | |
| myvwapd3= myvwap - devDn3 * dev | |
| myvwapu4= myvwap + devDn4 * dev | |
| myvwapd4= myvwap - devDn4 * dev | |
| plotValue = 0 | |
| plotValue := price >= myvwap and price < myvwapu1 ? 1 : plotValue | |
| plotValue := price >= myvwapu1 and price < myvwapu2 ? 2 : plotValue | |
| plotValue := price >= myvwapu2 and price < myvwapu3 ? 3 : plotValue | |
| plotValue := price >= myvwapu3 and price < myvwapu4 ? 4 : plotValue | |
| plotValue := price >= myvwapu4 ? 4 : plotValue | |
| plotValue := price <= myvwap and price > myvwapd1 ? -1 : plotValue | |
| plotValue := price <= myvwapd1 and price > myvwapd2 ? -2 : plotValue | |
| plotValue := price <= myvwapd2 and price > myvwapd3 ? -3 : plotValue | |
| plotValue := price <= myvwapd3 and price > myvwapd4 ? -4 : plotValue | |
| plotValue := price <= myvwapd4 ? -4 : plotValue | |
| // SPY std dev | |
| var float svwapsum = na | |
| var float sv2sum = na | |
| var float svolumesum = na | |
| sprice = request.security("SPY", timeframe.period, close) | |
| sstart = request.security("SPY", "D", time) | |
| shl2 = request.security("SPY", timeframe.period, hl2) | |
| svolume = request.security("SPY", timeframe.period, volume) | |
| snewSession = ta.change(sstart) ? 1 : 0 | |
| svwapsum := snewSession ? shl2*svolume : svwapsum[1]+shl2*svolume | |
| svolumesum := snewSession ? svolume : svolumesum[1]+svolume | |
| sv2sum := snewSession ? svolume*shl2*shl2 : sv2sum[1]+svolume*shl2*shl2 | |
| smyvwap = svwapsum/svolumesum | |
| sdev = math.sqrt(math.max(sv2sum/svolumesum - smyvwap*smyvwap, 0)) | |
| smyvwapu1= smyvwap + devUp1 * sdev | |
| smyvwapd1= smyvwap - devDn1 * sdev | |
| smyvwapu2= smyvwap + devUp2 * sdev | |
| smyvwapu3= smyvwap + devUp3 * sdev | |
| smyvwapd2= smyvwap - devDn2 * sdev | |
| smyvwapd3= smyvwap - devDn3 * sdev | |
| smyvwapu4= smyvwap + devDn4 * sdev | |
| smyvwapd4= smyvwap - devDn4 * sdev | |
| splotValue = 0 | |
| splotValue := sprice >= smyvwap and sprice < smyvwapu1 ? 1 : splotValue | |
| splotValue := sprice >= smyvwapu1 and sprice < smyvwapu2 ? 2 : splotValue | |
| splotValue := sprice >= smyvwapu2 and sprice < smyvwapu3 ? 3 : splotValue | |
| splotValue := sprice >= smyvwapu3 and sprice < smyvwapu4 ? 4 : splotValue | |
| splotValue := sprice >= smyvwapu4 ? 4 : splotValue | |
| splotValue := sprice <= smyvwap and sprice > smyvwapd1 ? -1 : splotValue | |
| splotValue := sprice <= smyvwapd1 and sprice > smyvwapd2 ? -2 : splotValue | |
| splotValue := sprice <= smyvwapd2 and sprice > smyvwapd3 ? -3 : splotValue | |
| splotValue := sprice <= smyvwapd3 and sprice > smyvwapd4 ? -4 : splotValue | |
| splotValue := sprice <= smyvwapd4 ? -4 : splotValue | |
| diffPlotValue = plotValue - splotValue | |
| diffPlotValue := math.max(math.min(diffPlotValue, 3), -3) | |
| plotColor = color.new(color.gray, 100) | |
| transparencyLevel = 100 | |
| transparencyLevel := diffPlotValue > 0 and diffPlotValue <= 1 ? 70 : transparencyLevel | |
| transparencyLevel := diffPlotValue == 0 and plotValue > 1 and splotValue > 1 ? 70 : transparencyLevel | |
| transparencyLevel := diffPlotValue > 1 and diffPlotValue <= 2 ? 0 : transparencyLevel | |
| transparencyLevel := diffPlotValue > 2 and diffPlotValue <= 3 ? 0 : transparencyLevel | |
| transparencyLevel := diffPlotValue < 0 and diffPlotValue >= -1 ? 70 : transparencyLevel | |
| transparencyLevel := diffPlotValue == 0 and plotValue < -1 and splotValue < -1 ? 70 : transparencyLevel | |
| transparencyLevel := diffPlotValue < -1 and diffPlotValue >= -2 ? 0 : transparencyLevel | |
| transparencyLevel := diffPlotValue < -2 and diffPlotValue >= -3 ? 0 : transparencyLevel | |
| plotchar(splotValue, "SPY std dev", "", location = location.top) | |
| plotchar(plotValue, "Ticker std dev", "", location = location.top) | |
| plotchar(diffPlotValue, "Diff std dev", "", location = location.top) | |
| // plotColor := diffPlotValue == 0 and plotValue > 1 ? color.new(color.green, 50) : plotColor | |
| // plotColor := diffPlotValue < 0 and (plotValue > 1 or splotValue > 1) ? color.new(color.green, 50) : plotColor | |
| // plotColor := diffPlotValue == 0 and plotValue == 1 and splotValue == 1 ? color.new(color.green, 100) : plotColor | |
| plotColor := plotValue > 1 and plotValue > splotValue and diffPlotValue > 0 ? color.new(color.green, 0) : plotColor | |
| plotColor := plotValue > 1 and splotValue > 1 and diffPlotValue == 0 ? color.new(color.green, 70) : plotColor | |
| plotColor := plotValue > 1 and splotValue > 1 and diffPlotValue < 0 ? color.new(color.green, 30) : plotColor | |
| plotColor := plotValue == 1 and splotValue < 1 ? color.new(color.green, 70) : plotColor | |
| plotColor := plotValue == 1 and splotValue == 1 ? color.new(color.green, 100) : plotColor | |
| plotColor := plotValue == -1 and splotValue == -1 ? color.new(color.red, 100) : plotColor | |
| plotColor := plotValue < -1 and plotValue < splotValue and diffPlotValue < 0 ? color.new(color.red, 0) : plotColor | |
| plotColor := plotValue < -1 and splotValue < -1 and diffPlotValue == 0 ? color.new(color.red, 70) : plotColor | |
| plotColor := plotValue < -1 and splotValue < -1 and diffPlotValue > 0 ? color.new(color.red, 30) : plotColor | |
| plotColor := plotValue == -1 and splotValue > -1 ? color.new(color.red, 70) : plotColor | |
| // plotColor := plotValue > splotValue ? color.new(color.green, 0) : plotColor | |
| // plotColor := plotValue < splotValue ? color.new(color.red, 0) : plotColor | |
| // plotColor := diffPlotValue == 0 and plotValue > splotValue ? color.new(color.green, 33) : plotColor | |
| // plotColor := diffPlotValue < 0 and plotValue > 1 and splotValue > 1 ? color.new(color.green, 66) : plotColor | |
| // // plotColor := diffPlotValue == 0 and plotValue < -1 ? color.new(color.red, 50) : plotColor | |
| // // plotColor := diffPlotValue > 0 and (plotValue < -1 or splotValue < -1) ? color.new(color.red, 50) : plotColor | |
| // plotColor := diffPlotValue < 0 and plotValue > 1 and splotValue > 1 and plotValue < splotValue ? color.new(color.red, 0) : plotColor | |
| // plotColor := diffPlotValue == 0 and plotValue < splotValue ? color.new(color.red, 33) : plotColor | |
| // plotColor := diffPlotValue > 0 and plotValue < 1 and splotValue < 1 ? color.new(color.red, 66) : plotColor | |
| // plotColor := diffPlotValue < 0 and (plotValue < 1 or splotValue < 1) ? color.new(color.red, transparencyLevel) : plotColor | |
| // plotColor := diffPlotValue == 0 and plotValue < 1 ? color.new(color.red, transparencyLevel) : plotColor | |
| plot(1, color=plotColor, style=plot.style_columns) | |
| // plot(0, color=color.gray) | |
| // plot(-4, color=color.gray) | |
| // plot(4, color=color.gray) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment