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 BuySignalPlot = BuySignal;
plot SellSignalPlot = SellSignal;

BuySignalPlot.SetDefaultColor(Color.UPTICK);
SellSignalPlot.SetDefaultColor(Color.DOWNTICK);

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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