Site Meter The Lawyer Trader: Indicator
Showing posts with label Indicator. Show all posts
Showing posts with label Indicator. Show all posts

Sunday, December 7, 2014

ThinkScript Indicator: CalmvVolatile

This is a pretty basic stud that compares the current Average True Range (ATR) with a long term average of the ATR.  The default periods are 14 period for the ATR and 500 period for the average.


This indicator can be helpful as a quick reference when taking short term trades.  If the instrument is volatile, you know that there's a better possibility of a quicker and farther move than if it's calm.  Enjoy.  The code is below.


#######Delete this line in TOS#############

input atrlength = 14;

input avglength = 500;

input plotlower = {default "yes", "no"};

def vol = AverageTrueRange(atrlength);

def avgvol = Average(vol, avglength);

def calm = vol < avgvol - (avgvol * .1);

def neutral = avgvol + (avgvol * .1) > vol > avgvol - (avgvol * .1);

def Volatile = vol > avgvol + (avgvol * .1);

AddLabel(yes, Concat("Market is Currently ", (if calm then "Calm" else if neutral then "Neutral" else if Volatile then "Volatile" else "Neutral")),  if calm then Color.GREEN else if neutral then Color.BLUE else if Volatile then Color.RED  else Color.GRAY);

declare lower;

plot window =  vol - avgvol;

window.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

window.AssignValueColor(if Volatile then Color.RED else if calm then Color.GREEN else if neutral then Color.BLUE else Color.GRAY);

plot zeroline = 0;

######delete this line in TOS##############

Tuesday, July 9, 2013

Although it's Changed Hands, It's Still Worth Following: Libor Spread Still Helps

I've posted before about how the 30 day and 90 day Libor spread tends to be a good leading indicator.  I also posted about how it sucks that there's been crazy manipulation and that it might not be good anymore.  Well, Euronext is taking over Libor and it appears that the Libor spread that I so love to watch is still worth keeping bookmarked and watching.  Here's the chart:


Not saying it's the end all be all...just might be worth keeping an eye on.

Hope everyone's having a good summer!

TLT

Wednesday, September 19, 2012

DT 2000 Gave a Buy Signal a Month Ago: Here's the Thinkscript Code for the Indicator

The DT 2000 is a trend following indicator that I came  up with about a year ago.  It uses linear regression and it's purpose is to determine the trend of the overall market.  It uses linear regression slope readings on 4 different symbols and its defaults are qqq, xlv, xlf, tlt.  The indicator tends to work well on the weekly time frame..which makes sense because the longer time frames smooth out the choppy price action of equities.

Here's a chart, the DT 2000 is at the bottom and it's coloring the bars on the chart as well:

This indicator is just one more tool in my collection that I look at to help gauge risk and market bias.  I don't necessarily trade this like a system in and of itself--such as buying the SPY or SSO on buy signals.  What this buy signal does for me is it gives me the confidence to put on more long positions, whether the positions are stocks or covered calls or options spreads.  As you can see from the chart, we've had 3 other buy signals in the last 4 years and the buy signals tend to last several months before petering out.  We'll see if this signal has any legs to it.

Here's the thinkscript code for you thinkorswimmers out there:

####DELETE THIS LINE WHEN PASTING INTO TOS####


declare lower;

input symbol1 = "qqq";
input symbol2 = "xlv";
input symbol3 = "xlf";
input symbol4Inverse = "tlt";
input lrlength = 20;

def data1 = close(symbol1);
def data2 = close(symbol2);
def data3 = close(symbol3);
def data4 = close(symbol4Inverse);

def trend1 = linearRegressionSlope(data1, lrlength);
def trend2 = linearRegressionSlope(data2, lrlength);
def trend3 = linearRegressionSlope(data3, lrlength);
def trend4 = linearRegressionSlope(data4, lrlength);

def score1 = if trend1 > 0 then 1 else -1;
def score2 = if trend2 > 0 then 1 else -1;
def score3 = if trend3 > 0 then 1 else -1;
def score4 = if trend4 < 0 then 1 else -1;

plot DT = score1 + score2 + score3 + score4;    

def buysignal = crosses(DT, 0, crossingDirection.ABOVE);
def sellsignal = crosses(DT, 0, crossingDirection.BELOW);  

assignPriceColor(if dt > 0 then color.green else if dt < 0 then color.red else color.blue);


####DELETE THIS LINE WHEN PASTING INTO TOS####


I hope everyone is having a great week so far.

TLT

Saturday, July 14, 2012

Summer Reading: Deemer on Technical Analysis and a TOS Code for His Break Away Momentum Indicator



This summer, I've been reading Walter Deemer's Deemer On Technical Analysis and it has been one of the best technical analysis books that I've read in a really long time.  Mr. Deemer gives his take on using TA for longer term investors and he shy's away from the ultra short term time frames that many modern trading books focus on.  He had a long career as a technical analyst and his book is chock full incredibly interesting and witty observations based on his own experiences from his career.


Deemer  not only breaks down what he feels is useful about TA, he also does a great job of explaining his beliefs on why the TA that he uses works.  You're not going to see pictures of massive charts with multiple indicators and squiggly lines in this book..he keeps his charts to the bare minimum of what he considers useful tools.  This book will likely be the book that I recommend to people when they ask me for a good book that can help them get started with investing/trading or with TA in genearl.  If you haven't read it yet, pick it up or order it for the kindle/ipad.  It's well worth the read.

As a bonus, I coded his Breakaway Momentum indicator for think or swim.  This indicator uses the NYSE advances and declines that are added together for the trailing 10 days and then a ratio is created of advances to declines.  To be breakaway momentum, the reading has to be above a 1.97.  These readings only happen once every 31 and a half years on average.  That being said, we had three in 2009..a bit of an anomaly and a testament to how oversold the market was after the 2008 meltdown.  For more info and historical recordings of breakaway momentum check out Mr. Deemer's website here.

Here's a chart, note TOS has some data issues with advance decline numbers starting in 2009 and going backwards, however, this indicator works well with recent data and you can still see the 3 breakaway readings in 2009..there are just some holes in the data that don't look pretty.



And here is the code for you thinkorswim fans:

####Delete this line when pasting in TOS####


declare lower;

input adv = "$ADVN";
input dec = "$DECN";
input length = 10;

def up = close(adv);
def down = close(dec);

def sumup = sum(up, length);
def sumdn = sum(down, length);

plot ratio = sumup/sumdn;

plot breakaway = 1.97;

####Delete this line when pasting in TOS####


Have a great weekend!

TLT

Monday, December 26, 2011

ID/NR4 Bars and Thinkscript

Linda Bradford-Raschke, Laurence Connors, Tony Crabel and many other professional traders have referenced narrow range bars as part of there trading setup arsenal.  LBR likes the ID/NR4 which stands for Inside Day Narrowest Range in 4 days.  That means the high and low of the bar have to be within the prior bar (an inside day) and the overall range itself has to be the narrowest in the last 4 bars.

Referenced in many books authored by the above mentioned traders, ID/NR4 and NR4 bars provide a low risk high reward trade setup.  The setup generally involves trading the break out above or below the ID/NR4 bar and placing a stop at the other side.  Then trail a stop for another bar or two.  LBR stresses that in the event your initial stop gets hit, you should stop and reverse so that you are now in the trade in the other direction.  She states that this is important because many of the moves can be false break outs but the move in the opposite direction can be very powerful after a false break out.  Regardless, these setups do allow for very tight stops and can provide some very good short term edges.  Adding some additional research such as current trend direction if any (Crabel does a lot of this research) or monitoring an opening range break out after a NR4 day (Crabel does this as well) or using some volume analysis can all help you filter NR4 or ID/NR4 bars for even higher probability trades.

Here's a chart, note the blue dots above bars indicate an ID/NR4 bar:

And for those of you on ThinkorSwim, here is the thinkscript:

###DELETE THIS ROW WHEN PASTING INTO TOS###


# ID/NR4 Bars
#
def range = high – low;
def na=double.nan;

def plotter=high+range*0.3;

def longvol = volatilityStdDev(100);
def shortvol = volatilityStdDev(6);

def volratio = shortvol/longvol;

def isnr4 = (range <= range[1] and range <= range[2] and range <= range[3] and range and high<high[1] and low>low[1]);

plot lowvol = if volratio<.5 and isnr4 then low-.0005 else double.nan;

lowvol.SetDefaultColor(color.violet);
lowvol.setstyle(curve.points);
lowvol.setlineWeight(3);

plot nr4 = if isnr4 then plotter else na;

nr4.SetDefaultColor(Color.yellow);
nr4.setstyle(curve.points);
nr4.setlineWeight(3);

###DELETE THIS ROW WHEN PASTING INTO TOS###

This code was adopted from a code for NR7 bars written by ReadtheProspectus at his blog with the same name.  If you like thinkscript it would be well worth it to spend some time at his blog.

Happy Holidays!

TLT

Wednesday, September 28, 2011

Leading Indicators Study Say's Bears are Still in Control

One indicator that I created a while back and have been following is called the "Leading Indicator Study."  No, these are not the economic data leading indicators, these are just different etfs of asset classes that represent the bullishness or bearishness of the market that tend to lead big moves.  It is based on the Euro (FXE), Copper (JJC), Small Caps (IWM), Emerging Markets (EEM), VIX (VIX or VXX), Long Term Treasuries (TLT), Short Term Treasuries (SHY) and Consumer Staples (XLP). 

I'm not going to go into exactly how this works, but I wanted to share the general idea...maybe it will spark some ideas with clever traders that look at such things to derive an edge.  The basic concept is to take risk sensitive asset classes, determine whether they are in an uptrend or downtrend, and then create a score based on the trends.  This particular indicator uses a couple of regression calculations to determine the trends and then it adds points for the bullish trends and subtracts points for the bearish.  Simple enough.  Regression is not necessary, you could easily use a moving average or volatility break out system in place of the regression.  The point is to look at multiple asset classes at the same time to get a heads up on what the market's current risk appetite is.

Here's a screen shot of the indicator paired with the S&P 500, note the colors of the price bars are indicative of the bullishness (green), bearishness(red), buycaution (yellow) and sellcaution(blue):

Hopefully you found this interesting and you can work out something similar or even better to implement with your own market analysis.  As you can see with the chart, price bars are red and the indicator score is a very low -92 which confirms the bearishness of the market.  That tells me not to get too excited about any rallies until this indicator gets back to bull territory.

TLT

Thursday, September 15, 2011

Take a Look at the EuroDollar Index over 3 Month Libor

This is an interesting indicator. Much like the TED spread and a handful of others, it tends to give good indications of whether the market is likely to move higher or lower. Nothing is perfect, but the short term interest rate markets are usually quick to move when something is anticipated in the market. Take a look at the chart, and notice the crosses on the moving averages:
I chose to use the word "anticipate" rather than signal because that's what I use this for.  It's not a signal in and of itself, it's a tool that helps gauge the likely overall direction of the market.  So why the 3 Month Libor instead of 1 Month? No special reason, you could use 1 Month Libor..the 3 Month is a little smoother when plotted with the EuroDollar. (*Note this is the EuroDollar market that is made up of dollar deposits in other countries..this has nothing to do with the Euro Currency in the forex market).

Something interesting to watch and keep on your radar. Hope everyone is managing the volatility..it's a wild one right now.

TLT

Thursday, September 8, 2011

Index Trader Indicator for Think or Swim: Using Volume, Advance/Decline and Cumulative Tick for Day Trading

I've been playing around with a day trading indicator.  It consists of the ratio of advancing stocks to declining stocks (on the NYSE), Up volume vs. Down volume (NYSE) and the cumulative tick (also NYSE).  Basically, if advancing stocks are above declining and the UpVolume for the day is higher than the down volume, this indicator will show you that the market is bullish.  To filter these signals, I use the cumulative tick.  If the tick lines up with the other two then the bars are painted green (when bullish) or red (when bearish).  If the tick conflicts with the other indicators, the bar will be painted blue.  Check out a five minute SPY chart:

This indicator is useful for day trading, as it can help you determine where the market internals are pushing the market and get you on board with the trend as it's developing intra-day.  This indicator should not be used all by itself for entries and/or exits.  It is not perfect, as there are plenty of times when the bars are green and prices just drop.  I have been playing with it more as a filter.  For example, if I'm trading using bollinger bands, I will look for long intra-day setups when the bars are green.  Or if I'm looking to fade rallies using a stochastic oscillator, I'll look to sell an over bought signal if the bars are red.  There are lots of possibilities to incorporate this and tweak it to your liking.

Here is the think script code for think or swim if anyone out there uses TOS.

//
def VolUp = close("$UVOL");
def VolDn = close("$DVOL");

def advancers = close("$ADVN");
def decliners = close("$DECN");

def BullVol = if volup>voldn then 1 else 0;
def BullAdv = if advancers>decliners then 1 else 0;
def BearVol = if volup<voldn then 1 else 0;
def BearAdv = if advancers<decliners then 1 else 0;

def BullMode = if BullVol and BullAdv then 1 else 0;
def BearMode = if BearVol and BearAdv then 1 else 0;

def upper = no;
input hidecumtick = yes;
input symbol = "$TICK";
input period = 20;
input smooth = 5;
input lookback = 4;
input filter = 300;
def p = period;
def i = barNumber();
def na = double.nan;
#input usetrend = {"No", default "Yes"};
def usetrend = yes;
rec htick = if IsNaN(high(symbol)) then htick[1] else high("$TICK") ;
rec ltick = if IsNaN(low(symbol)) then ltick[1] else low("$TICK");
rec avgh = if i == 1 then htick else Max(filter, avgh[1] + 2 / (p + 1) * (htick - avgh[1]));
rec avgl = if i == 1 then ltick else Min(-filter, avgl[1] + 2 / (p + 1) * (ltick - avgl[1]));


def hi = high("$TICK");
def lo = low("$TICK");

def Last = if IsNaN(close(symbol)[-1]) then close(symbol) else double.nan;

def amean = if IsNaN(close) then na else (avgh + avgl) / 2;
def trendmean = if usetrend AND (htick > avgh OR ltick < avgl) then amean else 0;

def bull = if htick > avgh then htick - avgh  else 0;
def bear = if ltick < avgl then ltick - avgl  else 0;

rec ctick = if i == 1 then 0 else if IsNaN(htick) OR IsNaN(ltick) then ctick[1] else ctick[1] + bull + bear + trendmean; 

def ctickavg = ExpAverage(ctick, smooth);
def cumtick = if IsNaN(close) then na else ctickavg;
def nettick = if IsNaN(close) then na else ctick;

def zero = 0;

AssignPriceColor(if !upper then color.current else if cumtick > cumtick[lookback] AND ltick < avgl then color.green else if cumtick > cumtick[lookback] then color.gray else if cumtick < cumtick[lookback] AND htick > avgh then color.red else color.gray);

def hcumtick=if !hidecumtick then cumtick else na;
def hzero=if !hidecumtick then zero else na;
AddCloud(hcumtick, hzero );
def buy = if cumtick > cumtick[lookback] AND ltick < avgl then low - tickSize() else if cumtick > cumtick[lookback] then na else if cumtick < cumtick[lookback] AND htick > avgh then na else na;
def sell = if cumtick > cumtick[lookback] AND ltick < avgl then na else if cumtick > cumtick[lookback] then na else if cumtick < cumtick[lookback] AND htick > avgh then high + tickSize() else na;

def ahi = if IsNaN(close) then na else avgh;
def alo = if IsNaN(close) then na else avgl;
def hib = if hi < 0 then hi else na;
def lob = if lo > 0 then lo else na;
def phi = hi;
def plo = lo;

#plot zero=0;
#
# Formatting:

Def TickBull = (if cumtick > cumtick[lookback] then 1 else 0);

assignPriceColor(if BullMode and TickBull then color.Green else if BearMode then color.red else color.blue);
//


That's all folks.  I have been working on quite a few indicators and strategies lately and would be happy to share more code if there is enough interest/demand.  We'll see.  Hope everyone's trading is going well.

TLT

*****Update*****
The above code has been fixed.  A reader alerted me to a problem with the coding from the original post..not sure what happen but it appears to be a copy/paste error.  The new code should work much better