A weighted average of Hourly, Daily, Weekly and Monthly Stochastic.
//Written by Ajay Malhotra @iamajeya //Original Code Stoch MTF by ChrisMoody on October 23, 2014 by user request - platinumFX //Original code Defaults to current timeframe Ability to change to different timeframe, or plot two RSI's on different timeframes. //New Code plots 4 timeframes and a weighted average of all 4 //Version 1.0 paints Hourly, Daily, Weekly and Monthly study(title="AJ_Stoch_HDWM", shorttitle="Red(H), Green(D), Blue(W), Black(M), Purple(Weighted Average)") //Take inputs for all Stochastics //Red iShow = input(true, title="Show Main Stochastic(Red-Hourly)") resCustom = "60" len = input(5, minval=1, title="Length for Main (Hourly) Stochastic") smoothK = input(3, minval=1, title="SmoothK for Main Stochastic") smoothD = input(3, minval=1, title="SmoothD for Main Stochastic") //Green iShow2 = input(true, title="Show 2nd Stochastic(Green-Daily)") resCustom2 = "D" len2 = input(14, minval=1, title="2nd Stoch Length") smoothK2 = input(3, minval=1, title="SmoothK for 2nd Stoch") smoothD2 = input(3, minval=1, title="SmoothD for 2nd Stoch") //Blue iShow3 = input(false, title="Show 3rd Stochastic(Blue-Weekly)") //resCustom3 = input(title="3rd Stoch Resolution? Default Weekly", type=resolution, defval="W") resCustom3 = "W" len3 = input(14, minval=1, title="3rd Stoch Length") smoothK3 = input(3, minval=1, title="SmoothK for 3rd Stoch") smoothD3 = input(3, minval=1, title="SmoothD for 3rd Stoch") //Black iShow4 = input(false, title="Show 4th Stochastic(Black-Monthly)") //resCustom4 = input(title="4th Stoch Resolution? Default Monthly (4 weeks)", type=resolution, defval="W") resCustom4 = "W" len4 = input(56, minval=1, title="4th Stoch Length") smoothK4 = input(12, minval=1, title="SmoothK for 4th Stoch") smoothD4 = input(12, minval=1, title="SmoothD for 4th Stoch") //purple iShowAvg = input(true, title="Show Weighted Average (Purple)?") // Weights for Hourly, Daily, Weekly and Monthly wgt1 = input(2, title="Weight for Red Stochastic") // Much higher for leveraged instruments, else 2,4,3,1 wgt2 = input(4, title="Weight for Green Stochastic") wgt3 = input(3, title="Weight for Blue Stochastic") wgt4 = input(1, title="Weight for Black Stochastic") //Remove these from input to reduce number of inputs //upLine = input(80, minval=50, maxval=90, title="Upper Line Value?") //lowLine = input(20, minval=10, maxval=50, title="Lower Line Value?") //sml = input(true, title="Show Mid Line?") //sbh = input(false, title="Show Back Ground Highlights When Stoch is Above/Below High/Low Lines?") //sch = input(false, title="Show Back Ground Highlights When Stoch Cross - Strict Criteria - K Greater/LesThan High/Low Line - Crosses D ?") //sl = input(true, title="Show 'B' and 'S' Letters When Stoch Crosses High/Low Line & D?") //sac = input(false, title="Show Back Ground Highlights When Stoch Cross - Any Cross?") //sacl = input(false, title="Show 'B' and 'S' Letters When Stoch Crosses - Any Cross?") upLine = 80 lowLine = 20 sml = true sbh = false sch = false sl = true sac = false sacl = false //Resolution for MTF res = resCustom res2 = resCustom2 res3 = resCustom3 res4 = resCustom4 //Stoch formula k = sma(stoch(close, high, low, len), smoothK) d = sma(k, smoothD) outK = security(tickerid, res, k) outD = security(tickerid, res, d) //Optional 2nd Stoch for additional plot k2 = sma(stoch(close, high, low, len2), smoothK2) d2 = sma(k2, smoothD2) outK2 = security(tickerid, res2, k2) outD2 = security(tickerid, res2, d2) //Optional 3rd Stoch for additional plot k3 = sma(stoch(close, high, low, len3), smoothK3) d3 = sma(k3, smoothD3) outK3 = security(tickerid, res3, k3) outD3 = security(tickerid, res3, d3) //Optional 4th Stoch for additional plot k4 = sma(stoch(close, high, low, len4), smoothK4) d4 = sma(k4, smoothD2) outK4 = security(tickerid, res4, k4) outD4 = security(tickerid, res4, d4) //definitions for Cross aboveLine = outK > upLine ? 1 : 0 belowLine = outK < lowLine ? 1 : 0 crossUp = (outK[1] < outD[1] and outK[1] < lowLine[1]) and (outK > outD) ? 1 : 0 crossDn = (outK[1] > outD[1] and outK[1] > upLine[1]) and (outK < outD) ? 1 : 0 //Definition for Cross that doesn't have to be above or below High and Low line. crossUpAll = (outK[1] < outD[1] and outK > outD) ? 1 : 0 crossDownAll = (outK[1] > outD[1] and outK < outD) ? 1 : 0 //BackGroound Color Plots bgcolor(sbh and aboveLine ? red : na, transp=70) bgcolor(sbh and belowLine ? lime : na, transp=70) bgcolor(sch and crossUp ? lime : na, transp=40) bgcolor(sch and crossDn ? red : na, transp=40) //plots for Cross with no filter bgcolor(sac and crossUpAll ? black : na, transp=40) bgcolor(sac and crossDownAll ? black : na, transp=40) //Plot main Stochastic plot(outK, title="Stoch K", style=line, linewidth=2, color=red) plot(outD, title="Stoch D", style=line, linewidth=2, color=yellow) //Ability to plot 2nd Stoch plot(iShow2 and outK2 ? outK2 : na, title="2nd Stoch K - Different TimeFrame", style=line, linewidth=3, color=teal) plot(iShow2 and outD2 ? outD2 : na, title="2nd Stoch D - Different TimeFrame", style=line, linewidth=2, color=lime) //Ability to plot 3rd Stoch plot(iShow3 and outK3 ? outK3 : na, title="2nd Stoch K - Different TimeFrame", style=line, linewidth=3, color=blue) plot(iShow3 and outD3 ? outD3 : na, title="2nd Stoch D - Different TimeFrame", style=line, linewidth=2, color=aqua) //Ability to plot 4th Stoch plot(iShow4 and outK4 ? outK4 : na, title="2nd Stoch K - Different TimeFrame", style=line, linewidth=4, color=black) plot(iShow4 and outD4 ? outD4 : na, title="2nd Stoch D - Different TimeFrame", style=line, linewidth=2, color=silver) p1 = plot(upLine, title= "Upper Line", style=dashed, linewidth=2, color=fuchsia, transp=70) p2 = plot(lowLine, title= "Lower Line", style=dashed, linewidth=2, color=fuchsia, transp=70) plot(sml ? 50 : na, title="Mid Line", style=linebr, linewidth=2, color=fuchsia, transp=70) plotchar(sl and crossUp ? crossUp : na, title="Buy Signal Strict Criteria", char='B', location=location.bottom, color=lime, transp=0, offset=0) plotchar(sl and crossDn ? crossDn : na, title="Sell Signal Strict Criteria", char='S', location=location.top, color=red, transp=0, offset=0) plotchar(sacl and crossUpAll ? crossUpAll : na, title="Buy Signal Any Cross Up", char='B', location=location.bottom, color=lime, transp=0, offset=0) plotchar(sacl and crossDownAll ? crossDownAll : na, title="Sell Signal Any Cross Down", char='S', location=location.top, color=red, transp=0, offset=0) fill(p1, p2, color=fuchsia, transp=97) //Weighted Average outWK = (outK*wgt1 + outK2*wgt2 + outK3*wgt3 + outK4*wgt4)/(wgt1+wgt2+wgt3+wgt4) outW = sma(outWK, 14) //Smoothed at 14 smaW = sma(outWK, 61) //outW = ((outK*dif1) + (outK2*dif2) + (outK3*dif3) + (outK4*dif4) / (dif1+dif2+dif3+dif4))/30 plot(iShowAvg and outW ? outW : na, title="Weighted Stoch", style=line, linewidth=4, color=purple) plot(iShowAvg and smaW ? smaW : na, title="Weighted Stoch D", style=line, linewidth=4, color=purple, transp=80)