Schwab MACD Histogram Daily Timeframe End of Day Entry and Exit

Mike

Member
Hello...not being an expert coder, I would like to modify this code
https://usethinkscript.com/threads/basic-scoring-system.4954/
to create a strategy. Any help would be appreciated.

Here is my logic:

MACD Histogram - Daily Timeframe - End of Day Entry and Exit
MACD Line: (12-day EMA - 26-day EMA)
Signal Line: 9-day EMA of MACD Line
MACD Histogram: MACD Line - Signal Line

Condition 1: SPX Closing price is > SMA5
Condition 2: SPX Closing price is > SMA10
Condition 3: MACD Histogram is > 0
If Condition 1 AND 2 AND 3 then Buy to Open

Condition 4: SPX Closing price is < SMA5
Condition 5: SPX Closing price is < SMA10
Condition 6: MACD Histogram is < 0
If Condition 4 AND 5 AND 6 then Sell to Close

Thank you.


the code is as follows:
Code:
# https://usethinkscript.com/threads/addorder-thinkscript-backtest-buy-sell-#in-thinkorswim.741/
# https://usethinkscript.com/threads/basic-scoring-system.4954/
# Multiple Variables Scoring System - MS 10/30/23

declare lower;

# SMA5PriceVariables
   input price5 = close;
   input length5 = 5;
   input displace5 = 0;

# SMA10PriceVariables
   input price10 = close;
   input length10 = 10;
   input displace10 = 0;
 
# MACD HistogramVariables
   input fastLength = 12;
   input slowLength = 26;
   input MACDLength = 9;
   input DiffLength = 9;
   def SMAPrice5 = Average(price5[-displace5], length5);
   def SMAPrice10 = Average(price10[-displace10], length10);
   def Diff = MACD(fastLength, slowLength, MACDLength, averageType.exponential).Diff;

# Variables Scoring
   def ScoreSMAPrice5 = if close > SMAPrice5 then 1 else 0;
   def ScoreSMAPrice10 = if close > SMAPrice10 then 1 else 0;
   def ScoreDiff = if Diff > 0 then 1 else 0;
   plot FinalScore = (ScoreSMAPrice5+ScoreSMAPrice10+ScoreDiff);

# End Script

A screenshot of the indicator follows:
 
Last edited:

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
465 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