//@version=4 study("TrendTraderPRO",overlay=true) Period = input(title="Period", type=input.integer, defval=35, minval=1, maxval=100, step=1) CandleSmoothing = input(title="Candle Smoothing", defval="Valcu", options=["Valcu", "Vervoort"]) movingAverageType = input(title="Smoothing Type", defval="Weighted", options=["Exponential", "TEMA", "Weighted", "Hull","Variable", "SIMPLE"]) TEMA(series, length) => if (length > 0) ema1 = ema(series, length) ema2 = ema(ema1, length) ema3 = ema(ema2, length) (3 * ema1) - (3 * ema2) + ema3 VMA(src, l) => k = 1.0/l pdm = 0.0 pdm := max((src - src[1]), 0) mdm = 0.0 mdm := max((src[1] - src), 0) pdmS = 0.0 pdmS := ((1 - k)*nz(pdmS[1]) + k*pdm) mdmS = 0.0 mdmS := ((1 - k)*nz(mdmS[1]) + k*mdm) s = pdmS + mdmS pdi = pdmS/s mdi = mdmS/s pdiS = 0.0 pdiS := ((1 - k)*nz(pdiS[1]) + k*pdi) mdiS = 0.0 mdiS := ((1 - k)*nz(mdiS[1]) + k*mdi) d = abs(pdiS - mdiS) s1 = pdiS + mdiS iS = 0.0 iS := ((1 - k)*nz(iS[1]) + k*d/s1) hhv = highest(iS, l) llv = lowest(iS, l) d1 = hhv - llv vI = (iS - llv)/d1 vma = 0.0 vma := (1 - k*vI)*nz(vma[1]) + k*vI*src vma openMA = 0.0 closeMA= 0.0 highMA= 0.0 lowMA= 0.0 if(movingAverageType == "Simple") openMA := bar_index >0 ? sma(open, Period) : open closeMA := bar_index > 0 ? sma(close, Period) : close highMA := bar_index > 0 ? sma(high, Period) : high lowMA := bar_index > 0 ? sma(low, Period) : low else if(movingAverageType == "Exponential") openMA := bar_index > 0 ? ema(open, Period) : open closeMA := bar_index > 0 ? ema(close, Period) : close highMA := bar_index > 0 ? ema(high, Period) : high lowMA := bar_index > 0 ? ema(low, Period) : low else if(movingAverageType == "Weighted") openMA := bar_index > 0 ? wma(open, Period) : open closeMA := bar_index > 0 ? wma(close, Period) : close highMA := bar_index > 0 ? wma(high, Period) : high lowMA := bar_index > 0 ? wma(low, Period) : low else if(movingAverageType == "Hull") openMA := bar_index > 0 ? hma(open, Period) : open closeMA := bar_index > 0 ? hma(close, Period) : close highMA := bar_index > 0 ? hma(high, Period) : high lowMA := bar_index > 0 ? hma(low, Period) : low else if(movingAverageType == "Variable") openMA := bar_index > 0 ? VMA(open, Period) : open closeMA := bar_index > 0 ? VMA(close, Period) : close highMA := bar_index > 0 ? VMA(high, Period) : high lowMA := bar_index > 0 ? VMA(low, Period) : low else if(movingAverageType == "TEMA") openMA := bar_index > 0 ? TEMA(open, Period) : open closeMA := bar_index > 0 ? TEMA(close, Period) : close highMA := bar_index > 0 ? TEMA(high, Period) : high lowMA := bar_index > 0 ? TEMA(low, Period) : low haOpen = 0.0 haClose = 0.0 haLow = 0.0 haHigh = 0.0 if (CandleSmoothing == "Valcu") haOpen := na(haOpen[1]) ? open : ((haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0)/2.0) haClose := ((openMA + highMA + lowMA + closeMA) / 4.0) else if(CandleSmoothing == "Vervoort") haOpen := na(haOpen[1]) ? open:((haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0) haClose := ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + max(highMA, haOpen) + min(lowMA, haOpen)) / 4.0) haLow := min(lowMA, haOpen) haHigh := max(highMA, haOpen) plotcandle(haOpen, haHigh, haLow, haClose, title='Uptrending', color = haOpen < haClose ? color.blue : color.red, wickcolor=color.blue) var haOpen1 = 0.0 var HAhigh1 = 0.0 var HAlow1 = 0.0 haOpen1 := haOpen > haClose ? haOpen : float(na) HAhigh1 := haOpen >= haClose ? haHigh : float(na) HAlow1 := haOpen >= haClose ? haLow : float(na) plotcandle(haOpen1, HAhigh1, HAlow1, haClose, title='Downtrending', color = haOpen1 < haClose ? color.green : color.orange, wickcolor=color.orange) type = haOpen > haClose ? 1 : 0 change = type != type[1] alertcondition(change, title='Trend Change', message='Trend Change') plotshape(haOpen > haClose and haOpen[1] < haClose[1] ? haHigh + 2 * syminfo.pointvalue: na,style=shape.triangledown,color=color.white,size=size.normal,location=location.absolute) plotshape(haOpen < haClose and haOpen[1] > haClose[1] ? haLow - 2 * syminfo.pointvalue: na,style=shape.triangleup,color=color.white,size=size.normal,location=location.absolute) //plotshape(haOpen > haClose and haOpen[1] < haClose[1] ? haHigh + 2 * syminfo.pointvalue: na,style=shape.arrowdown,color=color.red,size=size.normal,location=location.absolute) //plotshape(haOpen < haClose and haOpen[1] > haClose[1] ? haLow - 2 * syminfo.pointvalue: na,style=shape.arrowup,color=color.lime,size=size.normal,location=location.absolute)