Need watchlist for close where the price crosses below a 10 period SMA

craigjjmorrison

New member
VIP
In the code below, I tried hard to isolate the close for the bar during which the price first crossed below the SMA. With every attempt to write this, the answer I get seems to be pulled from a hat. In some tests, I have to go back several days just to determine where the return falls within the stock's daily price range.

This code is in a watchlist column with a five-minute aggregation.
Code:
def FloorIsOpen = SecondsFromTime(930) >= 0 and SecondsTillTime(1600) >= 0;
def SMA10 = SimpleMovingAvg(Close,10);
def Top = Max(Open,Close);
def SMACross = if !FloorIsOpen[1] and FloorIsOpen then 0 else if FloorIsOpen and SMACross[1] == 0 and crosses(Top,SMA10,CrossingDirection.BELOW) then Close else SMACross[1];

Plot X = SMACross;
 
Last edited by a moderator:
In the code below, I tried hard to isolate the close for the bar during which the price first crossed below the SMA. With every attempt to write this, the answer I get seems to be pulled from a hat. In some tests, I have to go back several days just to determine where the return falls within the stock's daily price range.

This code is in a watchlist column with a five-minute aggregation.
Code:
def FloorIsOpen = SecondsFromTime(930) >= 0 and SecondsTillTime(1600) >= 0;
def SMA10 = SimpleMovingAvg(Close,10);
def Top = Max(Open,Close);
def SMACross = if !FloorIsOpen[1] and FloorIsOpen then 0 else if FloorIsOpen and SMACross[1] == 0 and crosses(Top,SMA10,CrossingDirection.BELOW) then Close else SMACross[1];

Plot X = SMACross;

You may be making it more difficult than needed... Either that or we need more details...

Ruby:
close crosses below Average(close, 10);
close[1] crosses below Average(close, 10)[1];

This code will trigger each time close crosses below the SMA10... You can also use an offset to test if the cross was in the previous candle by using the second example... I would recommend the first example... That's all the code needed for the Scan to return those results... For only between 9:30 and 16:00 just leave Extended Hours unchecked...
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
1118 Online
Create Post

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