Repaints Multi-Time Frame True Momentum Oscillator (MTF) for ThinkorSwim

Repaints
TMO Alerts:
Below is the minimal, drop‑in ThinkScript snippet that you can paste at the bottom of your script. It creates alerts for:
Red → Green (bullish crossover)​
Green → Red (bearish crossover)​
And it works for both the primary and secondary TMO independently.

Ruby:
# Primary AGG
def bullCross1 = Main1 crosses above Signal1;   # Red → Green
def bearCross1 = Main1 crosses below Signal1;   # Green → Red

Alert(bullCross1, "Primary TMO: RED → GREEN (Bullish)", Alert.BAR, Sound.Ring);
Alert(bearCross1, "Primary TMO: GREEN → RED (Bearish)", Alert.BAR, Sound.Bell);

# Secondary AGG
def bullCross2 = Main2 crosses above Signal2;   # Red → Green
def bearCross2 = Main2 crosses below Signal2;   # Green → Red

Alert(bullCross2, "Secondary TMO: RED → GREEN (Bullish)", Alert.BAR, Sound.Ring);
Alert(bearCross2, "Secondary TMO: GREEN → RED (Bearish)", Alert.BAR, Sound.Bell);

@VR555 @Cedar
Thank you very much for this, @merryDay!
 
For the Dual-Aggregate TMO. How can I create a RED → GREEN Vertical line for only the second TMO when is going in the same direction as the first?
Code:
# Dual-Aggregate TMO ((T)rue (M)omentum (O)scillator)
# Idea by Mobius via OneNote
#Created by KHPro | Modified for dual aggregation
# V09.2025

declare lower;

input length = 14;
input calcLength = 5;
input smoothLength = 3;
input agg2 = AggregationPeriod.FIVE_MIN; # Secondary timeframe

# --- Primary TMO (Current Chart Timeframe) ---
def o1 = open;
def c1 = close;
def data1 = fold i1 = 0 to length
with s1
do s1 + (if c1 > getValue(o1, i1)
then 1
else if c1 < getValue(o1, i1)
then -1
else 0);
def ema1 = ExpAverage(data1, calcLength);
plot Main1 = ExpAverage(ema1, smoothLength);
plot Signal1 = ExpAverage(Main1, smoothLength);

Main1.AssignValueColor(if Main1 > Signal1 then Color.GREEN else Color.RED);
Signal1.AssignValueColor(if Main1 > Signal1 then Color.GREEN else Color.RED);
Main1.SetLineWeight(2);
Signal1.SetLineWeight(1);
Signal1.HideBubble();
Signal1.HideTitle();
addCloud(Main1, Signal1, Color.GREEN, Color.RED);

# --- Secondary TMO (User-defined Aggregation) ---
def o2 = open(period = agg2);
def c2 = close(period = agg2);
def data2 = fold i2 = 0 to length
with s2
do s2 + (if c2 > getValue(o2, i2)
then 1
else if c2 < getValue(o2, i2)
then -1
else 0);
def ema2 = ExpAverage(data2, calcLength);
plot Main2 = ExpAverage(ema2, smoothLength);
plot Signal2 = ExpAverage(Main2, smoothLength);

Main2.AssignValueColor(if Main2 > Signal2 then Color.GREEN else Color.RED);
Signal2.AssignValueColor(if Main2 > Signal2 then Color.GREEN else Color.RED);
Main2.SetLineWeight(2);
Signal2.SetLineWeight(1);
Signal2.HideBubble();
Signal2.HideTitle();
addCloud(Main2, Signal2, Color.GREEN, Color.RED);

# --- Reference Lines ---
plot zero = if IsNaN(close) then Double.NaN else 0;
zero.SetDefaultColor(Color.GRAY);
zero.HideBubble();
zero.HideTitle();

plot ob = if IsNaN(close) then Double.NaN else Round(length * 0.7);
plot os = if IsNaN(close) then Double.NaN else -Round(length * 0.7);
ob.SetDefaultColor(Color.GRAY);
os.SetDefaultColor(Color.GRAY);
ob.HideBubble();
ob.HideTitle();
os.HideBubble();
os.HideTitle();

addCloud(ob, length, Color.LIGHT_RED, Color.LIGHT_RED, no);
addCloud(-length, os, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
 
Last edited by a moderator:
I tried to make this code but the Arrows are not showing up? Any help?

Code:
#Dual_Aggregate_TMO_Arrows
# Dual-Aggregate TMO ((T)rue (M)omentum (O)scillator)
# Idea by Mobius via OneNote
# Created by KHPro | Modified for dual aggregation
# V09.2025 with arrow signals added by ChatGPT
declare lower;
input length = 14;
input calcLength = 5;
input smoothLength = 3;
input agg2 = AggregationPeriod.FIVE_MIN; # Secondary timeframe
# --- Primary TMO (Current Chart Timeframe) ---
def o1 = open;
def c1 = close;
def data1 = fold i1 = 0 to length
with s1
do s1 + (if c1 > getValue(o1, i1)
then 1
else if c1 < getValue(o1, i1)
then -1
else 0);
def ema1 = ExpAverage(data1, calcLength);
def Main1 = ExpAverage(ema1, smoothLength);
def Signal1 = ExpAverage(Main1, smoothLength);
plot TMO1 = Main1;
plot TMOSignal1 = Signal1;
TMO1.AssignValueColor(if Main1 > Signal1 then Color.GREEN else Color.RED);
TMOSignal1.AssignValueColor(if Main1 > Signal1 then Color.GREEN else Color.RED);
TMO1.SetLineWeight(2);
TMOSignal1.SetLineWeight(1);
TMOSignal1.HideBubble();
TMOSignal1.HideTitle();
AddCloud(Main1, Signal1, Color.GREEN, Color.RED);
# --- Secondary TMO (User-defined Aggregation) ---
def o2 = open(period = agg2);
def c2 = close(period = agg2);
def data2 = fold i2 = 0 to length
with s2
do s2 + (if c2 > getValue(o2, i2)
then 1
else if c2 < getValue(o2, i2)
then -1
else 0);
def ema2 = ExpAverage(data2, calcLength);
def Main2 = ExpAverage(ema2, smoothLength);
def Signal2 = ExpAverage(Main2, smoothLength);
plot TMO2 = Main2;
plot TMOSignal2 = Signal2;
TMO2.AssignValueColor(if Main2 > Signal2 then Color.GREEN else Color.RED);
TMOSignal2.AssignValueColor(if Main2 > Signal2 then Color.GREEN else Color.RED);
TMO2.SetLineWeight(2);
TMOSignal2.SetLineWeight(1);
TMOSignal2.HideBubble();
TMOSignal2.HideTitle();
AddCloud(Main2, Signal2, Color.GREEN, Color.RED);
# --- Reference Lines ---
plot zero = if IsNaN(close) then Double.NaN else 0;
zero.SetDefaultColor(Color.GRAY);
zero.HideBubble();
zero.HideTitle();
plot ob = if IsNaN(close) then Double.NaN else Round(length * 0.7);
plot os = if IsNaN(close) then Double.NaN else -Round(length * 0.7);
ob.SetDefaultColor(Color.GRAY);
os.SetDefaultColor(Color.GRAY);
ob.HideBubble();
ob.HideTitle();
os.HideBubble();
os.HideTitle();
AddCloud(ob, length, Color.LIGHT_RED, Color.LIGHT_RED, no);
AddCloud(-length, os, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
# --- Arrow Signals (both TMOs align) ---
def bullCross1 = Main1 crosses above Signal1;
def bearCross1 = Main1 crosses below Signal1;
def bullCross2 = Main2 crosses above Signal2;
def bearCross2 = Main2 crosses below Signal2;
def bullSignal = bullCross1 and bullCross2;
def bearSignal = bearCross1 and bearCross2;
plot ArrowUp = if bullSignal then -length * 0.6 else Double.NaN;
plot ArrowDown = if bearSignal then length * 0.6 else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetDefaultColor(Color.GREEN);
ArrowUp.SetLineWeight(3);
ArrowDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDown.SetDefaultColor(Color.RED);
ArrowDown.SetLineWeight(3);
 
I tried to make this code but the Arrows are not showing up? Any help?

What part isn't working...???

1769639136529.png
 
My intent was to make the arrows work only on the second TMO only if it is agreeing with the 1st.

Arrow Signals (secondary TMO triggers, primary must agree)
Replace your arrow statements with these.
Ruby:
# --- Arrow Signals (secondary TMO triggers, primary must agree) ---

def primaryBull = Main1 > Signal1;
def primaryBear = Main1 < Signal1;

def bullCross2 = Main2 crosses above Signal2;
def bearCross2 = Main2 crosses below Signal2;

def bullSignal = bullCross2 and primaryBull;
def bearSignal = bearCross2 and primaryBear;

plot ArrowUp = if bullSignal then main2 else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetDefaultColor(Color.GREEN);
ArrowUp.SetLineWeight(3); 

plot ArrowDown = if bearSignal then main2 else Double.NaN;
ArrowDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDown.SetDefaultColor(Color.RED);
ArrowDown.SetLineWeight(3);
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
1652 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