declare upper; #INPUTS input price = close; input period = 20; input alpha1 = 0.2; input alpha2 = 0.04; #LOGIC def stdDev = StDev(price, period); def avStdDev = Average(stdDev, period); def ratio = stdDev/avStdDev; def vidya1 = (alpha1 * ratio * price) + ((1-(alpha1*ratio)) * vidya1[1]); def vidya2 = (alpha2 * ratio * price) + ((1-(alpha2*ratio)) * vidya2[1]); def buy = Crosses(VIDYA1, VIDYA2, CrossingDirection.ABOVE); def sell = Crosses(VIDYA1, VIDYA2, CrossingDirection.BELOW); def sState = if buy then 100 else if sell then -100 else sState[1]; #PLOTS input showPlots = yes; plot pVidya1 = vidya1; pVidya1.SetHiding(!showPlots); plot pVidya2 = vidya2; pVidya2.SetHiding(!showPlots); # ARROWS input showArrows = yes; plot pUP = sState crosses above 0; pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); pUP.SetDefaultColor(Color.GREEN); pUP.SetLineWeight(2); plot pDown = sState crosses below 0; pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); pDown.SetDefaultColor(Color.RED); pDown.SetLineWeight(2); #COLORBARS input showColorBars = yes; AssignPriceColor(if showColorBars then if IsNaN(sState) then Color.GRAY else if sState > 0 then Color.GREEN else Color.RED else COLOR.CURRENT ); #LABELS input showLabels = yes; AddLabel(showLabels,"VIDYA2->", COLOR.CYAN); AddLabel(showLabels, "Buy", if isNaN(sState) then COLOR.DARK_GRAY else If sState == 100 then COLOR.GREEN else COLOR.DARK_GRAY); AddLabel(showLabels, "Sell", if isNaN(sState) then COLOR.DARK_GRAY else If sState == -100 then COLOR.RED else COLOR.DARK_GRAY);