Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=2
- strategy("Trend with S/R", overlay=true)
- //HA
- haclose = ((open + high + low + close)/4)//[smoothing]
- haopen = na(haopen[1]) ? (open + close)/2 : (haopen[1] + haclose[1]) / 2
- o = haopen
- c = haclose
- src = haclose
- price = haclose
- heikUpColor() => haclose > haopen
- heikDownColor() => haclose <= haopen
- barcolor(heikUpColor() ? green: heikDownColor() ? red : na)
- //Hi-Lo Range
- therange=24
- lowbar=lowest(therange)
- highbar=highest(therange)
- halfrange=(highbar-lowbar)/2
- middlebar=lowbar+halfrange
- middlehighbar=middlebar+(halfrange*0.61803399)
- middlelowbar=middlebar-(halfrange*0.61803399)
- closelowbar=middlebar-(halfrange*0.15450849)
- closehighbar=middlebar+(halfrange*0.15450849)
- //RSI
- up1 = rma(max(change(src), 0), 9)
- down1 = rma(-min(change(src), 0), 9)
- rsi = down1 == 0 ? 100 : up1 == 0 ? 0 : 100 - (100 / (1 + up1 / down1))
- //HMA source for CMO
- n1=12
- n2ma=2*wma(haclose,round(n1/2))
- nma=wma(haclose,n1)
- diff=n2ma-nma
- sqn=round(sqrt(n1))
- C=5
- n2ma6=2*wma(haopen,round(C/2))
- nma6=wma(haopen,C)
- diff6=n2ma6-nma6
- sqn6=round(sqrt(C))
- a1=wma(diff6,sqn6)
- a=wma(diff,sqn)
- //CMO
- gains= sum(a1>a, 1)
- losses = sum(a1<a, 1)
- cmo = 100 * (gains - losses) / (gains + losses)
- //Close Pivots
- len5 = 2
- h = highest(len5)
- h1 = dev(h, len5) ? na : h
- hpivot = fixnan(h1)
- l = lowest(len5)
- l1 = dev(l, len5) ? na : l
- lpivot = fixnan(l1)
- //Calc Values
- sup = rsi<25 and cmo>50 and lpivot
- res3 = rsi>75 and cmo<-50 and hpivot
- xup = sup ? low : xup[1]
- xdown = res3 ? high : xdown[1]
- tf1 = security(tickerid, period, xup)
- tf2 = security(tickerid, period, xdown)
- //Plot
- plot(tf1, "SR1", color=white, linewidth=1, style=circles, transp=20, join=false, editable=true)
- plot(tf2, "SR2", color=white, linewidth=1, style=circles, transp=20, join=false, editable=true)
- //KDJ
- hi = highest(high, 9)
- lo = lowest(low , 9)
- k = 100*((c-lo)/(hi-lo))
- pK = rma(k, 3)
- pD = rma(pK, 3)
- pJ = 3*pK-2*pD
- KD = avg(pK, pD)
- // ICHIMOKU CLOUD
- ATRlength = 200
- ATRMult = 2.272
- ATR = rma(tr(true), ATRlength)
- out2 = ema(c, 14)
- emaup = out2+(ATR*ATRMult)
- emadw = out2-(ATR*ATRMult)
- conversionPeriods = 5
- basePeriods = 26
- laggingSpan2Periods = 52
- displacement = 26
- donchian(len2) => avg(lowest(26), highest(26))
- conversionLine = donchian(conversionPeriods)
- baseLine = donchian(basePeriods)
- leadLine1 = avg(conversionLine, baseLine)
- leadLine2 = donchian(laggingSpan2Periods)
- //Highest & Lowest
- hgst = highest(high,1)
- lwst = lowest(low,1)
- plot(lwst, color = white)
- plot(hgst, color = white)
- //EMA
- ema5 = ema(c,5)
- ema10 = ema(c,10)
- //SLOW RSI
- periods = 6
- smooth = 14
- calc_wima(src, length) =>
- MA_s=(src + nz(MA_s[1] * (length-1)))/length
- MA_s
- r1 = ema( price, periods )
- r2 = iff( price > r1, price - r1, 0 )
- r3 = iff( price < r1, r1 - price, 0 )
- r4 = calc_wima( r2, smooth )
- r5 = calc_wima( r3, smooth )
- rr = iff( r5 == 0, 100, 100 - ( 100 / ( 1 + ( r4 / r5 ) ) ) )
- //GANN Trend
- avghigh = ema(high, 10)
- avglow = ema(low, 10)
- uptrend = high > avghigh
- downtrend = low < avglow
- //GANN Swing
- Length = 5
- xHH = highest(Length)
- xLL = lowest(Length)
- xGSO = iff(xHH[2] > xHH[1] and xHH[0] > xHH[1], 1,
- iff(xLL[2] < xLL[1] and xLL[0] < xLL[1], -1, nz(xGSO[1],0)))
- //TREND CONTINUE
- xChange = mom(close, 1)
- xPlusChange = iff(xChange > 0, xChange, 0)
- xMinusChange = iff(xChange < 0, (xChange * -1), 0)
- xPlusCF = iff(xPlusChange == 0, 0, xPlusChange + nz(xPlusCF[1], 1))
- xMinusCF = iff(xMinusChange == 0, 0, xMinusChange + nz(xMinusCF[1], 1))
- xPlus = xPlusChange - xMinusCF
- xMinus = xMinusChange - xPlusCF
- xPlusTCF = sum(xPlus, 35)
- nMinusTCF = sum(xMinus, 35)
- //DTI
- xHMU = iff(high - high[1] > 0, high - high[1], 0)
- xLMD = iff(low - low[1] < 0, -(low - low[1]), 0)
- xPrice = xHMU - xLMD
- xPriceAbs = abs(xPrice)
- xuXA = ema(ema(ema(xPrice, 14),10),5)
- xuXAAbs = ema(ema(ema(xPriceAbs, 14),10),5)
- Val1 = 100 * xuXA
- Val2 = xuXAAbs
- DTI = iff(Val2 != 0, Val1 / Val2, 0)
- //Ultimate MA
- useCurrentRes = input(true, title="Use Current Chart Resolution?")
- resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="D")
- len = input(20, title="Moving Average Length - LookBack Period")
- //periodT3 = input(defval=7, title="Tilson T3 Period", minval=1)
- factorT3 = input(defval=7, title="Tilson T3 Factor - *.10 - so 7 = .7 etc.", minval=0)
- atype = input(1,minval=1,maxval=8,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA, 8=Tilson T3")
- spc=input(false, title="Show Price Crossing 1st Mov Avg - Highlight Bar?")
- cc = input(true,title="Change Color Based On Direction?")
- smoothe = input(2, minval=1, maxval=10, title="Color Smoothing - Setting 1 = No Smoothing")
- doma2 = input(false, title="Optional 2nd Moving Average")
- spc2=input(false, title="Show Price Crossing 2nd Mov Avg?")
- len2 = input(50, title="Moving Average Length - Optional 2nd MA")
- sfactorT3 = input(defval=7, title="Tilson T3 Factor - *.10 - so 7 = .7 etc.", minval=0)
- atype2 = input(1,minval=1,maxval=8,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA, 8=Tilson T3")
- cc2 = input(true,title="Change Color Based On Direction 2nd MA?")
- warn = input(false, title="***You Can Turn On The Show Dots Parameter Below Without Plotting 2nd MA to See Crosses***")
- warn2 = input(false, title="***If Using Cross Feature W/O Plotting 2ndMA - Make Sure 2ndMA Parameters are Set Correctly***")
- sd = input(false, title="Show Dots on Cross of Both MA's")
- res = useCurrentRes ? period : resCustom
- //hull ma definition
- hullma = wma(2*wma(src, len/2)-wma(src, len), round(sqrt(len)))
- //TEMA definition
- ema1 = ema(src, len)
- ema2 = ema(ema1, len)
- ema3 = ema(ema2, len)
- tema = 3 * (ema1 - ema2) + ema3
- //Tilson T3
- factor = factorT3 *.10
- gd(src, len, factor) => ema(src, len) * (1 + factor) - ema(ema(src, len), len) * factor
- t3(src, len, factor) => gd(gd(gd(src, len, factor), len, factor), len, factor)
- tilT3 = t3(src, len, factor)
- avg = atype == 1 ? sma(src,len) : atype == 2 ? ema(src,len) : atype == 3 ? wma(src,len) : atype == 4 ? hullma : atype == 5 ? vwma(src, len) : atype == 6 ? rma(src,len) : atype == 7 ? 3 * (ema1 - ema2) + ema3 : tilT3
- //2nd Ma - hull ma definition
- hullma2 = wma(2*wma(src, len2/2)-wma(src, len2), round(sqrt(len2)))
- //2nd MA TEMA definition
- sema1 = ema(src, len2)
- sema2 = ema(sema1, len2)
- sema3 = ema(sema2, len2)
- stema = 3 * (sema1 - sema2) + sema3
- //2nd MA Tilson T3
- sfactor = sfactorT3 *.10
- sgd(src, len2, sfactor) => ema(src, len2) * (1 + sfactor) - ema(ema(src, len2), len2) * sfactor
- st3(src, len2, sfactor) => sgd(sgd(gd(src, len2, sfactor), len2, sfactor), len2, sfactor)
- stilT3 = st3(src, len2, sfactor)
- avg2 = atype2 == 1 ? sma(src,len2) : atype2 == 2 ? ema(src,len2) : atype2 == 3 ? wma(src,len2) : atype2 == 4 ? hullma2 : atype2 == 5 ? vwma(src, len2) : atype2 == 6 ? rma(src,len2) : atype2 == 7 ? 3 * (ema1 - ema2) + ema3 : stilT3
- out = avg
- out_two = avg2
- out1 = security(tickerid, res, out)
- out3 = security(tickerid, res, out_two)
- //Formula for Price Crossing Moving Average #1
- cr_up = open < out1 and close > out1
- cr_Down = open > out1 and close < out1
- //Formula for Price Crossing Moving Average #2
- cr_up2 = open < out3 and close > out3
- cr_Down2 = open > out3 and close < out3
- //barcolor Criteria for Price Crossing Moving Average #1
- iscrossUp() => cr_up
- iscrossDown() => cr_Down
- //barcolor Criteria for Price Crossing Moving Average #2
- iscrossUp2() => cr_up2
- iscrossDown2() => cr_Down2
- ma_up = out1 >= out1[smoothe]
- ma_down = out1 < out1[smoothe]
- //BUY AND SELL CONDITIONS
- Buy = rising(rr,1) and pK < pJ and rising(low,1) and uptrend
- Sell = falling(rr,1) and pK > pJ and falling(high,1) and downtrend
- pos= 0.0
- pos:= Buy?1 : Sell?-1 : pos[1]
- long = Buy and pos[1]!=1
- short= Sell and pos[1]!=-1
- // Chart plot
- plotshape(long, color=lime, style=shape.triangleup, text="Buy",
- location=location.belowbar,transp=0,offset=0,size=size.small)
- plotshape(short, color=red,style=shape.triangledown,text="Sell",
- location=location.abovebar,transp=0,offset=0,size=size.small)
- // Alerts
- alertcondition(long, title="Buy Alert")
- alertcondition(short, title="Sell Alert")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement