Tuesday, June 28, 2011

Beware of Infernal Shares

Internal shares are private shares of stock. One of the steps that a pre-IPO company must take is to create a private pool of shares that might eventually be sold to the public.

At some point in your career you may encounter an employer that offers to sell internal shares of stock to its employees. In my experience, this is a red flag. You might want to update your resume if an employer asks you to actually purchase the shares instead of granting them.

First of all, you must recognize that there is only a very illiquid market for those shares since you can only sell them to other employees. If you leave your job the shares may have no value. Any price that might be assigned to the shares, purportedly by an independent auditor, is highly suspect without the price discovery mechanism of a public market.

Also, you may feel pressured to buy internal shares merely by the fact that your employer is offering them. If you don't purchase them will your job be in jeopardy? I was once offered such internal shares from an employer for a nominal price and fortunately my spouse talked me out of purchasing more than the minimum 100 shares.

Don't get fooled into believing that internal shares implies that your company is actually going public. My company was acquired a year or two after I dropped $500 to buy 100 internal shares. The acquiring company simply canceled the shares.

I have enountered some companies that pay the match in their 401K in internal shares. To my way of thinking that is the same as offering NO MATCH, given that the internal shares are so vulnerable. If you do not get a match why bother contributing to a 401K!? Much better to contribute to an IRA where your investment choices are far broader.


Monday, June 20, 2011

nearly naked puts

 For the record, this post has absolutely nothing to do with Anthony Weiner - get your mind out of the gutter!

A naked put is when you short-sell a put option without a short-stock position to cover the put position. It's a neutral-bullish trade that makes money on time-decay or upward price movement. I actually prefer to call these cash-covered puts, because if the underlying's price moves down you are going to be paying cash for the shares at expiration, albeit with a better basis than buying the shares here-now. Usually you do this because the stock is something you are ok with owning the shares of anyway.

A nearly-naked put is a bull-put vertical for which the long option is purchased way out-of-the money, maybe 3 or 4 strikes below the short-put. This WOTM long-put is not really meaningful for stopping your losses if the underlying sells-off but it does have the effect of conserving buying power.  In a non-margin account, such as an IRA, you will be required to allocate 100% of the value of the shares to a cash-covered put trade. With the purchase of a the WOTM option, the buying power allocated to the trade is controlled by the difference of the strike prices (x 100 x no. contracts.) It is not hard to engineer a nearly-naked put trade in an IRA to achieve the same buying power allocation as a margin-covered put.

Now might be a good time to engage in these put-premium selling techniques. This is because sell-offs tend to push up the price of puts as investors seek protection on their long stock positions. So if you believe in buying support levels then selling the puts does the same thing but with time on your side. Going nearly-naked is the small-dog way of doing this.


Saturday, June 18, 2011

itsig - lower composite study of Investool signals

itsig is a lower study that shows all of the Investool arrow signals as a histogram. Here's a picture of the study:


SPY with sdi_itsig study.
Three green segments equal the Investools three green arrows (bullish signal) and three red segments equal the Investools three red arrows (bearish signal.) The advantage of such a study over the traditional Investools arrows is that it is easier to ascertain the arrow count, simply by looking at the sdi_itsig value on the right-most bar. This simplifies the task of browsing many equities for InvesTool signals. It also eases the job of identifying and comparing the duration of the composite buy/sell signals.

The dots identify where the MACD value has rolled over (i.e. started decreasing) while above the signal line or rolled-under (i.e. started increasing) while below the signal line. MACD roll-overs/unders are early warnings of a price reversal. Generally, I don't see much more than three or four MACD rolls in a given stretch of Investool buy/sell signals.

Revision 1.1 Oct 29, 2011:
While three segment trade signal is present the bars will darken when MACD is moving against the signal and brighten when it is moving with the signal.

Revision 1.2 Feb 28, 2012
  • Previously SMP was used to select simple moving average in the moving average type input now it is SMA to conform with TOS standards.
  • Previously MACD was always an EMA calculation. Now it conforms to the moving average type selection.

Here's the code:
# sdi_itsig: InvesTools SIGnals
#hint: Displays the Investools green arrow signals as a composite lower histogram study. Three red segments = three red arrows, three green segments = three green arrows. Phantom stocahstics arrows are accounted for. A color fade during a three arrow era represents the MACD fading back towards the zero line. A dot represents a MACD fade occuring during a stochastics over-bought/sold era. Rev:1.2 http://www.smalldoginvestor.com
# rev: 1.2 2/27/2012:
#   -Previously SMP was used to select simple moving average in the moving
#    average type input now it is SMA to conform with TOS standards.
#   -Previously MACD was always an EMA calculation. Now it conforms to the  
#    moving average type selection.
# author: allen everhart 10/8/2009
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale.
# Help me get the word out about my blog by keeping this header
# in place. 

declare lower;
# stochastics inputs
input Sto_over_bought = 75;
#hint Sto_over_bought: % level that defines over-bought. Any Full-D value above over-bought is an investool green arrow. Full-D is the slower varying line in the stochastics study.
input Sto_over_sold = 25;
#hint Sto_over_sold: % level that defines over-sold. Any Full-D value below over-sold is an investool red arrow. Full-D is the slower varying line in the stochastics study.
input sto_KPeriod = 14;
#hint sto_KPeriod: bars used to average the stochastics calculation to produce Fast-K, an intermediate calculation to Full-K and Full-D.
input sto_DPeriod = 5;
#hint sto_DPeriod: bars used to average Full-K to produce Full-D. Full-D is the slower varying line displayed in stochastics studies. Full-D overbought or oversold produces an Investools green or red arrow, resp. In midrange, Full-D rising or falling produces an Investools phantom green or phantom red arrow, resp.
def sto_priceH = high;
def sto_priceL = low;
def sto_priceC = close;
input sto_slowing_period = 3;
#hint sto_slowing_period: bars used to average Fast-K to produce Full-K. Full-K is the more swiftly varying line displayed in stochastics studies.
#input sto_smoothingType = 1;
input MACDFastLength = 8;
#hint MACDfastLength: bars used to produce the more swiftly varying average in MACD studies. The MACD value is the difference between the fast and slow moving averages.
input MACDSlowLength = 17;
#hint MACDSlowLength: bars used to produce the less swiftly varying average in MACD studies. The MACD value is the difference between the fast and slow moving averages.
input MACDLength = 9;
#hint MACDLength: bars used to produce MACD signal line, the moving average of the MACD value. A MACD value greater or less than the signal line produces an Investools green or red arrow, resp.
input MvgAvgLength = 30 ;
#hint MvgAvgLength: bars used to produce the Investools moving average. Underlying price closes above or below this moving average produce and Investools green or red arrow, resp.
input MvgAvgType = { default SMA, EMA    };
#hint MvgAvgType: Selects simple or exponential moving average calculations for all the composite studies.
def SimpleMvgAvgOnOrOff =
  if mvgAvgType == mvgAvgType.SMA then
; # 0 = exponential
def sto_smoothingType = SimpleMvgAvgOnOrOff ;
def c1 = sto_priceC - Lowest(sto_priceL, sto_KPeriod);
def c2 = Highest(sto_priceH, sto_KPeriod) - Lowest(sto_priceL, sto_KPeriod);
def FastK = c1 / c2 * 100;
def FullK =
if sto_smoothingType == 1 then
  Average(FastK, sto_slowing_period)
  ExpAverage(FastK, sto_slowing_period);
def FullD =
if sto_smoothingType == 1 then
  Average(FullK, sto_DPeriod)
  ExpAverage(FullK, sto_DPeriod);
# moving average
def MAprice =
if simpleMvgAvgOnOrOff == 1 then
  simpleMovingAvg( close, mvgAvgLength)
  ExpAverage( close, mvgAvgLength);
def MACDdiff =
if simpleMvgAvgOnOrOff == 1 then
  MACD( MACDfastLength, MACDslowLength,  MACDLength, "SMA").Diff
  MACD( MACDfastLength, MACDslowLength,  MACDLength, "EMA").Diff
#plot md = macddiff;
# macd stuff
rec MACDarrow =
if MACDdiff == 0 then MACDarrow[1]
else if MACDdiff > 0 then 1
else -1 ;
#plot MCDdiag = MACDarrow ;

# red/green arrow stuff
rec MAarrow = 
if close == MAprice then MAarrow[1]
else if close > MAprice then 1
else -1 ;
#plot MAdiag = MAarrow ;
rec StochsArrow =
if FULLD > sto_over_bought then 1
else if FULLD >= sto_over_sold and FULLD > FULLD[1] then 1
else if FULLD >= sto_over_sold and FULLD == FULLD[1] then 
else -1 ;
#plot StochsDiag = StochsArrow ;
def arrowCount =  MACDarrow + StochsArrow + MAarrow ;
def macdStoCount = MACDarrow + STOCHSArrow;
#plot mcdsto = macdStoCount;
plot up =
  if arrowCount == 3 then 3
  else if arrowCount == 1 then 2
  else if arrowCount == -1 then 1
  else double.NaN
  if arrowCount == 3 && MACDdiff >= MACDdiff[1] then color.GREEN
  else color.DARK_GREEN
plot dn =
  if arrowCount == -3 then -3
  else if arrowCount == -1 then -2
  else if arrowCount == 1 then -1
  else double.NaN
  if arrowCount == -3 && MACDdiff <= MACDdiff[1] then coLor.RED
  else color.DARK_RED

plot macd_rv =
  if MACDdiff[2] < MACDdiff[1] && MACDdiff[1] > MACDdiff && MACDdiff[1] > 0 && FULLD[1] > sto_over_bought then
  else if MACDdiff[2] > MACDdiff[1] && MACDdiff[1] < MACDdiff && MACDdiff[1] < 0 && FULLD[1] < sto_over_sold then
macd_rv.setpaintingStrategy( paintingStrategy.POINTS ) ;
macd_rv.setDefaultColor( COLor.DARK_GRAY) ;
macd_rv.setLineWeight(5) ;
  if isNaN( macd_rv ) then color.DARK_GRAY
  else if MACDdiff[1] > 0 then color.RED
  else if MACDdiff[1] < 0 then color.GREEN
  else color.DARK_GRAY

plot z = 0 ;
z.SetDefaultColor( color.DARK_GRAY );
plot p3 = 3 ;
p3.setDefaultColor( color.DARK_GRAY);
plot p2 = 2 ;
p2.SetDefaultColor( color.DARK_GRAY);
plot p1 = 1 ;
p1.SetDefaultColor( color.DARK_GRAY);
plot m3 = -3 ;
m3.setdefaultColor( color.DARK_GRAY);
plot m2 = -2 ;
m2.SetDefaultColor( color.DARK_GRAY);
plot m1 = -1 ;
m1.SetDefaultColor( color.DARK_GRAY);

Saturday, June 11, 2011

Double Dividends With Covered Calls

The covered call strategy should be every smallDogInvestor's first option strategy and lifelong friend. The reason is that there is a high success rate and very little downside risk. I like to use the covered call strategy on dividend paying stocks. The reason is that the payout of the dividend produces a predictable run-up and drop in the price of the stock. Here's how this works:

  1. Find a dividend paying equity. The DOW-30 and S&P 100 stocks are a good choice these days.
  2. Buy some shares about 30 days prior to the ex-dividend date. You will need to buy in multiples of 100 shares. If you already own a dividend paying stock that is profitable then use that. Round up your share ownership if necessary.
  3. Sell a front-month call(s) against your shares no later then closing bell the day before the ex-dividend date. I prefer to sell the first out-of-the money strike above my entry price if I can get a price equal to or greater than the dividend. The first in-the-money strike can be used if it is closer but still above your entry price.
  4. Once filled on the call, I place a GTC order to buy-back the calls for a nickel.
This works because investors are incentivized to buy stocks ahead of the ex-date AND short-sellers are disincentivized from shorting ahead of the ex-date. This latter bit occurs because short-sellers must pay the dividend on the shares they have borrowed if they hold the position through the ex-date. On the close of the last day of the dividend period the dividend is subtracted from the price of the last trade of the day and recorded as the adjusted closing price. The downward adjustment coupled with the shift in incentives for market participants often leads to a predictable drop in price in the first days of the new dividend period as a category of buyers disappears and a category of sellers are enabled. Properly executed you will collect both the dividend and the covered call premium. One caveat: some dividend runs peak a day or two before the ex-date, so look for toppy behavior and sell the call ahead of the must-own date.

Friday, June 10, 2011


AutoFib shows you the Fibonacci retrace lines between the high/low on your chart so you don't have to draw these for every equity. The basic concept of this thinkScript was sent to me from a friend. I added a little of my own Kung-fu: choice of where to display the lines. In my version you can have the fib lines display on the right extension area (sideline) of the chart, which is where I prefer to see them, or overlaying the price bars in main chart, or both. Here's a picture of what I'm talking about:

SPY with autofib.
 So SPY has just completed a retrace to 23.6% below the high. This is considered a shallow retrace in the world of Fibonacci's. A more normal retracement would be to 38.2% below the high, a level around 123 and not seen since last November.

Here's the code for this study:

# sdi_autofib - show fib-retracements between chart high/low
# source: smalldoginvestor.blogspot.com
# author: allen everhart
# date: Aug 15, 2010
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale.
# Help me get the word out about my blog by keeping this header
# in place.
#hint: sdi_autofib shows the fibinacci retracement levels between the high/low of the chart. rev:1.2.1
# rev. 1.2: version info in hint. sidebar selection.
# rev. 1.2.1 refactored sidebar to sideline

#hint sideline: Yes displays the levels only on the right extension otherwise only on the main chart.
input sideline = no;

def f11 = 0.236;
def f12 = 0.382;
def f13 = 0.50;
def f14 = 0.618;
def f15 = 0.786;
def hh = HighestAll(high);
def ll = LowestAll(low);
plot H =
  if isnaN(close) && sideline then
  else if !isnaN(close) && !sideline then
plot L =
  if isnaN(close) && sideline then
  else if !isnaN(close) && !sideline then
plot P236 =
  if isnaN(close) && sideline then
    hh - ((hh - ll) * f11)
  else if !isnaN(close) && !sideline then
    hh - ((hh - ll) * f11)
plot P382 =
  if isnaN(close) && sideline then
    hh - ((hh - ll) * f12)
  else if !isnaN(close) && !sideline then
    hh - ((hh - ll) * f12)
plot P50 =
  if isnaN(close) && sideline then
    hh - ((hh - ll) * f13)
  else if !isnaN(close) && !sideline then
    hh - ((hh - ll) * f13)
plot P618 =
  if isnaN(close) && sideline then
    hh - ((hh - ll) * f14)
  else if !isnaN(close) && !sideline then
    hh - ((hh - ll) * f14)
plot P781 =
  if isnaN(close) && sideline then
    hh - ((hh - ll) * f15)
  else if !isnaN(close) && !sideline then
    hh - ((hh - ll) * f15)


Wednesday, June 8, 2011

how to install one of my studies

all my studies are open-source so the quickest, cheapest way is the copy 'n paste method:
  1. select and copy the code from my blog.
  2. from a tos chart click studies/edit studies
  3. if installing a strategy then click the strategies tab otherwise click the studies tab.
  4. Select new from lower left corner of the edit studies dialogue.
  5. delete or overpaste the first line of code that reads, "plot Data = close;"
  6. paste the new code in to the code box.
  7. replace the automatically generated new study name with something more meaningful.
  8. click ok and the study should be added to your chart automatically.
the edit studies dialogue will kick out error messages if the copy 'n paste did not go well. please be assured that i test this on every code release. one common source of errors is an incomplete selection on the copy. another source of errors is line-wrap. some browsers insert newlines to wrap lines in a copy operation. also, if you save to notepad first be sure to disable line-wrap.

strategies call the addorder function to create a simulated trade. other than addorder, there is very little difference between a study and a strategy but thinkorswim insists on keeping them separated in a different tab on the edit studies and strategies dialogue. 

alternatively, you don't have to hassle with copying and pasting the source code. throw me a bone($10) and i will email you the import files for all of my studies, plus a bonus study or two:

Sunday, June 5, 2011

Small Account Strategy

Trading a really small account is problematic. By small I'm talking about a couple hundred dollars or so, the kind that your kid might open to invest their babysitting money because the banks aren't paying interest on savings accounts anymore.

Firstly, there's the issue of whether the brokerage will even open the account. Many brokerages don't want to know you until you have $3,000 and will simply decline to open small accounts. And Even if you are permitted to open a small account, many brokerages have low balance fees that are designed to skunk you out of your money.

Then there is the issue of commissions. Because of commissions, small account traders tend to trade way too big. Even 5 - 6 shares of most any reasonable stock represents a huge risk to a small account. Even with a winning pick such a position will need to produce very high, percentage-wise, returns to overcome the commissions. Otherwise, small account traders will buy penny-stocks which have a dismally poor track record because they tend to be companys that are going out of business.

However, it is possible for a small trader to get a foot in the door. Here's how:
  1. Open a TD Ameritrade account. They don't have low-balance fees nor do they have minimum balance requirements to open. So far as I know this is unique in the industry.
  2. Sign-up for TD's commission-free ETF's. An ETF (Exchange Traded Fund) is a mutual fund that trades like a stock. This is advantageous because you can use good-til-cancelled orders to take profits at the moment your target price is achieved, not at the close of the day (or more likely day-after if your'e not checking intraday) as with a traditional mutual fund. TD offers a menu of about 100 ETFs that you can purchase for no commission, provided that you hold the shares for 30 days. There is a special waiver you need to fill out that says you understand about the holding period and the consequence for breaking it: a $20 commission on the early sell - roughly what TD would collect for the entry/exit round-trip on any other equity.
  3. Select commission-free ETFs under $50 that pay a dividend. There are a goodly number of these, such as PCY and JNK that pay dividends monthly and have fairly stable prices.
  4. Buy 1 share. Yes, you can buy just one share and there is no shame in it. Size=risk, so take advantage of the fact that you can trade this small. Also, the days of penalizing odd-lot (not a multiple of 100) transactions is long gone. 
  5. After 30 days enter a sell order. After 30 days enter a good-til-cancelled limit order to sell the share when it achieves a 10% gain. Defining your profits is the big secret to profitable trading. I can't tell you how many times I and my fellow traders have seen a profitable position reverse and go negative. The smaller your target, the faster it will be achieved. Since you have no commission overhead to cover why not take profits a soon as you can. Experiment - maybe 5% or 2% is more optimal.
  6. Lather, rinse, repeat. You should buy several different ETF's, if they are a growth fund then don't look for dividends so much.
  1. Avoid stop-loss orders. The point of this strategy is to size the position small enough to avoid needing stop-loss orders, which have their own set of problems. ETF's are comprised of many different underlying equities and therefore the chances of one going to zero is very small.
  2. Avoid adding-on to the position. The thirty-day holding period applies not only to the add-on shares but also to previous shares purchased. If you must add-on, then, cancel any previous sell orders and be prepared to wait-out another 30 days on the whole position.
  3. Keep 5-10% of the account in cash. The cash position cushions a falling market and gives you some ammunition to buy after the fall.
  4. The usual disclaimers: These investments can lose money and are not FDIC insured. Your milage may vary. Swim at your own risk.
I have verified that all of the above works because I use this strategy to invest on behalf of a certain relative of mine. We opened the account with $250 earlier this year. There are currently 8 single-share positions in the account and it is currently worth about $265.


Saturday, June 4, 2011

sdi_seapro5 - 5 Season Projection Of Price (deprecated)

(Note: this fixed 5-season version of seasonal projection has been deprecated. This means I am freezing all updates to this software. Instead of using sdi_seaproj5 I would suggest my sdi_seaproj which permits the user to specifiy the number of seasons that are averaged into the projection.)

One of the TOS studies I had been holding back is SeaPro, Seasonal Projection of price. This study averages the fractional seasonal moves from a reference date and projects the average into the future. Here's an image of SeaPro5 in action:

  • How todays price might move if this was last year or two years ago
Internally, SeaPro calculates the fractional moves that the stock made in a previous season and multiples these against the last closing price to create an individual seasonal projection. It's like asking how todays price might move if this was last year or two years ago or in the case of the above image every fourth year. Then the individual seasonal projections are averaged together to produce a projection average, the solid blue line.
  • Theoretically, seasonality should be factored into the implied volatility
In as much that the individual seasonal projections are the measure of what's to come, the projection average can be said to be predictive, which is why it plots to the right of the prices in the chart. If you use this study on a 1day/1year chart you will need to adjust your settings to show 252 or so bars to the right to see a full years projection. Theoretically, seasonality should be factored into the implied volatility, in that traders could know this information and bid the price of options accordingly.  So this study just gives you a way to visualize seasonality better when some commentator says there is a seasonal bias in play.
  • The area between the projection average and the flat line is high probability for recurrance.
The dashed blue line is the flat line, which is obvious, but until I actually plotted that line it did not occur to me take notice of the area between the flat line and the projection average. If the projection average represents even odds for recurrance then the area between the projection average and the flat line is high probability for recurrance.
  • What track through the high probability area, between flat line and projection average, is important for my trading?
The next question I wanted to know the answer to is: what track through the high probability area, between flat line and projection average, is important for my trading? If you plot standard deviation lines above and below a projection average then statistics tells us that 84% (=.5 * 68 + 50) of the individual seasonal projections track above the lower standard deviation line (and vice versa for the upper standard deviation.) For most any stock with a strong uptrending projection average it can take months for a lower standard deviation line to move above the flat line. Most option traders, like me, have a shorter time frame, so we are willing to go with less probability (as long as it is greater than a coin flip) if a modest advance can be achieved more quickly. This was the inspiration for that splash of green on the chart that I call the HPI, High Probability Indicator.
  • 62% of the individual seasonal projections track above this lower HPI 
The line of the HPI, by default, tracks .3 times a standard deviation away from the projection average. Statistically it can be shown that 62% of the individual seasonal projections track above this lower HPI (and vice versa for the upper HPI.) Only the part of the HPI line that tracks between the flat line and projection average is shown and only when it tracks 2%, by default, or more away from the flat line. So when I see a swath of green from the HPI I know that it is saying that there is a relatively strong bullish seasonal edge in play. If there is just a few splashes of green here and there then there is a weak case for seasonality.

  • A Trio Of Studys
 I have in my arsenal two other variations of SeaPro, seven and fifteen season versions I call SeaPro7 and SeaPro15. Due to limitations of ThinkScript it is not possible to write a dynamic version of SeaPro that self-adjusts to the number of seasons of data available for any given equity so if you come across a relatively new equity you might find that the projection simply does not display. Experience has shown me that SeaPro5 is the most versatile version because it can show the Presidential Cycle (on a weekly chart) to an earnings cycle and everything in between.

# sdi_seaPro5: 5-Season Seasonal Projection Of Price
#hint: Displays a seasonal projection of price based on the average fractional price move between the anchor date and same seasonal dates in the past. Also shows an indicator of high probability of exceeding-on-date (hpi.) Triangles decorate the HPI when 3 or more seasons exceed it. rev:1.9.1 http://www.smalldoginvestor.com
# author: allen everhart
# date: 17Dec2010
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale.
# Help me get the word out about my blog by keeping this header
# in place. 
input trailAnchor = 0; #hint trailAnchor: Sets Moving anchor date to n-bars ago. Takes precedence over anchorDate.
input anchorDate = 0; #hint anchorDate: Sets fixed anchor date. Format: YYYYMMDD.
input seasonLen = 252 ; #hint seasonLen: Sets number of bars in a season. <br>252=1yr on US-equity, daily charts. <br>63=3mo qtr on US-equity, daily charts. <br> 260=1yr FX & Futures daily charts. <br>52=1yr on weekly chart.
input hpIsoline = { "54%", default "62%", "73%", "84%", "90%", "hide" }; #hint hpIsoline: Sets exceed-on-date probability for hpi.
input hpiMinPct = 2.0 ; #hint hpiMinPct: Sets profit filter for hpi.
input individualSeasons = { default hide, show}; #hint individualSeasons: show the projection of individual seasons. Most recent 3 are lime-colored, oldest are grey.
input stdMultiple = 0.0; #hint stdMultiple: Multiple of the standard deviation to show. Zero to hide.
#input version = { hide, default show }; #hint version: show script version as a chart label.
#AddChartLabel( version == version.show, "sdi_seaPro5 v:1.7.0" );
# v:1.9.1 - 5/19/2012 clsy(n>0) was referencing close from 1 bar too recent. fixed.
# v:1.9.0 - 3/30/2010 hide bubbles - prevent bloat.
# v:1.8.0 - 8/30/11 deprecate the version label - version in hint
# v:1.7.0 - simplify - remove envelope and spike analysis
# v:1.6.0 - expand the choice on standard deviation multiples.
# v:1.5.2 - fixes bug w. originDate not propagating forward correctly
# v:1.5.1 - fixes spurious incorrect color on hpi

def x = if hpIsoline == hpIsoline."54%" then 0.1
else if  hpIsoline == hpIsoline."62%" then 0.3
else if  hpIsoline == hpIsoline."73%" then 0.6
else if  hpIsoline == hpIsoline."84%" then 1.0
else 1.3;
rec originDate =
  if trailAnchor > 0 && IsNaN(close[-trailAnchor]) && IsNaN(close[-trailAnchor - 1]) then
  else if trailAnchor > 0 && originDate[1] > 0 then # 1.5.2 added [1] to originDate
#plot od = originDate;

# pn is the number of bars past the originDate
rec pn =
  if !pn[1] && getYyyyMmDd()[1] < originDate && getYyyyMmDd() >= originDate  then
  else if !pn[1] && IsNaN(close) && !IsNaN(close[1]) then
  else if pn[1] > 0 then
    pn[1] + 1
#plot p=pn;
rec clsy0 =
  if pn == 1 then close[1]
  else if pn > 1 then clsy0[1]
  else 0;
plot fl = if pn > 0 then clsy0 else double.NaN; # flat line
fl.SetStyle(curve.SHORT_DASH) ;

rec clsy1 =
  if pn == 1 then close[seasonLen+1]
  else if pn > 1 then clsy1[1]
  else 0;
#plot fl1 = if clsy1 > 0 then clsy1 else double.NaN;
rec clsy2 =
  if pn == 1 then close[(2 * seasonLen) +1]
  else if pn > 1 then clsy2[1]
  else 0;
#plot fl2 = if clsy2 > 0 then clsy2 else double.NaN;
rec clsy3 =
  if pn == 1 then close[(3 * seasonLen) +1]
  else if pn > 1 then clsy3[1]
  else 0;
#plot fl3 = if clsy3 > 0 then clsy3 else double.NaN;
rec clsy4 =
  if pn == 1 then close[(4 * seasonLen) +1]
  else if pn > 1 then clsy4[1]
  else 0;
#plot fl4 = if clsy4 > 0 then clsy4 else double.NaN;
rec clsy5 =
  if pn == 1 then close[(5 * seasonLen) +1]
  else if pn > 1 then clsy5[1]
  else 0;
#plot fl5 = if clsy5 > 0 then clsy5 else double.NaN;

def y1 = close[1 * seasonLen] / clsy1 ;
def y2 = close[2 * seasonLen] / clsy2 ;
def y3 = close[3 * seasonLen] / clsy3 ;
def y4 = close[4 * seasonLen] / clsy4 ;
def y5 = close[5 * seasonLen] / clsy5 ;

plot p1 = if pn > 0 then clsy0 * y1 else double.NaN;
plot p2 = if pn > 0 then clsy0 * y2 else double.NaN;
plot p3 = if pn > 0 then clsy0 * y3 else double.NaN;
plot p4 = if pn > 0 then clsy0 * y4 else double.NaN;
plot p5 = if pn > 0 then clsy0 * y5 else double.NaN;

p1.setHiding(individualSeasons == individualSeasons.hide);
p2.setHiding(individualSeasons == individualSeasons.hide);
p3.setHiding(individualSeasons == individualSeasons.hide);
p4.setHiding(individualSeasons == individualSeasons.hide);
p5.setHiding(individualSeasons == individualSeasons.hide);


def yavg = (y1 + y2 + y3 + y4 + y5 ) / 5;
plot pa =
  if pn > 0 then
    (p1 + p2 + p3 + p4 + p5 ) / 5

def hpiUpTarg = clsy0 * (1 + (hpiMinPct / 100));
def hpiDnTarg = clsy0 * (1 - (hpiMinPct / 100));

def pstd = Sqrt((Sqr(p1 - pa) + Sqr(p2 - pa) + Sqr(p3 - pa)
+ Sqr(p4 - pa) + Sqr(p5 - pa) ) / 5);
plot psdu = pa + (pstd * stdMultiple);
plot psdd = pa - (pstd * stdMultiple);
def hpul =  pa - (x * pstd);
def hpll =  pa + (x * pstd);
plot hpi = # High Probability isoline
  if pn > 0 && pa > clsy0 && hpul >= hpiUpTarg then
  else if pn > 0 && pa < clsy0 && hpll <= hpiDnTarg then
hpi.AssignValueColor( if hpi > fl then color.GREEN else color.RED );
AddCloud( hpi, fl, color.GREEN, color.RED );
hpi.setHiding(hpisoline == hpisoline.hide);
def nup =
  (if p1 >= hpi then 1 else 0)
  + (if p2 >= hpi then 1 else 0)
  + (if p3 >= hpi then 1 else 0)
  + (if p4 >= hpi then 1 else 0)
  + (if p5 >= hpi then 1 else 0)
#plot pnup = if pn>0 then nup else double.NaN ;
def ndn =
  (if p1 <= hpi then 1 else 0)
  + (if p2 <= hpi then 1 else 0)
  + (if p3 <= hpi then 1 else 0)
  + (if p4 <= hpi then 1 else 0)
  + (if p5 <= hpi then 1 else 0)
plot n =
  if pn > 0 && yavg > 1 && nup > 3 && hpi >= hpiUpTarg then
  else if pn > 0 && yavg < 1 && ndn > 3 && hpi <= hpiDnTarg then
  if n > clsy0 && nup > 4 then color.MAGENTA
  else if n < clsy0 && ndn > 4 then color.MAGENTA
  else if n > clsy0 then color.GREEN
  else color.RED
n.setHiding(hpisoline == hpisoline.hide);


Wednesday, June 1, 2011

Pre-Presidential Progress

Here is the market progress against the pre-presidential year cycle average (last 5 cycles):

The market overperformed the projection in the first quarter and is underperforming  so far in the second. A regression to the mean would take the SPX to the 1400-1420 area by July.