close above moving average for 2 days.

JE $$

Member
Im trying to create a scan to identify stocks that have two sequential closes above a 10D SMA of the high
in other words, i want to find stocks who closed above a 10D SMA of the highs for two days in a row
I can get part of the way but have a hard time figuring out how to get the two days in a row part.
what i have so far is below - trying to accomplish the two days in a row part by altering the "within" parameter but it doesnt work well
can anyone help?
basically using this as a part of a moving average channel strategy(MAC) - two closes above the MAC = buy signal

close is greater than SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA" and close is greater than SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA" within 2 bars and close crosses above SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA" within 3 bars
 
@rad14733's code will give you the most recent close against historical moving average points. This will give you the historical close against the historical sma points:
Code:
close is greater than SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA" 
and close[1] is greater than SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA"[1] 
and close[2] crosses above SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA"[2]
All I added to the good code above is an index value on the close prices. Both are good code, but do different things. I didn't dig into your strategy to know which one you wanted, but thought I would put this into the thread just for good measure.

happy trading,
mashume
 
@JE $$ Try:

Ruby:
close is greater than SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA"
and close is greater than SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA"[1]
and close crosses above SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA"[2]

Also check out https://tlc.thinkorswim.com/center/reference/thinkScript/Operators/Indexing for more information...
Thanks for looking into this. I really appreciate it. I used yourcode to come up with the following scan:

https://tos.mx/c4ajrOt

It seems to get some of what I'm looking for but also some aberrant results and I cant figure out why.

My strategy is that I have a moving average channel with the top line of the channel being the highs of the day, for 10 days.
So a 10D SMA of the highs.

I want to find stocks who 3 days ago were not above that level.
two days ago closed above that level
and then today closed above that level.

So essentially I get a stock who has closed above the 10D SMA of the highs for 2 days only.
The thought being that this indicates the start of a new uptrend (jake bernstein strategy)

Can you think of how to modify it to accomplish this? Also, I was wrong in my initial code where I put "close crosses" and it shouldhave been "close is greater than" for all of them.
 
@rad14733's code will give you the most recent close against historical moving average points. This will give you the historical close against the historical sma points:
Code:
close is greater than SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA"
and close[1] is greater than SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA"[1]
and close[2] crosses above SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA"[2]
All I added to the good code above is an index value on the close prices. Both are good code, but do different things. I didn't dig into your strategy to know which one you wanted, but thought I would put this into the thread just for good measure.

happy trading,
mashume
Mashume, thanks for looking into this. I wasnt as clear as I should have been.
My strategy is that I have a moving average channel with the top line of the channel being the highs of the day, for 10 days.
So a 10D SMA of the highs.

I want to find stocks who 3 days ago were not above that level.
two days ago closed above that level
and then today closed above that level.

So essentially I get a stock who has closed above the 10D SMA of the highs for 2 days only.
The thought being that this indicates the start of a new uptrend (jake bernstein strategy)

Can you think of how to modify it to accomplish this? Also, I was wrong in my initial code where I put "close crosses" and it shouldhave been "close is greater than" for all of them.

I asked rad14733 too, so we can see his thoughts as well.
thanks for everyones time - you guys are awesome
 
I think this gets stocks who closed for 2 days above the 10D SMA of the highs:
sum(close > Average(High,10), 2) >= 2

But, how to make the condition that 3 days ago it was below the 10D SMA of the highs?
 
@rad14733's code will give you the most recent close against historical moving average points. This will give you the historical close against the historical sma points:
Code:
close is greater than SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA"
and close[1] is greater than SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA"[1]
and close[2] crosses above SimpleMovingAvg("price" = HIGH, "length" = 10)."SMA"[2]
All I added to the good code above is an index value on the close prices. Both are good code, but do different things. I didn't dig into your strategy to know which one you wanted, but thought I would put this into the thread just for good measure.

happy trading,
mashume
sorry- now i see the [] you put in
 

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