50/200 SMA Cross Daily with entry requiring Green MACD Histogram

brianqw

New member
I have much experience writing and debugging Excel VBA script, but no experience with thinkscript. I have had Copilot AI write studies for 50/200 SMA Cross with various different filters, but it didn't work, even after much more collaboration with Copilot. Can anyone please give me working thinkscript for 50/200 SMA cross and better yet adding the condition that the MACD histogram be green to take the signal?

Thanks much for any help offered!

Brian
 
Solution
I have much experience writing and debugging Excel VBA script, but no experience with thinkscript. I have had Copilot AI write studies for 50/200 SMA Cross with various different filters, but it didn't work, even after much more collaboration with Copilot. Can anyone please give me working thinkscript for 50/200 SMA cross and better yet adding the condition that the MACD histogram be green to take the signal?

Thanks much for any help offered!

Brian
Hi Brian,
This script plots green arrows when the 50 SMA crosses above the 200 SMA and the MACD histogram is positive, and red arrows when the 50 SMA crosses below the 200 SMA and the MACD histogram is negative.
Code:
declare upper;

# Inputs
input shortSMA_length = 50;
input...
I have much experience writing and debugging Excel VBA script, but no experience with thinkscript. I have had Copilot AI write studies for 50/200 SMA Cross with various different filters, but it didn't work, even after much more collaboration with Copilot. Can anyone please give me working thinkscript for 50/200 SMA cross and better yet adding the condition that the MACD histogram be green to take the signal?

Thanks much for any help offered!

Brian
Hi Brian,
This script plots green arrows when the 50 SMA crosses above the 200 SMA and the MACD histogram is positive, and red arrows when the 50 SMA crosses below the 200 SMA and the MACD histogram is negative.
Code:
declare upper;

# Inputs
input shortSMA_length = 50;
input longSMA_length = 200;
input macd_fastLength = 12;
input macd_slowLength = 26;
input macd_macdLength = 9;

# Calculate SMAs
def shortSMA = simplemovingavg(close, shortSMA_length);
def longSMA = simplemovingavg(close, longSMA_length);

# Calculate MACD components
def macdValue = MovingAverage(AverageType.EXPONENTIAL, close, macd_fastLength) - MovingAverage(AverageType.EXPONENTIAL, close, macd_slowLength);
def signal = MovingAverage(AverageType.EXPONENTIAL, macdValue, macd_macdLength);
def macdHist = macdValue - signal;

# Detect SMA Crosses
def crossAbove = shortSMA crosses above longSMA;
def crossBelow = shortSMA crosses below longSMA;

# Condition: MACD Histogram color
def macdGreen = macdHist > 0;
def macdRed = macdHist < 0;

# Signals with MACD histogram color filter
def buySignal = crossAbove and macdGreen;
def sellSignal = crossBelow and macdRed;

# Plot SMAs
plot SMA50 = shortSMA;
SMA50.SetDefaultColor(Color.CYAN);
plot SMA200 = longSMA;
SMA200.SetDefaultColor(Color.ORANGE);

# Plot buy/sell arrows on price chart
plot BuyArrow = if buySignal then low else Double.NaN;
BuyArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuyArrow.SetDefaultColor(Color.GREEN);
BuyArrow.SetLineWeight(3);

plot SellArrow = if sellSignal then high else Double.NaN;
SellArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellArrow.SetDefaultColor(Color.RED);
SellArrow.SetLineWeight(3);
I hope this is what you were looking...
If not, just say the word and I’ll be happy to help you tweak it!
 
Solution

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