# Combine ThinkorSwim MomentumSMA and Momentum Studies into a Strategy

#### 0Predictions

##### New member
I'm working on combining the ThinkorSwim MomentumSMA and Momentum Studies into a combined Strategy but need some help as i'm not able to get the strategy to work correctly. Here is the two generic Studies along with my attempt to combine them into a Strategy. There is something I have incorrect here that I can't seem to fix. Thanks in advance for your help!
#Momentum Study
# TD Ameritrade IP Company, Inc. (c) 2007-2023
declare lower;
input length = 12;
input price = close;
input showBreakoutSignals = no;
assert(length > 0, "'length' must be positive: " + length);
plot Momentum = price - price[length];
plot ZeroLine = 0;
plot UpSignal = if Momentum crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Momentum crosses below ZeroLine then ZeroLine else Double.NaN;
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);
Momentum.SetDefaultColor(GetColor(1));
ZeroLine.SetDefaultColor(GetColor(0));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

#MomemtumSMA
# TD Ameritrade IP Company, Inc. (c) 2007-2023
declare lower;
input price = close;
input momentumLength = 100;
input smaLength = 300;
assert(momentumLength > 0, "'momentum length' must be positive: " + momentumLength);
plot Momentum = price - price[momentumLength];
plot Avg = Average(data = Momentum, length = smaLength);
plot ZeroLine = 0;
Momentum.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(0));
plot upSignal = if Momentum crosses above Avg then Avg else Double.NaN;
plot DownSignal = if Momentum crosses below Avg then Avg else Double.NaN;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Here is my attempt to combine the two studies above into a Strategy together:
# Momentum Strategy

input price = close;
input momentumLength = 100;
input smaLength = 300;

assert(momentumLength > 0, "'momentum length' must be positive: " + momentumLength);

plot ZeroLine = 0;
def Momentum = price - price[momentumLength];
def Avg = Average(data = Momentum, length = smaLength);

# Signal conditions
def BuySignal = Momentum > Avg and Momentum[1] <= Avg[1] and Momentum crosses above ZeroLine;
def SellSignal = Momentum < Avg and Momentum[1] >= Avg[1] and Momentum crosses below ZeroLine;

# Plot signals on the same day
plot SellSignalPlot = SellSignal;

SellSignalPlot.SetDefaultColor(Color.DOWNTICK);

# Strategy orders
AddOrder(OrderType.SELL_TO_CLOSE, condition = SellSignal, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "SellSignal");

Combine RSI with On Balance Volume in ThinkorSwim? Questions 37
Combine PLOT and ROUND? Questions 1
Combine Two Studies Questions 1
Combine VWAP - Coppock Questions 3
Combine William% and RSI Questions 5

87k+ Posts
352 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?