Posts Tagged ‘swing_points’

ProSwingVWAP: Combining Swing Points with volume-weighted prices to define trends

November 19, 2018

Hello, it’s been a long time.  Life finds a way to get you off track.  I’m trying to get things here up and running again.

This is something I was working on a long time ago, and I just re-visited it this last week.  I think it’s interesting, so here it is: ProSwingVWAP.

2018-11-18-ProSwingVWAP

A VWAP is a volume-weighted average price.  I talked about VWAPs more here.  The idea for this indicator is to use Swing Points to define the period where we start tracking the volume-weighted value.  The chart above shows it in action.  I like using a VWAP as the price input, so you get a running volume-weighted total of each bar’s VWAP.  Kind of a VWAP squared.  You can use close, high, low, etc. as well.

Once a swing point (white dot) is charted, that swing point becomes the first value for that SwingVWAP.  From there, the price value you choose to average for the VWAP is volume-weighted on each bar and the running VWAP is adjusted.  This is done for swing highs (green dots) and swing lows (red dots) separately.  As long as a new swing high / low hasn’t been made, that long / short VWAP value will just continue to build.  A new swing high or low will reset the VWAP and start again.  I added optional paintbars to show green when a bar close is above the swing high VWAP, red if a bar closes below the swing low VWAP, and grey if it closes between them.  I also hide the VWAP value if bars close beyond them.

Because swing points need to have some future values to know if it really is a swing, there is a delay in this indicator.  The more forward bars you require to decide if a swing is in, the longer it will take for the data structure to be confirmed.  If you set the “FlagEarly” input to yes, then paintbars are yellow during this unknown stage.  The fastest reaction is if you use a value of 1 for Swing Forward, but you get more false positives this way too.  I usually use a value of 1 or 2.  The more bars back you look (Swing Back), you get fewer swings but they are bigger ones.  I mess with this value based on the timeframe and the particular name I’m working with, but I’ll usually use 8 or so.

I’m still in the research phase of this one, so I haven’t decided exactly what to do with it yet.  I like how it defines trends.  A bull trend is present when price is closing above the long SwingVWAP, and a bear trend when price is closing below the short SwingVWAP.  I also like the way it shows when a pullback is on, and when the trend resumes.  On the chart above of $SPY, the period from June to October is a prime example.  The market bottomed out at the end of July and then started an uptrend.  When a new swing high was in, the long SwingVWAP (green dots) told us when we were still in the pullback. Once price closed above the long value again, the trend was back on.  The short SwingVWAP kept trailing along below, reminding us that we were in a bull trend.  Then, as October started, we closed below the short SwingVWAP very dramatically, and the correction was on.  Now we seem to be right back in the middle of the two in a holding pattern.

For now it’s a just a context indicator rather than a trading signal, but it looks like it has some potential.  You can get ProSwingVWAP in the “Donors Only” folder in “Released Thinkscript Studies” at my Google site.  It will work on desktop or mobile, but paintbars only work on the desktop platform.

If you’d like to become a blog donor, hit the button below:

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: