NexusFi: Find Your Edge


Home Menu

 





NT7 indicator "LogReturns"


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one MXASJ with 6 posts (5 thanks)
    2. looks_two Fat Tails with 2 posts (1 thanks)
    3. looks_3 Big Mike with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 7,388 views
    2. thumb_up 6 thanks given
    3. group 2 followers
    1. forum 10 posts
    2. attach_file 8 attachments




 
Search this Thread

NT7 indicator "LogReturns"

  #1 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

I'm slowly putting together some tools to help me with volatility analysis in NT7. The attached indicator looks at the period log of returns. The attached chart gives you an idea of what people mean by Volatility Clustering .

The guts of the code is:

 
Code
                            
if(CurrentBar || Close[1] <= 0)
{
Value.Set(0);
return;
}
 
plotLog = (Math.Log(Close[0]/Close[1])); 
Value.Set(plotLog); 
That snippet is part of the HistoricalVolatility indicator I've been developing in the Elite section.

I'm posting this here for any suggestions/corrections belore posting it in downloads. On its own it is not that exciting but may be useful as a part of something bigger.

Attached Thumbnails
Click image for larger version

Name:	LogReturns.jpg
Views:	345
Size:	134.9 KB
ID:	15731   Click image for larger version

Name:	WithATRandHistVolRainbow.jpg
Views:	259
Size:	141.3 KB
ID:	15733   Click image for larger version

Name:	WithZScoreofLogReturns.jpg
Views:	265
Size:	159.3 KB
ID:	15734  
Attached Files
Elite Membership required to download: LogReturns.zip
Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Exit Strategy
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
33 thanks
Just another trading journal: PA, Wyckoff & Trends
26 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #3 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


Upload test to the new server. And a cool chart...

Attached Thumbnails
Click image for larger version

Name:	Vol.jpg
Views:	261
Size:	170.7 KB
ID:	15736  
Started this thread Reply With Quote
  #4 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102

A volatility cluster is related to a fat tail, so I am listening attentively, LOL.

If you print volatility and/or logarithmic returns, this is nice, but what is your intention? I agree that voaltility is important, even if you do not want to calculate option prices. I use volatility for my trading approach in the following ways

1) Keltner Channels, they use the average true range, which is a measure of volatility. I prefer Keltner Channels to Bollinger Bands, as Bollinger Bands are sensitive to both directional bias and volatility (it is a two-in-one indicator).

2) The classic floor pivots use yesterday's range to establish targets, so they use 1-day-volatility.

3) I also use a multiple of ATR as a trailing stop, or to enter pullback trades.

Now thinking about, how to use those log returns. Volatility clustering suggests that you get a better prediction for future volatility if you give more weight to recent volatility, when calculating an average. This could be achieved by replacing the ATR with an EMA of the last true ranges. But can't see how to use log returns for this.

The main application that I would have for log returns is to calculate correlation coefficients for pairs of instruments. You could code an indicator that monitors the log return of two instruments and then plots the correlation between the returns. You could then displace one of the series by one or more periods to find out, whether returns of the first instrument could "predict" returns of the other one, prerequisite to intermarket analysis.

Reply With Quote
Thanked by:
  #5 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


Fat Tails View Post
...The main application that I would have for log returns is to calculate correlation coefficients for pairs of instruments. You could code an indicator that monitors the log return of two instruments and then plots the correlation between the returns. You could then displace one of the series by one or more periods to find out, whether returns of the first instrument could "predict" returns of the other one, prerequisite to intermarket analysis.

It would be a different formula than what I have been playing with for basic pairs trading, but definately worth looking at. Thank you for that comment.

I started looking at the vol thing because one thing that has worked for me recently is some options swing trading... buying vol when vega drops on an "inside" day during high vol periods, and selling it when vega picks up again a day or five later. Its an opportunistic trade that by definition only presents itself <5% of the time. That would be 12 times per year using daily charts.

Like I said LogReturns might work well as part of something else. In the last chart I posted, I plot the ZScore of the LogReturns and found it interesting. I'll be updating the ZScore code I have in the Elite downloads section with the code I used for the indi above this weekend.

Started this thread Reply With Quote
  #6 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

The code for the ATRRainbow indicator is attached. Its one I threw together to compare with other things (like LogReturns) so it could probably be better. I'll post it in the downloads section after my usual comment/rethink period.

Attached Thumbnails
Click image for larger version

Name:	ATRRainbow.jpg
Views:	282
Size:	127.8 KB
ID:	15738  
Attached Files
Elite Membership required to download: ATRRainbow.zip
Started this thread Reply With Quote
Thanked by:
  #7 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

I'm just screwing around here but here is a Weekly. Fat Tails() worth looking at.

Attached Thumbnails
Click image for larger version

Name:	Weekly.jpg
Views:	244
Size:	152.3 KB
ID:	15744  
Started this thread Reply With Quote
  #8 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102

It is known that stock markets are asymmetrical (flat peaks and sharp troughs), it follows that (a moving average of) volatility declines in a rising market and increases during declines. The question is, whether volatility produces leading or conincident signals.

For the topping process I could not see any divergences, but for the bottoming process there is a clear divergence that can be seen on the weekly chart. The stock market makes a new low, but volatility (fear) does not reach new highs.

An alternative to historical voloatility would be implied volatility (VIX) or very basic, volume. The force index of Alexander Elder is one of the various indicators that would produce a divergence allowing to identify a low as well.

Comparing ATR (Rainbow) with VIX and force index may show similar results. They can identify climax type situations and produce divergences. So you can use them to identify stock market bottoms or commodity tops, as stock markets from sharp troughs and commodities sharp tops. But they would be unusable to detect stock market tops and commodity bottoms.

Would need to do some backtesting to check whether the divergences give us an edge, and whether ATR can beat VIX and/or volume.


MXASJ View Post
I'm just screwing around here but here is a Weekly. Fat Tails() worth looking at.


Reply With Quote
  #9 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

Elders Force Index is a Price+Volume thing I believe. Here is how TOS does it:

 
Code
                            
#
# thinkorswim, inc. (c) 2007
#
declare lower;
input length 13;
plot FI ExpAverage(data = (close close[1]) * volumelength);
FI.SetDefaultColor(GetColor(8));
plot ZeroLine 0;
ZeroLine.SetDefaultColor(GetColor(5)); 
Proper IV figures require an option price to calculate I believe, and that is dificult to code (for me) in NT. I can get NT to give me specific options prices if I set them up in Instrument Manager (I do that now with IQFeed), but there are better tools for that. So your reference to the VIX is interesting. If the VIX (and other index IV indexes) is our only source of IV data in NT, that is something to keep in mind.

Started this thread Reply With Quote
  #10 (permalink)
Loukas
London
 
Posts: 27 since Jun 2011
Thanks Given: 4
Thanks Received: 2


Hi,

Your work looks interested. Could you share the code of Z-Score(LogReturns) indicator?

Thanks

Reply With Quote




Last Updated on June 21, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts