Join useThinkScript to post your question to a community of 21,000+ developers and traders.
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/
![]()
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?
# 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);
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 likeAddLabel(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.
# 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 . . . .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);
# 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);
AddLabel(1,"Difference = " + round(Main - Signal,2), if Main > Signal then color.dark_green else color.dark_red);
@MerryDay How do I edit this scanner scan so that it can only scan for momentum that is above 0?@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];
input showlabels = yes ;
input paintcandles = no ;
input length = 14;
input calcLength = 5;
input smoothLength = 3;
input ob = 10;
input os = -10;
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);
DefineGlobalColor("CoverShorts", CreateColor(50, 200, 255)) ;
DefineGlobalColor("TrendBEGIN", CreateColor(0, 0, 255)) ;
DefineGlobalColor("Rising", CreateColor(0, 165, 0)) ;
DefineGlobalColor("Overowned", CreateColor(255, 139 ,61)) ;
DefineGlobalColor("TrendEnd", CreateColor(255, 204, 0)) ;
DefineGlobalColor("Falling", CreateColor(225, 0, 0)) ;
DefineGlobalColor("Neutral", CreateColor(204, 204, 204)) ;
AddLabel(showlabels,
if main < os then "CoverShorts " +round(main,0) else
if main > ob then "Overowned " +round(main,0) else
if main crosses above os then "TREND BEGIN!" else
if main crosses below ob then "TREND END!" else
if main < signal then "BEARISH " +round(main,0) else
if main >= main[1] then "RISING " +round(main,0) else
if main < main[1] then "FALLING " +round(main,0) else
"NEUTRAL " +round(main,0),
if main < os then GlobalColor("CoverShorts") else
if main > ob then GlobalColor("Overowned") else
if main crosses above os then GlobalColor("TrendBEGIN") else
if main crosses below ob then GlobalColor("TrendEND") else
if main < signal then GlobalColor("falling") else
if main > main[1] then GlobalColor("rising") else GlobalColor("neutral")) ;
AssignPriceColor(
if !paintcandles then color.CURRENT else
if main < os then GlobalColor("CoverShorts") else
if main > ob then GlobalColor("OVEROWNED") else
if main crosses above os then GlobalColor("TrendBEGIN") else
if main crosses below ob then GlobalColor("TrendEND") else
if main < signal then GlobalColor("falling") else
if main > main[1] then GlobalColor("rising") else GlobalColor("neutral")) ;
# End Code TMO
#
# 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 ob = 10;
input os = -10;
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);
#ScanTrigger
# for CoverShorts = ScanTrigger = 1
# for Overowned = ScanTrigger = 2
# for TREND BEGIN!= ScanTrigger = 3
# for TREND END! = ScanTrigger = 4
# for BEARISH = ScanTrigger = 5
# for RISING = ScanTrigger = 6
# for FALLING = ScanTrigger = 7
# for NEUTRAL = ScanTrigger = 0
Plot scanTrigger =
if main < os then 1 else
if main > ob then 2 else
if main crosses above os then 3 else
if main crosses below ob then 4 else
if main < signal then 5 else
if main >= main[1] then 6 else
if main < main[1] then 7 else 0 ;
# End Code TMO
I added this script to a watchlist. Can anyone color the backgrounds based on the script? I tried myself but was unsuccessful. TIAHi, Merry, I came across a code where you added some labels... I made some slight changes to the labels, but wanted to know about how I could having TOS scan for such things as "Cover Shorts", "Trend Begins," and "Bearish" etc. Is there a way that you could help me so that the following labels can be scanned for in TOS? Here is the code:
input showlabels = yes ;
input paintcandles = no ;
input length = 14;
input calcLength = 5;
input smoothLength = 3;
input ob = 10;
input os = -10;
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);
DefineGlobalColor("CoverShorts", CreateColor(50, 200, 255)) ;
DefineGlobalColor("TrendBEGIN", CreateColor(0, 0, 255)) ;
DefineGlobalColor("Rising", CreateColor(0, 165, 0)) ;
DefineGlobalColor("Overowned", CreateColor(255, 139 ,61)) ;
DefineGlobalColor("TrendEnd", CreateColor(255, 204, 0)) ;
DefineGlobalColor("Falling", CreateColor(225, 0, 0)) ;
DefineGlobalColor("Neutral", CreateColor(204, 204, 204)) ;
AddLabel(showlabels,
if main < os then "CoverShorts " +round(main,0) else
if main > ob then "Overowned " +round(main,0) else
if main crosses above os then "TREND BEGIN!" else
if main crosses below ob then "TREND END!" else
if main < signal then "BEARISH " +round(main,0) else
if main >= main[1] then "RISING " +round(main,0) else
if main < main[1] then "FALLING " +round(main,0) else
"NEUTRAL " +round(main,0),
if main < os then GlobalColor("CoverShorts") else
if main > ob then GlobalColor("Overowned") else
if main crosses above os then GlobalColor("TrendBEGIN") else
if main crosses below ob then GlobalColor("TrendEND") else
if main < signal then GlobalColor("falling") else
if main > main[1] then GlobalColor("rising") else GlobalColor("neutral")) ;
AssignPriceColor(
if !paintcandles then color.CURRENT else
if main < os then GlobalColor("CoverShorts") else
if main > ob then GlobalColor("OVEROWNED") else
if main crosses above os then GlobalColor("TrendBEGIN") else
if main crosses below ob then GlobalColor("TrendEND") else
if main < signal then GlobalColor("falling") else
if main > main[1] then GlobalColor("rising") else GlobalColor("neutral")) ;
# End Code TMO
The following thinkScript of the true momentum oscillator was created by Mobius.
![]()
thinkScript Code
Rich (BB 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.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); # End Code TMO
Shareable Link
https://tos.mx/yXqNwi
Nice indicator. It would be fun to have a chart where the candlestick colors mimic the color of this True Momentum Oscillator. What would the code be for that?The following thinkScript of the true momentum oscillator was created by Mobius.
![]()
thinkScript Code
Rich (BB 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.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); # End Code TMO
Shareable Link
https://tos.mx/yXqNwi
# 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 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);
plot Main = ExpAverage(EMA5, smoothLength);
plot Signal = ExpAverage(Main, smoothLength);
Main.AssignValueColor(if Main > Signal
then color.green
else color.light_red);
Signal.AssignValueColor(if Main > Signal
then color.green
else color.light_red);
Signal.HideBubble();
Signal.HideTitle();
addCloud(Main, Signal, color.green, color.light_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);
def BUYsignal =Main < OS and Main crosses above Signal and Main < os;
def SELLsignal = Main > OB and Main crosses below Signal and Main > ob;
# Alerts
Alert(SellSignal[AlertDisplace], " ", Alert.Bar, Sound.ring);
# 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;
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
![]() |
Archived: RSI Divergence Indicator | Indicators | 131 | |
![]() |
Archived: Opening Range Breakout | Indicators | 340 | |
![]() |
Archived: Supertrend Indicator by Mobius for ThinkorSwim | Indicators | 312 | |
![]() |
TMO with Higher Agg_Mobius @ TSL | Indicators | 204 | |
![]() |
TMO True Momentum Oscillator For ThinkOrSwim | Indicators | 121 |
Start a new thread and receive assistance from our community.
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.
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.