# TS_TapeMomentum
# http://www.thinkscripter.com
# [email protected]
# Last Update 07 Nov 2010
#hint: For use on tick charts <b>ONLY</b>. Red inidcates average momentum, yellow > average, green > two standard deviations.
#hint period: Averaging period.
#hint capMultiplier: Multiple of standard deviation at which large spikes will be truncated with a magenta dot.
#hint capLargeSpikes: Truncate larger spikes at a given standard deviation multiplier to avoid scale compression.
declare lower;
input period = 14;
input capMultiplier = 5.0;
input capLargeSpikes = YES;
def isTickChart = if GetAggregationPeriod() <= 3200 then 1 else 0;
def timer = SecondsTillTime(1615);
def deltaT = AbsValue(timer[-1] - timer);
def momentum = if isTickChart then volume / deltaT else 0;
;
def aveSM = Average(momentum, period);
def sdAve = aveSM + 2 * StDev(momentum, period);
def spikeCap = TotalSum(momentum) / BarNumber() * capMultiplier;
plot tickMomentum = if capLargeSpikes then Min(momentum, spikeCap) else momentum;
plot cap = if capLargeSpikes and tickMomentum == spikeCap then spikeCap else Double.NaN;
cap.SetStyle(Curve.POINTS);
cap.SetLineWeight(2);
cap.SetDefaultColor(Color.MAGENTA);
tickMomentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
tickMomentum.SetLineWeight(2);
tickMomentum.AssignValueColor(if tickMomentum >= Min(spikeCap, sdAve) then Color.GREEN else if tickMomentum > aveSM then Color.YELLOW else Color.RED);
plot zero = 0;
zero.SetDefaultColor(Color.WHITE);
plot EMA_MA = ExpAverage( tickMomentum,20);
AddLabel(!isTickChart, "THIS STUDY ONLY FOR USE ON TICK CHARTS", Color.RED);