Scan with two moving averages and candlestick pattern


Category:
0
0

How would you write this custom scanner?  I need a scan that is based on two minute interval.  I need the 20SMA above the 200SMA and the close above the 20SMA.  Then I need pattern of Green, Red, Green or Green, Red, Red, Green.  Could you help me with this please?

Marked as spam
Posted by (Questions: 3, Answers: 1)
Asked on January 3, 2020 3:08 pm
228 views
1
Private answer

There is no need to write any custom code for the 20 period SMA above the 200 SMA. Nor is there any need to write custom code for the close being above the 20 period SMA. All of those elements from your specifications can be constructed with just a few clicks of the mouse using the Condition Wizard.

Details here:

https://www.hahn-tech.com/thinkorswim-condition-wizard/

Once you learn how to use the Condition Wizard you will realize there is very little need to write any custom code to create your scans. It is even possible to build a condition for candlestick patterns, such as green-red-green. But I will provide a custom code solution for your candlestick pattern. You can build a separate study filter using the Condition Wizard to cover the moving average elements of your specifications. Then add a second study filter to contain this custom code.

Here is the code for your candlestick pattern filter:

def greenCandle = close > open;
def redCandle = close < open;
def patternOne = greenCandle and redCandle[1] and greenCandle[2];
def patternTwo = greenCandle and redCandle[1] and redCandle[2] and greenCandle[3];
plot scan = patternOne or patternTwo;

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 4, 2020 2:42 pm
0
Thank you for this code. It works well. I ran into an issue when I was implementing. I am a software developer and I was using it with the hope that the td-ameritrade api would deliver a dynamically generated watchlist from this scan. I discovered that watchlist are only static, meaning once a stock is in the watchlist, nothing is added or subtracted from it. Do you know of any service that could act like a stock scanner, like td-ameritrade, but through an api? Thank you for your website.
( at February 8, 2020 5:04 pm)
0
No, I don't work with API's at all. However if you are working in the Thinkorswim platform, you can save the custom scan. You will be able to assign that as the source of a watchlist, which will dynamically update in real time as the scan results change.
( at February 9, 2020 8:53 am)