# TMO ((T)rue (M)omentum (O)scillator) With Higher Aggregation breakouts only
# Mobius
# custom by WTF_Dude based off V01.05.2018
#hint: TMO calculates momentum using the DELTA of price. Giving a much better picture of trend, trend reversals and divergence than momentum oscillators using price.
declare upper;
input length = 21;
input calcLength = 5;
input smoothLength = 3;
input agg = AggregationPeriod.DAY;
def o = open(period = agg);
def c = close(period = agg);
def data = fold i = 0 to length
with s
do s + (if c > getValue(o, i)
then 1
else if c < getValue(o, i)
then - 1
else 0);
def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);
#Main.AssignValueColor(if Main > Signal
# then color.green
# else color.red);
# Signal.AssignValueColor(if Main > Signal
# then color.green
# else color.red);
# Signal.HideBubble();
#Signal.HideTitle();
#addCloud(Main, Signal, color.green, color.red);
plot Bull = Crosses(main, signal, CrossingDirection.ABOVE);
plot Bear = Crosses(main, signal, CrossingDirection.BELOW);
Bull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bull.SetDefaultColor(Color.CYAN);
Bull.SetLineWeight(2);
Bear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bear.SetDefaultColor(Color.MAGENTA);
Bear.SetLineWeight(2);