TMO True Momentum Oscillator For ThinkOrSwim

@Iceburgh Sure thing. Here you go:

Code:
# TMO ((T)rue (M)omentum (O)scilator)
# 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.
# Modified by BenTen 03/24/2021: added arrows to upper chart

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
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);
plot up = if Main crosses above Signal then low else double.nan;
plot down = if Main crosses below Signal then high else double.nan;
up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
down.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Added breakout signals

Code:
# TMO ((T)rue (M)omentum (O)scilator)
# 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.

declare Lower;

input length = 14;
input calcLength = 5;
input smoothLength = 3;

#input symbol = "SPX";
def o = open;#(symbol);
def c = close;#(symbol);
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);
     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 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();
addCloud(ob, length, color.light_red, color.light_red, no);
addCloud(-length, os, color.light_green, color.light_green);

input showBreakoutSignals = no;


plot longsignal = if main crosses above signal then main else Double.NaN;
plot shortSignal = if main crosses below signal then signal else Double.NaN;

longSignal.SetHiding(!showBreakoutSignals);
shortSignal.SetHiding(!showBreakoutSignals);

longsignal.SetDefaultColor(Color.UPTICK);
longsignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
shortSignal.SetDefaultColor(Color.DOWNTICK);
shortSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
# End Code TMO
 
Needed TMO normalized code to run with RSI scale to run scan with if needed. Normalizing code can be very useful for scans and utilizing the same lower study to pile on a few indicators.

Image below, code below image.
QTcN4v9.jpg


Code:
# TMO ((T)rue (M)omentum (O)scilator)
# 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.
#4/13/21 @rlohmeyer modified raw code and normalized for RSI scale

declare Lower;

input data_length = 14;
input EMA_Length = 5;

def o = open;
def c = close;
def data = fold i = 0 to data_length with s do s + (if c > getValue(o, i) then 1 else if c < getValue(o, i)    then - 1 else 0);
def Main = ExpAverage(data, EMA_Length);
#Scale Normalization Code
def hh = Round(highestAll(main),2);
def ll = Round(lowestall(main),2);
plot TMO = ((main-ll)/(hh-ll))*100;
TMO.setdefaultColor (color.yellow);
 
For those interested I include how I am using TMO combined with 2 RSI indicators on a normalized scale for swing trading on day charts. Below is a graphic and below that the code. TMO in yellow. The RSI's in Cyan and Magenta.
lxPOJt9.jpg

Code:
# TMO ((T)rue (M)omentum (O)scilator)
# 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.
#@rlohmeyer: RSI,TMO on normalized scale
declare lower;
#Scale Normaliztion Script
script normalizePlot {
    input normalize_data = close;
    input MinRng = -1;
    input MaxRng = 1;
    def HH = HighestAll( normalize_data );
    def LL = LowestAll( normalize_data );
    plot NR = ((( MaxRng - MinRng ) * ( normalize_data - LL )) / ( HH - LL )) + MinRng;
}

#TMO
input Tmo_Price = close;
input Tmo_data_length = 5;
input Tmo_Ema_Length = 5;
def o = open;
def TMOdata = fold i = 0 to TMO_data_length with s do s + (if TMO_price > getValue(o, i) then 1 else if TMO_price < getValue(o, i)    then - 1 else 0);
def TMOavg = ExpAverage(TMOdata, TMO_EMA_Length);
#RSI
input RSI_price = close;
def RSI_Average = AverageType.WILDERS;
input RSI_Avg_Length = 2;
def NetChgAvg = MovingAverage(RSI_Average, RSI_price - RSI_price[1], RSI_Avg_Length);
def TotChgAvg = MovingAverage(RSI_Average, AbsValue(RSI_price - RSI_price[1]), RSI_Avg_Length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RS = 50 * (ChgRatio + 1);
input Rsi_Ema_Length = 2;
def RSIavg =  ExpAverage(RS, RSI_EMA_Length);
#RSI2
input RsiTwoPrice = close;
def RsiTwoAverage = AverageType.WILDERS;
input RsiTwoAvgLength = 2;
def NetChgAvg2 = MovingAverage(RsiTwoAverage, RsiTwoPrice - RsiTwoPrice[1], RsiTwoAvgLength);
def TotChgAvg2 = MovingAverage(RsiTwoAverage, AbsValue(RsiTwoPrice - RsiTwoPrice[1]), RsiTwoAvgLength);
def ChgRatio2 = if TotChgAvg2 != 0 then NetChgAvg2 / TotChgAvg2 else 0;
def RS2 = 50 * (ChgRatio2 + 1);
input RsiTwoEmaLength = 2;
def RSIavg2 =  ExpAverage(RS2, RsiTwoEmaLength);

#Scale parameters
input MaxRng = 100;#Max range value
input MinRng = 0;#Min range value
input OBH = 95;
input OBL = 90;
Addcloud(OBH,OBL,color.green);
input OSH = 10;
input OSL = 5;
Addcloud(OSH,OSL,color.red);

#Scale normalization based on parameters
def newTMO = normalizePlot(TMOavg, MinRng, MaxRng );
def newRSI = normalizePlot(RSIavg, MinRng, MaxRng );
def newRSI2 = normalizePlot(RSIavg2, MinRng, MaxRng );
#Plots
plot TMO = newTMO;
TMO.setdefaultColor(color.yellow);
TMO.Hidebubble();
TMO.hidetitle();

plot RSI = newRSI;
RSI.setdefaultColor(color.cyan);
RSI.hidebubble();
RSI.hidetitle();

plot RSI2 = newRSI2;
RSI2.setdefaultColor(color.magenta);
RSI2.hidebubble();
RSI2.hidetitle();

plot Mid = (MaxRng + MinRng)/2;
Mid.setdefaultColor(color.light_gray);
Mid.hidebubble();
Mid.hidetitle();
 
Is there a way to make a watchlist column to show the distance between the Main and Signal Lines? So you can sort by closest to farthest apart?
 
Is there a way to setup a watchlist column to sort by the distance between the TMO Main line and TMO Signal line?

I have a watchlist that is my TMO scan results for Green TMO (Main line above Signal line) in the under -10 zone and I want to be able to sort that list by thickest to thinnest .

TMO
https://usethinkscript.com/threads/true-momentum-oscillator-for-thinkorswim.15/
hL1ww4J.png
Is there a way to make a watchlist column to show the distance between the Main and Signal Lines? So you can sort by closest to farthest apart?

@bobknob Test this and verify the results -

Code:
# Watchlist column using TMO ((T)rue (M)omentum (O)scilator) by Mobius, V01.05.2018
# column displays the difference between the main and signal lines when the main line is
# above the signal line and both are below the oversold line.

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
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);
def os = -round(length * .7);
def total = Main > Signal and Signal < os;

plot between = if total then Main - Signal else 0;
between.assignvaluecolor(if total then color.green else color.black);

You can add something like AddLabel(1,round(Main - Signal,2),color.white) to your chart's lower True Momentum Oscillator code to have a label show the difference between the two lines.
 
@bobknob Test this and verify the results -

Code:
# Watchlist column using TMO ((T)rue (M)omentum (O)scilator) by Mobius, V01.05.2018
# column displays the difference between the main and signal lines when the main line is
# above the signal line and both are below the oversold line.

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
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);
def os = -round(length * .7);
def total = Main > Signal and Signal < os;

plot between = if total then Main - Signal else 0;
between.assignvaluecolor(if total then color.green else color.black);

You can add something like AddLabel(1,round(Main - Signal,2),color.white) to your chart's lower True Momentum Oscillator code to have a label show the difference between the two lines.

Okay I got this to work and to do what I wanted using the code blow (I'm sure there's a cleaner version of the "plot between" section but it works and gives me a positive value for green trends and a negative for red).

I also tried adding that bit of label code to the end of my TMO code but it crashed it out "invalid statement AddLabel"

Code:
# Watchlist column using TMO ((T)rue (M)omentum (O)scilator) by Mobius, V01.05.2018
# column displays the difference between the main and signal lines and cloud color.

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
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);
def os = -round(length * .7);
def total = Main > Signal;

plot between = if total then Main - Signal else Main - Signal;
between.assignvaluecolor(if total then color.green else color.yellow);
AssignBackgroundColor(if Main > Signal then color.dark_GREEN else color.dark_RED);
 
Okay I got this to work and to do what I wanted using the code blow (I'm sure there's a cleaner version of the "plot between" section but it works and gives me a positive value for green trends and a negative for red).

I also tried adding that bit of label code to the end of my TMO code but it crashed it out "invalid statement AddLabel"

Code:
# Watchlist column using TMO ((T)rue (M)omentum (O)scilator) by Mobius, V01.05.2018
# column displays the difference between the main and signal lines and cloud color.

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
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);
def os = -round(length * .7);
def total = Main > Signal;

plot between = if total then Main - Signal else Main - Signal;
between.assignvaluecolor(if total then color.green else color.yellow);
AssignBackgroundColor(if Main > Signal then color.dark_GREEN else color.dark_RED);
@bobknob Good job with the modifying the code! As you said, it can be "cleaned up", but it does'nt need much at all. Since you are'nt using the oversold level that line of code can be removed, and the plot can be made a bit more concise. As for the AddLabel error, all it needs is a semicolon at the end. Its free code, so . . . . 😁

Code:
# Watchlist column using TMO ((T)rue (M)omentum (O)scilator) by Mobius, V01.05.2018
# column displays the difference between the main and signal lines and cloud color.

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
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);
def total = Main > Signal;

plot between = Main - Signal;
between.assignvaluecolor(if total then color.green else color.yellow);
AssignBackgroundColor(if total then color.dark_GREEN else color.dark_RED);

Here's a new fancier Label to add to the TMO code. This one should work right out of the box.
AddLabel(1,"Difference = " + round(Main - Signal,2), if Main > Signal then color.dark_green else color.dark_red);
 
@unkownriver
TMO ((T)rue (M)omentum (O)scilator) Scan Scanner
Mobius, with modifications by tomsk, 1.1.2020

Ruby:
# TMO ((T)rue (M)omentum (O)scilator) Scan
# Mobius, with modifications by tomsk, 1.1.2020
# 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.

input length = 14;
input calcLength = 5;
input smoothLength = 3;
input level = -15;   ##Bullish Scan
#input level = 10;   ##Bearish Scan

def o = open;
def c = close;
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);
def Signal = ExpAverage(Main, smoothLength);
addchartBubble(close,close,main);
plot sell = main crosses below 10 ;
#hint: Comment out using # below to scan for Bullish or Bearish.  Please note that ## applies to conditional scan with parameters -10 (over sold condition) Bullish Scan) and 10 (over bought condition) Bearish Scan) Default is set to a Bullish TMO Scan without any conditions.

##***Bullish Scan***
plot scan = main crosses above level;
#plot scan = main < level and signal < level and main > signal;
#plot scan = main < main[1] and signal < signal[1];

##***Bearish Scan***

##plot scan = main > level and signal > level and main < signal;
#plot scan = main > main[1] and signal > signal[1];
@MerryDay How do I edit this scanner scan so that it can only scan for momentum that is above 0?
 
Hey guys I am trying to add long and short arrows to the TMO indicator that trigger when the main line comes back out of OS or OB. I have tried several times but am having no luck. The code is fine with no errors but the arrows don't paint. I tried to copy the format from other indicators with arrows but still can't get it to work. Here's my code:

Ruby:
# TMO ((T)rue (M)omentum (O)scilator)
# 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.

declare Lower;

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
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);
     Main.AssignValueColor(if Main > Signal
                           then color.white
                           else color.black);
     Signal.AssignValueColor(if Main > Signal
                             then color.white
                             else color.black);
     Signal.HideBubble();
     Signal.HideTitle();
addCloud(Main, Signal, color.white, color.black);
plot zero = if isNaN(c) then double.nan else 0;
     zero.SetDefaultColor(Color.black);
     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();
addCloud(ob, length, color.DARK_GRAY, color.DARK_GRAY, no);
addCloud(-length, os, color.dark_gray, color.dark_gray);


def LONG = MAIN > OS AND MAIN < OS [1];
PLOT UPARROW = LONG;
UPARROW.SetPaintingStrategy(PaintingStrategy.
BOOLEAN_ARROW_UP);
UPARROW.SetDefaultColor(Color.WHITE);
UPARROW.SetLineWeight(5);

def SHORT = MAIN < OB AND MAIN > OB [1];

PLOT DOWNARROW = SHORT;

DOWNARROW.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DOWNARROW.SetDefaultColor(Color.BLACK);
DOWNARROW.SetLineWeight(5);

# End Code TMO

Here's a screenshot of what I am trying to get:

 
Last edited by a moderator:
@Noca Jones
TOS requires that you state WHERE on the candle you want the arrow to print. IE: plot it on the main plot, on the signal, on zero, etc... So the statement you need to make is if long is true then print candle at main else print nothing (double.NaN) and you didn't need the boolean logic on your arrows.
So syntax looks like:
Code:
def LONG = main crosses above OS;
PLOT UPARROW = if LONG then main else double.NaN ;
UPARROW.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UPARROW.SetDefaultColor(Color.WHITE);
UPARROW.SetLineWeight(5);

def SHORT = MAIN crosses below OB ;

PLOT DOWNARROW = if SHORT then main else double.NaN ;

DOWNARROW.SetPaintingStrategy(PaintingStrategy.ARROW_down);
DOWNARROW.SetDefaultColor(Color.BLACK);
DOWNARROW.SetLineWeight(5);

Sorry for the mix-up before.
a2.png
 
Hey guys I am trying to add long and short arrows to the TMO indicator that trigger when the main line comes back out of OS or OB. I have tried several times but am having no luck. The code is fine with no errors but the arrows don't paint. I tried to copy the format from other indicators with arrows but still can't get it to work. Here's my code:

# TMO ((T)rue (M)omentum (O)scilator)
# 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.

declare Lower;

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
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);
Main.AssignValueColor(if Main > Signal
then color.white
else color.black);
Signal.AssignValueColor(if Main > Signal
then color.white
else color.black);
Signal.HideBubble();
Signal.HideTitle();
addCloud(Main, Signal, color.white, color.black);
plot zero = if isNaN(c) then double.nan else 0;
zero.SetDefaultColor(Color.black);
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();
addCloud(ob, length, color.DARK_GRAY, color.DARK_GRAY, no);
addCloud(-length, os, color.dark_gray, color.dark_gray);


def LONG = MAIN > OS AND MAIN < OS [1];
PLOT UPARROW = LONG;
UPARROW.SetPaintingStrategy(PaintingStrategy.
BOOLEAN_ARROW_UP);
UPARROW.SetDefaultColor(Color.WHITE);
UPARROW.SetLineWeight(5);

def SHORT = MAIN < OB AND MAIN > OB [1];

PLOT DOWNARROW = SHORT;

DOWNARROW.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DOWNARROW.SetDefaultColor(Color.BLACK);
DOWNARROW.SetLineWeight(5);

# End Code TMO

Here's a screenshot of what I am trying to get:


just because there are no errors, doesn't mean the code is ok.

your os and ob formulas are wrong.
you need to fix what is inside of the round( ) functions.
the values will never result in a true condition in LONG = or SHORT =.


length =14
plot ob = if isNaN(c) then double.nan else round(length * .7);
plot os = if isNaN(c) then double.nan else -round(length * .7);

plot Main = ExpAverage(EMA5, smoothLength);

def LONG = MAIN > OS AND MAIN < OS [1];
PLOT UPARROW = LONG;
 
@zeek
Copy the code below and paste it directly into the scanner. Hope this helps!
PMNonsc.png

Ruby:
# TMO ((T)rue (M)omentum (O)scilator) **************  scanner only  ****************
# 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.

input length = 14;
input calcLength = 5;
input smoothLength = 3;
input AlertDisplace = 0;

def o = open;
def c = close;
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);

def zero = if isNaN(c) then double.nan else 0;
def ob = if isNaN(c) then double.nan else round(length * .7);
def os = if isNaN(c) then double.nan else -round(length * .7);

plot BUYsignal =Main < OS and Main crosses above Signal and Main <  os;
#plot SELLsignal = Main > OB and Main crosses below Signal and Main > ob;
 
I'm using this TMO label that show me some information about the signal, i want to add another detail in my label that tells me when the signal goes ob and os, i try few ideas but every time only show me one, like if the signal is above 0 and above ob only show me one but not both, can some one give me an idea how to write this part?

My label tells me when the signal is rising or falling and if its over 0 or below -0 and what I was trying to add inside the label is that let me know if its above 10 or below -10 too. Something like TMO above 0 and over 10, same for below?

Code:
# TMO Label
def length = 14;
def calcLength = 5;
def smoothLength = 3;

def ob = if isNaN(close) then Double.NAN else round(length * .7);
def os = if isNaN(close) then Double.NAN else -round(length * .7);

def data = fold i = 0 to length with s do s + (if close > getValue(open, i) then 1 else if close < getValue(open, i) then - 1 else 0);
def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);

def riUp = main >= main[1];
def faDn = main < main[1];

AddLabel(yes,  
     if riUp and main and signal < 0 then " TMO Rising Below: " + " -0 " + " " else   
     if riUp and main and signal > 0 then " TMO Rising Above: " + " 0 " + " " else   
     if faDn and main and signal > 0 then " TMO Falling Above " + " 0 " + " " else   
     if faDn and main and signal < 0 then " TMO Falling Below " + " -0 " + " " else " ",   
     if riUp and main and signal < 0 then Color.Dark_GREEN else   
     if riUp and main and signal > 0 then Color.GREEN else   
     if faDn and main and signal > 0 then Color.DARK_RED else   
     if faDn and main and signal < 0 then Color.RED else Color.CURRENT);
 
Here is what you requested. I am not sure how useful this will be. It requires that the TMO and it's average walk in lock step which doesn't always happen. Might be better to test for main or its signal. Not both.

When testing for multiple conditions: the order that you nest your if statements is vital. Here we test for 10 and -10 first. If satisfied, it gets a 10/-10 label. Otherwise, it moves on to test for the zero condition.

Ruby:
def riUp = main >= main[1];
def faDn = main < main[1];

AddLabel(yes,
     if riUp and main<-10 and signal <-10 then " TMO Rising Below: " + " -10 " + " " else  
     if riUp and main>10 and signal > 10 then " TMO Rising Above: " + " 10 " + " " else  
     if faDn and main>10 and signal >10 then " TMO Falling Below " + " 10 " + " " else  
     if faDn and main<-10 and signal <-10 then " TMO Falling Below " + " -10 " + " " else
 
     if riUp and main<0 and signal < 0 then " TMO Rising Below: " + " -0 " + " " else  
     if riUp and main>0 and signal > 0 then " TMO Rising Above: " + " 0 " + " " else  
     if faDn and main>0 and signal > 0 then " TMO Falling Above " + " 0 " + " " else  
     if faDn and main<0 and signal < 0 then " TMO Falling Below " + " -0 " + " " else " ",  
   
     if riUp and main<-10 and signal <-10 then Color.Dark_GREEN else  
     if riUp and main>10 and signal > 10 then Color.GREEN else  
     if faDn and main>10 and signal > 10 then Color.DARK_RED else  
     if faDn and main<-10 and signal < -10 then Color.RED else
 
     if riUp and main<0 and signal < 0 then Color.Dark_GREEN else  
     if riUp and main>0 and signal > 0 then Color.GREEN else  
     if faDn and main>0 and signal > 0 then Color.DARK_RED else  
     if faDn and main<0 and signal < 0 then Color.RED else Color.CURRENT);
53S6axX.png
 
Here is what you requested. I am not sure how useful this will be. It requires that the TMO and it's average walk in lock step which doesn't always happen. Might be better to test for main or its signal. Not both.

When testing for multiple conditions: the order that you nest your if statements is vital. Here we test for 10 and -10 first. If satisfied, it gets a 10/-10 label. Otherwise, it moves on to test for the zero condition.

Ruby:
def riUp = main >= main[1];
def faDn = main < main[1];

AddLabel(yes,
     if riUp and main<-10 and signal <-10 then " TMO Rising Below: " + " -10 " + " " else 
     if riUp and main>10 and signal > 10 then " TMO Rising Above: " + " 10 " + " " else 
     if faDn and main>10 and signal >10 then " TMO Falling Below " + " 10 " + " " else 
     if faDn and main<-10 and signal <-10 then " TMO Falling Below " + " -10 " + " " else
 
     if riUp and main<0 and signal < 0 then " TMO Rising Below: " + " -0 " + " " else 
     if riUp and main>0 and signal > 0 then " TMO Rising Above: " + " 0 " + " " else 
     if faDn and main>0 and signal > 0 then " TMO Falling Above " + " 0 " + " " else 
     if faDn and main<0 and signal < 0 then " TMO Falling Below " + " -0 " + " " else " ", 
  
     if riUp and main<-10 and signal <-10 then Color.Dark_GREEN else 
     if riUp and main>10 and signal > 10 then Color.GREEN else 
     if faDn and main>10 and signal > 10 then Color.DARK_RED else 
     if faDn and main<-10 and signal < -10 then Color.RED else
 
     if riUp and main<0 and signal < 0 then Color.Dark_GREEN else 
     if riUp and main>0 and signal > 0 then Color.GREEN else 
     if faDn and main>0 and signal > 0 then Color.DARK_RED else 
     if faDn and main<0 and signal < 0 then Color.RED else Color.CURRENT);
53S6axX.png
Here you can have a little more reading from the TMO Indicator in your chart. In case you looking another's indicators and you don't want change charts, here you can read the exact level or moment on the TMO Indicator on your Label. I'm being using this since MarryDay help me with this and normally I don't go to the indicator at all, big thanks MarryDay

Code:
# TMO Label
def lengthtmo = 14;
def calcLength = 5;
def smoothLength = 3;

def data = fold i = 0 to lengthtmo with s do s + (if close > getValue(open, i) then 1 else if close < getValue(open, i) then - 1 else 0);
def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);

def riUp = main >= main[1];
def faDn = main < main[1];

AddLabel(yes,
     if riUp and Main < -10 and signal < -10 then " TMO: " + Round(Main, 2) + " |" + " Rising Below:" + " -10 " + " " else 
     if riUp and Main > 10 and signal > 10 then " TMO: " + Round(Main, 2) + " |" + " Rising Above:" + " 10 " + " " else 
     if faDn and Main > 10 and signal > 10 then " TMO: " + Round(Main, 2) + " |" + " Falling Below:" + " 10 " + " " else 
     if faDn and Main < -10 and signal < -10 then " TMO: " + Round(Main, 2) + " |" + " Falling Below:" + " -10 " + " " else
     if riUp and Main < 0 and signal < 0 then " TMO: " + Round(Main, 2) + " |" + " Rising Below:" + " -0 " + " " else 
     if riUp and Main > 0 and signal > 0 then " TMO: " + Round(Main, 2) + " |" + " Rising Above:" + " 0 " + " " else 
     if faDn and Main > 0 and signal > 0 then " TMO: " + Round(Main, 2) + " |" + " Falling Above:" + " 0 " + " " else 
     if faDn and Main < 0 and signal < 0 then " TMO: " + Round(Main, 2) + " |" + " Falling Below:" + " -0 " + " " else "",   
     if riUp and Main < -10 and signal < -10 then Color.Dark_GREEN else 
     if riUp and Main > 10 and signal > 10 then Color.GREEN else 
     if faDn and Main > 10 and signal > 10 then Color.DARK_RED else 
     if faDn and Main < -10 and signal < -10 then Color.RED else
     if riUp and Main < 0 and signal < 0 then Color.Dark_GREEN else 
     if riUp and Main > 0 and signal > 0 then Color.GREEN else 
     if faDn and Main > 0 and signal > 0 then Color.DARK_RED else 
     if faDn and Main < 0 and signal < 0 then Color.RED else Color.CURRENT);

 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
548 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top