Find Stocks above simple moving average 3 days


Category:
0
0

Hi Mr. Hahn,

I was wondering if you could help with creating a TOS code. I am looking  to scan for stocks that have 3 bars of Price above the 100 day SMA(Close).  Thank you so much for all your hard work.

RESOLVED
Marked as spam
Posted by (Questions: 5, Answers: 7)
Asked on March 12, 2017 10:35 am
2217 views
0

I updated the title of your question to include more detail. The original title, ”EMA”, is two vague and actually has nothing to do with your description. I have also moved the question out of the Chart Studies topic and into the Stock Scanner topic. Now on to your request. Please define the word ”price” in your description ”3 bars of Price above”. We have 4 prices for each bar, Open, High, Low and Close. So when you say price above, does that mean just the high of the bar? Or does it mean the close of the bar? Or perhaps you need to have the entire candle above the SMA?

( at March 12, 2017 12:13 pm)
0

Thank you, as you can see I am a noob when it comes to defining what I really need. I would like to run a scan looking for 3(I would like to pick how many i’m looking for) candles closes above or bleow a certain EMA or SMA and I can pick the EMA or SMA and if its a Open, High,

( at March 12, 2017 8:42 pm)
0
Private answer

Give this a try. It does not limit the results to stocks with ONLY 3 bars above the moving average. It finds stocks where 3 OR MORE bars are above the moving average. You did not specify a preference so I picked the easiest one to write.

def sma = Average(close, 100);
def ema = ExpAverage(close, 100);
def threeClossesAboveSMA = Lowest(close - sma, 3) > 0;
def threeClossesAboveEMA = Lowest(close - ema, 3) > 0;
# Scan to use for simple moving average
plot scan = threeClossesAboveSMA;
# Scan to use for exponential moving average
#plot scan = threeClossesAboveEMA;

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on March 13, 2017 7:42 am
0
Thank you Mr. Hahn, but is there any way to only get a range of candles like 1-3 instead of infinite number above a moving avg. Also, when you say (close-sma,3) > 0 can you please explain what does this mean.
( at March 18, 2017 7:18 pm)
0

I’ll answer the second question first, so we can understand how to answer the first. Lowest(close – sma, 3) > 0; means that for each of the last three bars, including the current one, we check if the close is above the sma. Close – SMA will be positive if it’s above the sma and it will be negative if it’s below the sma. So I am just testing if the lowest value of the close minus the sma is greater than zero for the last three bars, including the current bar.
Now for the first question. We can reference previous bars using brackets [0]. The current bar is zero [0], the previous bar is one [1]. So if we want to look back 4 bars we would use [3]. With this knowledge we can apply one potential solution. Which is to change plot scan = threeClossesAboveSMA; to plot scan = threeClossesAboveSMA and close[3] < sma[3]; I added a second condition using the keyword (and). The second condition checks if the close of 4 bars ago is less then the sma of 4 bars ago. While responding to this comment I realized I made a typo in that threeClossesAboveSMA should have been threeClosesAboveSMA. I apologize for that error. I'll leave it there as proof that I am human. LOL.

( at March 18, 2017 8:13 pm)
0

Ahh it works… Thanks so much bro donation on the way!

( at March 18, 2017 11:54 pm)
0

Thank you so much for your support! Very glad I could help.

( at March 19, 2017 8:52 am)
0
Hi Pete for some reason i’m not comprehending this code. I tired to modify the code but its not giving me the right results. Can you please re-copy the correct code. This is what I have, but its not giving me the correct results because i only want 3 closes above or below a SMA. Basically, i’m looking to find inputs of : price low below 100 SMA. In the setting you can set your SMA to HIGH or LOW or OLHC ect ect
( at April 30, 2017 4:49 pm)
0

Please provide a screenshot indicating the exact pattern you are trying to pick up in the scan.

( at April 30, 2017 6:40 pm)