# TMO ((T)rue (M)omentum (O)scillator) With Higher Aggregation
# Mobius
# V01.05.2018
#hint: TMO calculates momentum using the DELTA of price. Giving a much better picture of trend, tend reversals and divergence than momentum oscillators using price.
#Welkin: added a switch to toggle between the default data inputs open/close to volume, turning this into a volume ROC indicator. Added some labels showing signals for up to 6 bars. Also made it easier to change the color scheme.
declare Lower;
input dataInput = {default open_close, volume};
input length = 14;
input calcLength = 5;
input smoothLength = 3;
input agg = AggregationPeriod.FIVE_MIN;
input showLabels = yes;
def o;
def c;
switch(dataInput){
case open_close:
o = open(period = agg);
c = close(period = agg);
case volume:
o = volume(period = agg);
c = volume(period = agg);
}
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("OverBought", CreateColor(100,40,40));
DefineGlobalColor("OverSold", CreateColor(40,40,100));
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);
plot Main = ExpAverage(EMA5, smoothLength);
plot Signal = ExpAverage(Main, smoothLength);
def sigtest = Main > Signal;
Main.AssignValueColor(if sigtest
then GlobalColor("Bullish")
else GlobalColor("Bearish"));
Signal.AssignValueColor(if sigtest
then GlobalColor("Bullish")
else GlobalColor("Bearish"));
Signal.HideBubble();
Signal.HideTitle();
addCloud(Main, Signal, GlobalColor("Bullish"), GlobalColor("Bearish"));
plot zero = if isNaN(c) then double.nan else 0;
zero.SetDefaultColor(Color.gray);
zero.hideBubble();
zero.hideTitle();
plot ob = if isNaN(c) then double.nan else round(length * .7);
ob.SetDefaultColor(Color.gray);
ob.HideBubble();
ob.HideTitle();
plot os = if isNaN(c) then double.nan else -round(length * .7);
os.SetDefaultColor(Color.gray);
os.HideBubble();
os.HideTitle();
#Labels
AddLabel(showLabels," ", Color.BLACK);
AddLabel(showLabels," ", if sigtest[5] then GlobalColor("Bullish") else GlobalColor("Bearish"));
AddLabel(showLabels," ", if sigtest[4] then GlobalColor("Bullish") else GlobalColor("Bearish"));
AddLabel(showLabels," ", if sigtest[3] then GlobalColor("Bullish") else GlobalColor("Bearish"));
AddLabel(showLabels," ", if sigtest[2] then GlobalColor("Bullish") else GlobalColor("Bearish"));
AddLabel(showLabels," ", if sigtest[1] then GlobalColor("Bullish") else GlobalColor("Bearish"));
AddLabel(showLabels," ", if sigtest then GlobalColor("Bullish") else GlobalColor("Bearish"));
addCloud(ob, length, GlobalColor("OverBought"), GlobalColor("OverBought"));
addCloud(-length, os, GlobalColor("OverSold"), GlobalColor("OverSold"));
# End Code TMO with Higher Aggregation