Saturday, October 3, 2015

thinkscript included: sdi_bnh_label - display buy 'n hold p&l in a chart label

hi folks, i know it's been a while but i've been working on a bunch of things and i have a backlog of stuff to get out to you. here's the first:

the sdi_bnh_label displays the percentage gain/loss that one would have achieved had one bought the charted equity on the open of the first bar of the chart. here's what i'm talking about:
 
spy with bnh label
i find that this is particularly helpful when combined with the sdi_yield_label on a 1 year chart:

spy with bnh and yield labels
you see, some data providers treat dividends as little splits of the underlying equity but tos charts do not, which is a positive in my book. here we can see that the gain in spy in the past 52 weeks has been entirely from dividends.

here's the code: (how to install)

Sunday, August 9, 2015

get the fed-wind at your back with sdi_corLabel - correlation percent in a chart label. (thinkscript included)

'don't fight the fed' is the watch-phrase of wallstreet. but, how do you know if your investment is fighting the fed? the fed controls the inter-bank overnight loan rate which forms a low-bound on interest rates overall. when this rate is changed all the other interest rates tend to change in lockstep. of particular influence on stocks is the ten-year treasury yield which forms the basis of home mortgage rates (e.g. 10 year treasury yield + 2 pts is a common recipe for a mortgage quote.) so it behooves one to know how ones investments are affected by interest rates, which can be understood by the correlation to the tnx 10-year treasury index. here's the picture: 

Sunday, August 2, 2015

souping thinkorswim: purge your simtrades

if you have discovered the tos analyze tab then you undoubtedly have created simtrades for analysis. these simtrades don't go away until you delete them and they consume considerable resources in the java heap. here's how to search and destroy these resource 'suckers':

go to the analyze tab. then blank out any entry in the symbol text entry box.  this will cause the positions and simulated trades section to show everything. then click on the expand all dropdown panels button which has an icon that looks like multiple overlapping triangles. here's what this should look like:


analyze tab showing all positions and simulated trades expanded
then scroll through the list and delete all the simtrades that you don't need anymore, especially those that were for options that have expired which will be highlighted in red. alternatively, you can click on the show actions menu button, adjacent to the expand all dropdown panels button, and select delete simulated trades as a shortcut if you are relatively sure there aren't any simtrades you want to keep.

when i deleted about a score or so of my old simtrades i got back several hundred megabytes of memory. besides recovering memory, eliminating these forgotten objects speeds up the garbage collector because it then has fewer live objects in its list to evaluate. 

Thursday, June 18, 2015

thinkscript included: sdi_afterhours - display pre- and post-market price levels on a daily chart

previously, one needed to switch from a day time-aggregation to an intraday in order to see after-hours pricing. now, with this new chart study, sdi_afterhours, one can see after-hours pricing on a chart with day time-aggregation. here's a picture of this:
spy with after-hours pricing
the blue level shows where after-hours trading has moved price. this includes pre-market pricing. when the pre- or post-market session ends the after-hours price hides.

caveat: the stock must have options trading on it for afterhours to display. 

here's the code:

Sunday, June 14, 2015

thinkscript included: sdi_mfc rev:1.1 cluster indicator with overlay option

the market forecast indicator is a trio of oscillators that operate in multiple time-frames. i find that this indicator is most useful when the three oscillators cluster in the over-bought or over-sold areas, a condition that purports to foretell a reversal. the reversal might come a day or two to a week after the cluster, so i use this as mostly for a heads-up. with the spaghetti of plots it is a little hard sometimes to see when a cluster occurred, especially if it was just for one day. so i added a little indicator to help point out exactly when the cluster happens:
spy with sdi_mfc rev:1.1, cluster indication
a side benefit of this is that if you are only interested in the cluster indication then you can hide the momentum, shortTerm, intermediate, overbought and oversold plots and place the study in the upper price graph like this:


spy with sdi_mfc in cluster overlay mode.


now that's a good deal tidier.

as always the revised code is maintained on the original post for this chart study.

Sunday, June 7, 2015

thinkscript included: sdi_closeLevel - plot the eod price on a heiken-ashi candle.

i have become enamored with the heiken-ashi candle. the heiken-ashi candle re-jiggers the way open and close are represented. here's a picture that 'splains the heiken-ashi basics:
heiken-ashi explained
the tails point to the same high/low of day as regular candles but the heiken-open is the mid-point of the previous day's heiken-ashi body and the heiken-close is the average price of the day as represented by (open+high+low+close)/4 (aka ohlc4.) the advantage of this presentation of the data is that a series of fat-body/single-tailed candles makes it easy to identify a trend in its nascent stages. also, the heiken-open represents good trade placement in the trend direction. so, if the days trading crosses through the heiken-open to create a two-tailed candle then the trend is questionable and might be reversing.

however, the heiken-ashi candle is a little disconcerting. i think this is because it hides where the market leaves price at the end-of-the-day. so i wrote a thinkscript that shows the eod price in relationship to the heiken-ashi candle. here's what this looks like:
heiken-ashi candles with eod prices
when the eod price is above the heiken-body i color it green because the bulls won the battle on that day and when the eod price is below the heiken-body i color it red because the bears won the battle. if the eod price is inside the heiken-body then i color it black - a stalemate was achieved. i think this improves the heiken-ashi system.

here's the code:

Tuesday, May 19, 2015

thinkscript included: sdi_ivp_alert - implied volatility percentile that is compatible with study alerts.

it was brought to my attention that implied volatility percentile (aka rank) was not an available selection when composing alerts. this is because, as far as tos is concerned, iv percentile is a number that only has relevence as a stat on the trade tab or as a study filter on the scan tab. the fact that people might want to set alerts when iv percentile reaches a level of interest perhaps has eluded them? 

into this void i bring the sdi_ivp_alert study. this chart study merely plots the iv percentile in a fashion that is compatible with alerts. here's how it looks on a chart:
spy with sdi_ivp_alert study
just a simple line plot, no bells and whistles, those you have to add via marketWatch/alerts/study alert:

here's the code:

Monday, April 27, 2015

souping thinkorswim: run two instances.

you can run two instances of the thinkdesktop from the same computer. that is, i run a second thinkdesktop and log-in twice. two is permitted by the tda servers but i think a 3rd instance will trigger a failure.  i just tried this today from a single laptop and it worked great. on one instance i had all my normal gadgets, watchlists w. custom columns, charts, studies and strategies running. on the second instance i deleted all gadgets, watchlists and displayed no charts - but i ran the shadow trader presentation from this second instance.

previously, i ran all this stuff including the shadow trader presentation from a single instance and was getting pesky long pauses when the garbage collector ran. my observations of the task manager during these gc-pauses revealed that one of my dual cpu's was running flat-out while the other one was idle - giving the misimpression of a non-constrained cpu resource (50% idle.) research on oracle's website revealed some interesting facts about the java garbage collecter that led me to this dual- instance experiment:

  1. the java heap does not maintain a linked-list of free memory blocks. free memory is one contiguous block that is doled out as requested.
  2. the more objects in use the longer the gc takes to run. this is because there is no freelist. instead, the gc performs a tree-search of live objects, marking them as it sweeps through the list, then, infers that anything not marked as 'alive' is trash. the more live objects there are, the longer this takes.
  3. trash compaction is part of every gc run. again, because there is no free-list, all live objects are moved around so that the free memory is one contiguous space at the end of a gc run. this might put a write-load on the page-file but that is why i went with the solid state disk.
  4. the garbage collector is single threaded. no matter how many concurrent threads the application codes for, the gc is mostly a single threaded affair that puts all application threads into suspension while it runs. this explains why i see one cpu pinned-out while the other is idle.
so now, with the dual tos instances, i have two heaps and the possibility of dual garbage collection with fuller cpu utilization. each heap has fewer live objects to contend with, so the gc-pauses are much smaller - and at least i can listen to brad agunas while i am waiting.


Saturday, April 25, 2015

thinkscript included: sdi_advmLabel - average dollar volume in millions label

some people claim you should select only stocks that trade a million shares a day. however, there are plenty of penny-stocks that trade a million shares for which it is prudent to stay away from. also, there are worthwhile high priced stocks that trade fewer than a million shares. it is my contention that this million-share selection criterion is an approximation for average dollar-volume (adv) or the average price multiplied by the average share-volume. so i wrote a chart label that displays this value. here's what this looks like:
spy with sdi_advmLabel
the 'M' in the label stands for millions. so the spy etf represents how 20 billion dollars changes hands per day, on average, over the last 20 days. if you use a $10 price minimum in conjunction with the 1million share criterion then what you are really looking for is a stock that has an average-dollar-volume of 10 million, so why not just look for that?

here's the code:

Wednesday, April 1, 2015

how now dow/gold?

the dow/gold ratio expresses the value of the dow in terms of a commodity that has a relatively fixed store of value. economists look at the dow/gold to get an idea of how the economy is doing ex-inflation and ex-monetary policy. here's how this looks:



we are channeling to the upside but just revisiting a resistance level from 2008. the larger picture of this has formed a large cup as in the cup 'n handle pattern which you can see in this big-picture. if we are following that pattern we should see a break above 15.2, perhaps to 16ish, followed by a shallow pullback. the break of that 16ish resistance should produce a rally to higher levels which technical analysis would predict to be around 26. all this means: dow up, gold down.

Sunday, March 29, 2015

seasonal 5 day hold on spy

the following chart shows the seasonal performance of buying $10,000 of spy on trading day 60 (monday 3/30/15) and holding for 5 days:

spy with sdi_seasonalStgy study

Friday, March 27, 2015

caveat emptor on unusual otm call volume

there's this rumor going around among option traders that 25% of all otm calls are insider trading. this rumor derives from the andrew ross sorkin story from last june (study asserts startling number of insider rogues) in the new york times. this rumor is a misrepresentation of the facts and can be dangerous to your trading success. here's why:

Tuesday, March 24, 2015

thinkscript include: sdi_hilo_cnt - chart label to display count of highs and lows.

think your stock is overbought and can't possibly go higher? think again. the sdi_hilo_cnt chart label counts the number of range highs and range lows on your chart and displays the count in a chart label. here's the picture:
aapl with sdi_hilo_cnt label
the chart label is saying that aapl pushed up new 1-year highs 56 times on this one year chart. the '252' is the number of bars in the lookback range and defaults to the number of trading days in a year. also note that aapl did not carve any new lows. this means that the chart low (not shown) is a number that aged into that designation. (and, yes, you can select the color for the label.)

here's the code:

Sunday, February 15, 2015

my comp - display labeled comparison plots (thinkscript included)

thinkorswim has a native comparison study that you can apply to a chart. this plots the performance of an comparison equity to the charted equity. the method employed is to re-origin the comparison product to the closing price on the first bar of the charted equity and then apply the percentage moves of the comparison product to the comparison plot. when you get a lot of comparison equities on a chart it looks like this:
SPY with sector etf comparisons.
spaghetti! and it takes some forensics to figure out which product is which colored line. 

sdi_comp plots the same comparison line but adds a bubble at the endpoint of each comparison plot to identify the ticker. also, a chart label is displayed at the top in the same color as the comparison line. here's how this looks:
SPY compared to sector etf performance using sdi_comp
ok, still spaghetti but it should be a little easier to figure out what's what. you should at least be able to see what the two extreme sector etfs are: xly the leader and xle the laggard. 

in the theory of sector rotation xly, the consumer descretionary sector etf, is typically a beneficiary of the late stages of an economic contraction cycle while xle, the energy sector etf, is typically prominent in the late stages of an economic expansion. iyt, the transportation etf, is a beneficiary of the early stages of economic expansion and it is clearly lagging a little bit. so this array of sector performance would seem to indicate the economy is in the late stages of an economic contraction soon to begin an expansion phase ... in theory.

here's the code:

Saturday, January 31, 2015

psar psearch makes AMaZiNg call

in the last half hour of the day the psar indicator, working on psar-psearch optimized settings, reversed a short position and went long on amzn. take a look:

Saturday, January 24, 2015

thinkscript included: sdi_seasonalStgy revision 1.3.0

this release of sdi_seasonalStgy includes two improvements to the statistics label. 


  • previously, the stats label omitted the first trade from the accounting when it coincided with the first bar on the chart. the reported win/loss ratio and average g/l were correct they just, sometimes, included one fewer data point than was available. 
  • the second improvement is a report of the standard deviation of the gains and losses. this is shown as a +/- number following the average g/l as you can see from the image below:

SPY with sdi_seasonalStgy rev 1.3.0 showing average g/l over last 15 years of a 10 trading-day hold.
this is probably why some pundits are suggesting not trading over the next two weeks.

Wednesday, January 21, 2015

thinkscript included: %bid custom watchlist-column

one of the bits of thinkscript that i use every morning in the premarket is a custom column in my watch list called '%bid', here's the picture:
a watchlist with the %bid custom column
%bid compares the the current market bid to the last closing price expressed as a percentage. very simple, but it has helped me enhance profits many times. how? i sort my watchlist by %bid and that allows me to rapidly identify one of my positions that is gapping up before the market opens. this affords me the opportunity to cancel whatever exit trade i have in place and follow the equity in question during the opening hours. maybe it is one of the rare gap-and-go stocks and runs up all day. here's the code:

Tuesday, January 13, 2015

thinkscript included: sdi_impvol - yet another implied volatility script

sdi_impvol plots implied volatility in a chart subgraph like the tos impVolatility study does but with some additional stuff that I think you will find is an improvement. here is an image of sdi_impvol at work:
spy with sdi_impvol showing the high, low and mid levels and the rank.
the green plot line is the implied volatility and the blue lines are the high, low and mid levels. the rank label indicates where the current implied volatility is with respect to the range between high and low. the rank and range lines contain a correction for equities that have discontinuous or infinite values for implied volatility and will display values for rank even when the tos iv percentile (same as iv-rank) does not. the label text and color are adjustable from the customize study dialogue as are the plot properties. in fact, the plots can be hidden, leaving only the rank label showing, and the study moved to the upper chart graph to replace my previous sdi_ivp study with an improved rank label.

here's the code: (how to install)

Monday, January 12, 2015

using options to make that com-free etf work harder

i've been eating my own cooking on these commission-free etf's. rsx, the russian etf, is one of the etf's that i started accumulating because it was sporting a 5% yield. the yield has now moved down to the 4% handle so i have slowed my accumulation of rsx but i have accumulated 19 shares with all the up and down in that product. 

so now i want to show how the strategic use of options can make those measly 19 shares work harder. the action i took today was to sell a call vertical spread on rsx. here's the picture of what i'm talking about:
rsx bear-call vertical
if rsx is trading under 16 (14.80 at the time of this writing) in 39 days then these two options expire worthless and i will have lowered the cost basis on my 19 shares by $1.26/share because i collected $24 (net of commissions) up front against 19 shares. 

as the price of rsx moves above 16.24 at feb expiration then the vertical starts to be worth more than what i collected up front and detracts from the net-liquidating value of the total position. however, the shares will have improved in price by $1.44 or more in that case. the actual break-even price is at $16.54. here's a picture of the p&l analysis:
p&l graph for long 19 rsx shares and short call vertical
there is an excellent 72% chance that this position finishes in the under 16.54 price area, where i am better-off for selling the spread. there is a worse-off price area between $16.55 and $19 that has a slim 15% chance of occurring. above 19 the p&l starts to improve again and the upside-profit is actually unlimited, just diminished by the $80 it will take to buy back the spread.  if you are building wealth from scratch and choose to copy me on this strategy then stop buying the underlying. on the slim chance that rsx does take off to the upside you could then sell 5 or fewer shares, commission-free, to cover the spread repurchase cost.

Sunday, January 4, 2015

commission free etf's on tos

previously, one couldn't participate in the commission-free etf program from a thinkorswim account. i don't know when that changed but its no longer true. i do it all the time now.

there's an advantage to trading the com-free's from tos because one can utilize advanced order types that are only available on tos. for example, trailing buy-stops are rejected by the tda web accounts but work on tos. also, you can make use of tos's advanced order-triggering mechanisms. i recently found utility for the advanced order called 1rst triggers sequence. this order type creates a queue of orders that are sent to the market in sequence as each one is filled. here's a screen shot of one of my sequenced orders:
commission-free etf, ewu, with queue of single share buy orders
each of these orders is a duplicated 20 cent trailing buy-stop-limit to purchase a single share. the trailing buy-stop is a wonderful tool that will defer buying into a falling market. as the price moves down, the stop price will move down with it but 20 cents higher. when price moves up by 20 cents the stop is triggered and the order converts into a limit-order at wherever the stop price has migrated to. regular stop orders convert into market orders, which is great for exiting trades, but i like stop-limits for trade entry to help prevent unfavorable fills on a gap-up in price. the 18.50 price is the current ask price and controls where the initial stop sets up, at 18.70. once the market is open the stop will shift down to 20 cents over the mid-bid-ask price (or mark-price) and maintain that relationship thereafter. 

the basic idea here is to accumulate shares when the market is rising. choppy markets may trigger buys without trending price movement but that's mitigated by the small number of orders in the queue. once the queue is empty one can re-evaluate the trend and adjust the parameters for the orders. for example, a bigger trailing-stop will throttle back the fills in a choppy market. in general, i like a 1% trailing stop on etf's yielding above 5%, 2% trailing stop on 4% yield and 3% on 3% yield. when an etf gets under 3% yield i don't refill the order queue. that's my plan to accumulate a small number of shares in a diverse number of temporarily high-yielding etf's. alas, dividend payouts may vary and not always to the upside.


Friday, January 2, 2015

on-again referral offer

the tda referral promotion is back and so is my referral offer: let me refer you to tda when you are opening a new funded account and i will email you a distribution of the import files of my thinkscript suite.

here's how this works: there are three pieces of information i need to initiate the referral - your first name, last name and the email address you will provide when you open the account. then, you open the account and fund it with at least $2,000 within 90 days. when i receive the referral reward i will email the suite for you. tda is offering you up to a $600 reward to open a new account so its a win/win. 

best and make 2015 a good one.
-allen



Thursday, January 1, 2015

commission-free dogs

this time of year you will hear about the dogs-of-the-dow strategy for investing. this is because dotd strategy revises its list of dogs on jan 1.  dotd picks the top-10 yielding dow stocks on jan 1 and invests equal dollar amounts into each. at the end of the year one sells the stocks that are no longer dogs and buys the new dogs. 

the simple concept behind dotd is that since price and yield move inversely to each other, then, the highest yielding stocks are in some sense priced cheaply and will eventually get bid up to an average yield for the dow ... in theory. in practice, this strategy has a checkered past, with some years of outperformance and others of underperformance and thus represents no particular investing magic but as an engagement tool is still valid, except that you need some money to start with.  you will need to deploy a minimum of a $1000 for every stock to reduce the impact of commissions to 1% or 2% to even have a fighting chance of making money. so implicit in this strategy is that one already has $10,000 sitting idle in a brokerage account.

at smalldog investor i like to show how one might start with almost nothing and methodically build up invested wealth by application of investing knowledge and technique. at tdameritrade (my brokerage and the one that is friendliest to small investors) there is a list of etf's (exchange traded funds) that can be traded for zero commissions, provided one holds shares for at least 30 days (there is an online agreement that must be signed in order to participate; signup is free.) some of these commission-free etf's pay a substantial dividend, like between 5% and 7%. so one could apply the same dotd logic to this list of commission-free etf's - list them in decreasing order of yield and invest in the highest yielding ones. this looks like:
tda commission-free dogs
the difference now is that one can buy these etf's efficiently in sizes as small as 1 share (and i have.) why not? there's no commission. so if one has an extra $20 a week to spare, one can start buying ewu, the etf that represents ownership of british stocks, and make almost 8% in dividends.

what's more, one can scale-into these etf's 1 share at a time. the biggest fear that a yield chaser has is that a decline in share-price will offset the dividends collected, but, one could simply buy additional shares to efficiently dollar-cost average. 

if price increases, the yield will drop for additional shares purchased but your original shares purchased at high yield will continue to yield that original rate, so long as the dividend remains the same. thus, one could stop buying the etf's that have declined in yield and maybe start purchasing new etf's that have increased in yield. i recommend revisiting this frequently, preferably weekly but monthly or quarterly will do.

as dividends start coming in they will increasingly offset the cost of shares being acquired. eventually, one will get to the point where the incoming dividends pay the whole cost purchasing shares and the process becomes self-sustaining. with the ewu, for example, yielding 7.8% and a share price of $18, owning 231 (=18/.078) shares will pay for 1 additional share per year. 52x that (~12,000 shares) will pay for an additional share per week.

this is a kind of a diy drip (dividend re-investment program) the difference being that you control when the re-investment occurs and you can cross pollinate. that is, use the dividends from the old high-priced ex-dogs to help pay for the new dogs.