Posts Tagged ‘swing_points’

Adaptive Opening Range Indicator for Think or Swim

August 25, 2009

The trades I have been taking lately are dependent on defining an opening range. I’ve noticed a few things that I want to trade from:

1. There is usually a good move off the open during the first half hour. I want to trade INSIDE of this move. I won’t get the whole thing, nor do I want to at this point. I’ll be happy with 1 or 2 ES points out of it.

2. Watching a 133 tick chart (the fastest available in ToS), I’ve observed something I’m calling the Opening Balance. Basically, there’s a swing one way, a swing the other way, and then a retrace to the middle of the two. Once we get the retrace, we’ve balanced the first moves off the open, and we’re waiting to see which way the scale tips. This can take anywhere from 10 seconds to 5 minutes or more.

3. I want a few early longs and early shorts to jump in and commit on the bell. That sets up some loser fuel right there! When the next push comes, one way or the other, there’s a new loser that needs to bail out, which is what pushes price. Burning losers are the jet fuel of the markets. (I should know)

My strategy is to go in the direction that the market moves right after the opening balance is made, possibly with confirmation from the internals like the NYSE A-D line and the NYSE Tick. In the past, I’ve been using a 1min time window to define the opening range, and I’ve watched how that compares to this idea of opening balance. The problem with this is that the opening balance I’m looking for could happen in the first 1min, 5min, or any other amount of time. I got whipsawed the other day when the opening balance wasn’t complete for about 5 minutes and I used a 1min OR.

I had the idea to combine my swing points indicator with the shaded opening range indicator. This way, the opening balance can be calculated according to the two price swings instead of an arbitrarily chosen time window. The result is an adaptive opening range indicator that plots the Opening Balance as I’ve defined above:

AOR_2009-08-25-TOS_CHARTS

I am beat and dying for time right now, so instead of writing a tutorial, I will post my early beta version of the indicator as an example of how to do it for the home-gamers, and the final indicator is on my Google site for donors. Note that for either, if you put the start time as the market open, you can’t use market hours only data. The Pro version has the ability to hide or show the swing points as well as changing the lookback and lookahead for defining swing points as an input. (I like 5 back and 3 forward.)

So existing donors, go grab it on the Google site under Released Thinkscript Studies. Look for “AdaptiveOR_ProSTUDY”. Feel free to donate again if you feel this is valuable to you, but it’s not required.

If you are new and want to become a donor, send me a donation through my Paypal:

For everybody else: Thinkscript time! This code will create an adaptive opening range using the definition of highest high three bars forward and three bars back for swing highs, and vice versa for swing lows.

#Start with inputting the start time you want:

Declare fullrange;
Input StartTime = 0930;

#Next define recursive functions to hold your high and low values while waiting for the OR balance to complete:

plot ORStart = if IsNaN(secondsFromTime(StartTime)) then 1 else if secondsFromTime (StartTime) >= 0 then 1 else 0;
plot ORbar1 = if barNumber() == 1 and ORStart then 1 else if ORSTART and !ORSTART[1] then 1 else 0;

rec highs = if ORbar1 then high else if high > highs[1] then high else highs[1];
rec lows = if ORBar1 then low else if low < lows[1] then low else lows[1];

Def swinghigh = if high >= high[1] and high >= high[2] and high >= high[-1] and high > high[-2] then 1 else 0;

Def swinglow = if low <= low[1] and low <= low[2] and low <= low[-1] and low < low[-2] then 1 else 0;

plot sh = if swinghigh then high else double.nan;
plot sl = if swinglow then low else double.nan;

Rec countswinghigh = if barNumber() == 1 then 0 else if !ORStart then 0 else if ORStart AND swinghigh then countswinghigh[1] + 1 else countswinghigh[1];

Rec countswinglow = if barNumber() == 1 then 0 else if !ORStart then 0 else if ORStart AND swinglow then countswinglow[1] + 1 else countswinglow[1];

rec ORHigh = if !ORStart then double.nan else if countswinglow * countswinghigh <> 0 AND countswinglow[1] * countswinghigh[1] == 0 then highs else ORHigh[1];

rec ORLow = if !ORStart then double.nan else if countswinglow * countswinghigh <> 0 AND countswinglow[1] * countswinghigh[1] == 0 then lows else ORLow[1];

Plot ORH = if ORStart then ORHigh else double.nan;
Plot ORL = if ORSTART then ORLow else double.nan;
AddCloud(ORH, ORL);

sh.SetLineWeight(3);
sh.SetStyle(curve.POINTS);
sh.AssignValueColor(color.white);
sl.SetLineWeight(3);
sl.SetStyle(curve.POINTS);
sl.AssignValueColor(color.WHITE);

CCI Divergence Indicator for Think or Swim

May 21, 2009

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

I got commissioned to write more divergence indicators, and the customer was generous enough to allow me to share it with the rest of the donors. I say donors because it builds on my donor-only fully variable swing points indicator, so I’m not releasing it freely as a sponsored indicator. If you are a past (or future 🙂 ) donor, you can get it from the “Released Thinkscript Studies” page, called “Pro_CCIDivergence_v1STUDY.zip”. I like this “donor share” idea and will keep doing it as those who commission custom work are willing to share. If you don’t care to donate or you just want to do-it-yourself, it’s not complicated to write your own if you already have a swing points logic built, like I outlined previously. I’ll walk through the additional steps below.

Following on the heels of my Swing Points and MACD Divergence indicators, here’s two more indicators that look for divergences between the CCI and price, and divergences between Price and CCI. There’s one upper study and one lower study.

Every time we get a lower swing low in price, the CCI is checked to see if it also prints a lower value. Similar for highs; higher high without higher CCI is a divergence. Here is a picture of the indicator at work. On the upper frame, the ProCCIDivergence is plotted as a red dot for bearish divergence, and a green dot for bullish divergence. On the lower frame, the opposite divergence is checked. If the CCI has a a lower swing low, the price lows are checked to see if they also print a lower value. Similar for highs; higher CCI swing high without higher price high is a divergence. The colors on the lower plot look backwards, but remember–the lower indicator is plotting a bullish divergence for the value of CCI, NOT the value of price. And as CCI rises, price generally declines.

CCI_Divergence

To make the top study, just follow the MACD divergence tutorial, but in the recursive divergence functions, change the references from MACD to CCI in this way:

input l=14; #This is the CCI input length
rec blCCI = if swinglow then reference CCI(length=l).CCI else blCCI[1];
rec brCCI = if swinghigh then reference CCI(length=l).CCI else brCCI[1];

And there you go. If you also want the lower study, you change it up a bit. The swing point checks are reversed in that you check CCI values for swing highs and lows, and then you define your bullish and bearish divergence recursive functions above to get the value of price if you are at a CCI swing high or CCI swing low, like this:

input l=14; #This is the CCI input length
def CCI=reference CCI(length=l).CCI;
Def swinghigh = if CCI > CCI[1] and CCI > CCI[2] and CCI > CCI[-1] and CCI > CCI[-2] then 1 else 0;
Def swinglow = if CCI < CCI[1] and CCI < CCI[2] and CCI < CCI[-1] and CCI < CCI[-2] then 1 else 0;
rec blPRICE = if swinglow then low else blPRICE[1];
rec brPRICE = if swinghigh then high else brPRICE[1];

Then plot what you want, and go from there! Personally, I think the lower study is less useful than the upper, but you may feel differently.

That’s it! If you are making your own, leave a comment if you have any questions. If you just want to grab mine, donate away: