StockFetcher Forums · General Discussion · ThinkScript<< >>Post Follow-up
dleather25
20 posts
msg #155964
Ignore dleather25
2/26/2021 12:49:51 AM

Hello, this may be a shot in the dark but I'm trying to develop a ThinkScript filter because Stockfetcher is only limited to penny stocks that are in the United States, I was wondering if anyone has any idea how to code ThinkScript and if they could give me a couple syntax examples that would be enough to get me started figuring out how to develop my own filters. I hate asking for help, but I am so used to this syntax and have developed some pretty decent stock filters here just want access to all of the stocks instead of just the ones based in the US.

If by chance anyone knows the coding for TOS this would help me get started

->Accumulation distribution is above accumulation distribution 3 days ago
close is below 10
close is above close 5 days ago
->OBV is above OBV 3 days ago
volume is above 100,000
average volume is above 100,000
->MACD Fast Line is below MACD Fast Line 4 days ago
->MACD Fast Line is below 0 for the last 5 days
plot (draw for SF) ma(50)


I put an arrow by the ones that are most difficult to code, I've spent hours trying to code but it always shows up red or doesn't allow me to apply it. Any help is appreciated!!!




klynn55
702 posts
msg #155965
Ignore klynn55
2/26/2021 12:52:53 AM

you might try here : https://usethinkscript.com/

meatyboy
5 posts
msg #155966
Ignore meatyboy
2/26/2021 1:26:39 AM

Because there isn't any really special demands with your scan, it's entirely possible to build that in the scanner itself. The only special coding you'd need to add to the scan would be :

declare lower;
plot Raise = close is greater than close from 5 bar ago;

dleather25
20 posts
msg #155993
Ignore dleather25
3/1/2021 1:00:13 PM

Thanks, I am going to keep playing with it and see what I can do.

klynn55
702 posts
msg #155994
Ignore klynn55
3/1/2021 2:48:52 PM

many times i have seen posters asking for help and getting it at the site i posted! it's free also, unless you decide to become a vip member!

lis
28 posts
msg #156068
Ignore lis
3/8/2021 5:46:56 PM

First, a few more sites with good information on thinkScript -

ThinkOrSwim Learning Center's Tech Indicators reference:
https://tlc.thinkorswim.com/center/reference/Tech-Indicators

ThinkOrSwim Learning Center's thinkScript reference (including tutorials):
https://tlc.thinkorswim.com/center/reference/thinkScript

Hahn-Tech, LLC - basically a bunch of stuff around ThinkOrSwim and creating scans, studies, and strategies, including a forum-like membership:
https://www.hahn-tech.com

Now, I'm assuming by "filter" you mean you're looking for what TOS calls a "scan". Based on that assumption, here's something to start with...

* Declare variables with `def` or `input`. `input` causes you to be able to edit those values in the scan's settings.
* You probably know that you remark out a line with the `#` character.
* You probably know that you need to end each line with a semicolon (`;`)
* Where I've given URLs, you can find the parameters, if any, for a given study.

Using the parameters, you can set the values of your choice, such as with the MACD code I have below.
If you use the parameters in order, you don't need to specify parameter labels; however, if you use only some of the parameters, or they're not in order, you need to specify. For example:

MACD(fastLength, slowLength, MACDLength)
-- OR --
MACD("fast length"=12, "average type"=AverageType.EXPONENTIAL)

* The following sample code times out on execution, probably because of the way I threw in the MACD part. I don't get an orange triangle, meaning that the script is "too complex" in TOS' opinion. It attempts to bring results, but then times out. It works if you remark out the MACD condition, which I've done, as it's not really going to do what you want anyway.

* The following sample code is using some default values. Again, check the Learning Center for the parameters for which you might want to set values.


# https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/A-B/AccumulationDistribution
def accumulationDistributionAbove3DaysAgo = AccumulationDistribution() > AccumulationDistribution()[2];

def closeIsBelow10 = close < 10;
def closeIsAboveClose5DaysAgo = close > close[4];

# https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/O-Q/OnBalanceVolume
def OBVisAboveOBV3DaysAgo = OnBalanceVolume() > OnBalanceVolume()[2];
def volumeIsAbove100k = volume > 100000;
def averageVolumeIsAbove100k = Average(volume) > 100000;

#####
THE FOLLOWING CODE IS VALID, BUT THE RESULTS AREN'T.
Unlike SF, TOS' MACD doesn't have the fast and slow lines broken out.
The HAHN-TECH site I've referenced has an example calculation using the various parts that make up the MACD.
#####
# https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MACD
# https://www.hahn-tech.com/ans/finding-a-macd-crossover-below-the-zero-line/
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
def MACDFastLineIsBelowFastLine4DaysAgo =
MACD(fastLength, slowLength, MACDLength) < MACD(fastLength, slowLength, MACDLength)[3];

def MACDFastLineIsBelowZeroForTheLast5Days = MACD(fastLength, slowLength, MACDLength) > 0 and MACD(fastLength, slowLength, MACDLength)[1] > 0 and MACD(fastLength, slowLength, MACDLength)[2] > 0 and MACD(fastLength, slowLength, MACDLength)[3] > 0 and MACD(fastLength, slowLength, MACDLength)[4] > 0;
#####

# final result for scan ("filter") - but with MACD stuff remarked out
plot scan =
accumulationDistributionAbove3DaysAgo and
closeIsBelow10 and
closeIsAboveClose5DaysAgo and
OBVisAboveOBV3DaysAgo and
volumeIsAbove100k and
averageVolumeIsAbove100k; # and
#MACDFastLineIsBelowFastLine4DaysAgo and
#MACDFastLineIsBelowZeroForTheLast5Days;


StockFetcher Forums · General Discussion · ThinkScript<< >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


Copyright 2018 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.