Posts Tagged ‘Thinkscript’

Multi-Divergence Scan for Think or Swim: MACD, RSI, CCI Divergence in Your Stock Scans

September 13, 2016

In my Multi-Divergence indicator, there is logic used that breaks the study filter when you try to use it in a scan. So I made a new indicator specifically for scanning by limiting it to only use MACD, RSI or CCI. Now it can be used in a watchlist scan, and it’s called “Pro_Divergence_Scan”. It is still a donor-only script, so use your blog donor info to access it in the Released Thinkscript Studies section of the Google site. If you’re not a donor, you can chip in by clicking the Donate button:

Instructions:  Import Pro_Divergence_Scan like any other study, then follow these directions to set up a scan with it.

Go to the scan tab in Think Desktop, and choose “Stock Hacker”.  Then you click “Add Study Filter” (First in screenshot below) then click the pencil to edit the default filter that is added (Second in screenshot):

screen-shot-2016-09-11-at-7-19-25-pm

Delete the default ADXCrossover() if there is one (Third in screenshot) and then click “Thinkscript Editor” (Fourth):

screen-shot-2016-09-11-at-7-19-47-pm

Choose your Aggregation period at the top (D for Daily in this example).  In the editor, type in “Pro_Divergence_Scan()” and then choose “Inspector” from the side panel.  You’ll see the Pro_Divergence_Scan study inputs and the four plots that you can scan for:

    1. BullDivs for Bullish Divergence on short timeframe
    2. BearDivs for Bearish Divergence on short timeframe
    3. BullDivl for Bullish Divergence on long timeframe
    4. BearDivl for Bearish Divergence on long timeframe

 

screen-shot-2016-09-11-at-7-25-30-pm

(As an aside, you can also type the name of any other study you have in your library at this thinkscript editor to get access to it for any filter.)

For the scan to trigger, you want to check for when your chosen plot value is equal to 1, because that’s what I coded the indicator to do.  To do this, add the string “==1” after the plot name, as shown here:

screen-shot-2016-09-11-at-7-25-54-pm

After this, click “Ok” and run your scan.  You may get a pop-up that warns that future changes to the study will not be reflected in this filter.  That just means that if you change the code in the Pro_Divergence_Scan, it won’t be reflected here.  The filter takes a snapshot of the code when you make the filter.  If you update the indicator, just delete the old filter and set it up again as above.

UPDATE: MACD Divergence Indicator for Think or Swim

December 10, 2014

This indicator has been updated!  See the new post here.

This has been a long time in coming.  My family life has been in upheaval for a couple years now.  I finally had a bit of time so I wanted to get this done.  Thanks for staying with me.

Many people have asked for a version of the MACD Divergence Indicator that can run in a scan.  The old one I had ran on recursive logic and so wasn’t supported in scans.  This new one uses a different philosophy that runs in real time.  Before I would use my Swing Points and check the value of the MACD against them.  Higher swing highs and lower corresponding values of MACD on those bars would signal a bearish divergence.  Now I am using Linear Regression slopes to compare divergences.  Here’s the theory of how it works:

A linear regression is a way to fit a straight line through some data such that you get the least amount of average distance from the line. If the slope of the linear regression is up, then values are generally trending upward over the set of data you put in. If the slope is negative, then the values trend downward.

So I take a linear regression of price, then get the slope of the LR, and I also take a linear regression of the standard MACD indicator and get that slope. When the price slope is positive and the MACD slope is negative, we have a bearish MACD divergence. If price slope is negative and MACD slope is positive, we have a bullish divergence. If price slope and MACD slope are the same, we have a trend continuation (up/up or down/down). This chart shows this theory in action:

howitworks

 

Here’s what my indicator actually looks like.  The small arrows are short term divergences, the larger arrows are the long term divergences.  The short and long timeframes are inputs, so you can set them at whatever you want.  This chart uses 20 and 50 as the inputs, but you can experiment with what works best for what you are trading:

whatitlookslikenew

As with all divergences, just because it is there doesn’t mean that the trend must reverse. Sometimes divergences can go on for a long time. This information is good to give you a sense that a trend might reverse, and you can plan your own entry and stop accordingly.

Now, to set set up a custom scan, you follow the instructions in these pictures:

scan1

scan2

Then when your scan runs, you will get flagged if the divergence you asked for is currently found.

This indicator is for blog donors only.  You can find it on my google site under Released Thinkscript Studies down in the Donors Only section.

Thinkscript Chat Room Comes to Think or Swim

January 17, 2012

Today I got word from Think or Swim of a new resource for Thinkscript users and developers. The ToS folks are listening to the requests of their customers for more Thinkscript support. Within the next two weeks, there will be a new chat room inside of the Think Desktop platform covering the topic of Thinkscript! The idea is to build a ToS sanctioned community where people can share ideas and scripts, or just ask for help. It will be moderated by ToS. They plan to have free chat times, and also have the occasional presenter talk about a certain topic of interest like they do in the other rooms in Think Desktop.

As you may know, I tried to put up a little discussion board, but there wasn’t enough interest. I know that there are sporadic groups of folks on the yahoo boards, or communities at sites like Thinkscripter’s. Hopefully having a centrally located area will gather more people together. I think it will also be a good place to make requests for new features in the Thinkscript language and report any bugs that we see.

I see any attention given to Thinkscript from inside ToS as a big positive, since the management types don’t necessarily see it as a big profit center. The more we as customers show up and support the work of the ToS dev team, the more firepower they have to get resources to bring us more capability.

So look for this in your Think Desktop platform soon!

Volatility-Based Trailing Stop Strategies for Think or Swim

November 15, 2010

Here is my Volatility-Based Trailing Stop indicator implemented as strategies. These are only exit strategies at the moment, so if you use long and short entry strategies of your choice, these will stop you out if the corresponding trailing stop is breached.

These files are free. Download “VolatilityTS_Strategies.zip” from “Released Thinkscript Strategies” on my Google site.

Fixed Stop Loss and Profit Target Strategies for Think or Swim

November 2, 2010

As promised, here are four strategies showing how to implement fixed stop losses and fixed profit targets for TOS. You need to add these to a chart with some entry strategy. I have included two example entries for you to test out if you want. These are called “Justbuy” and “Justsell”. If there are two green bars in a row, it goes long. If two red bars in a row, it goes short. Otherwise, the targets and stops manage the trade.

You can run a backtest on it to see the results, and play with the stops and targets to see if it improves (or worsens!). To me, this is a good quick way to test if you have any edge in an idea. If there is one, it will show up right away in a simple test. If it takes fancy tools and algorithms to squeeze out a drop of an edge, but you don’t have direct market connections and 8+ figures of capital to employ it, then you are fooling yourself and asking for pain.

These strategies are free. Download “Fixed Stops and Targets.zip” from “Released Thinkscript Strategies” on my Google site. As always, leave a comment if you have any questions or need help setting them up!