NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 10-29-2008, 09:53 AM   #1
maestrom
Junior Member
 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 times in 0 posts
Default need help converting volatility indicator

i'm new to ninjatrader and was looking to convert an indicator i use in my options trading. what the indicator does is track the total number of ticks or deltas traded. there are tons of ways to look at realized volatilty...
log of daily returns, ATR, Parkinson, Garman-Klass, etc.

from my experience a big problem they all have is that by only looking at one time slice (ie, daily data) they miss much of the the back and forth movement. what i had created in excel to calculate this was a indicator to tell me the total number of ticks traded over a given time period.

on any given bar price can only take 2 paths to the close.

open->high->low->close or open->low->high->close

below is the vba code i use in excel to track the tics traded

it first checks the open->high->low->close path

hedgeTick is a variable i can set. it can be set to the minimum tick increment or a larger value to see count the number or moves of a given size (say if i want to hedge s&ps every 10 points).

it then checks the open->low->high->close path. since even on 1 minute data you can't be sure which path price took i then take the minimum of the 2.

i have found this indicator to be of much greater value in my options trading as it gives you a real sense of the number of tics (or deltas) that a security trades over the course of a day.

i started trying to code this in ninjatrader but am still at the early part of the learning curve. i think since it requires a data history to check against it would require me to set up variables using
new
DataSeries(this);
in the
protected
overridevoid Initialize() section
but im a bit lost at how to proceed. if someone had an idea how to get this started any help would be greatly appreciated.

------------------------------------------------------------

refCheckOHLC = prevClose
refCheckOLHC = prevClose
ohlcSum = 0
olhcSum = 0


If (check = 1) Then
'Check O->H->L->C First
' PREV CLOSE -> OPEN
If (cOpen - TickSize) > refCheckOHLC Then
If ( ((cOpen - TickSize) - refCheckOHLC) / hedgeTick) >= 1 Then
ohlcSum = ohlcSum + Int( ((cOpen - TickSize) - refCheckOHLC) / hedgeTick)
refCheckOHLC = refCheckOHLC + Int( (((cOpen - TickSize) - refCheckOHLC) / hedgeTick))
End If
ElseIf (cOpen + TickSize) <= refCheckOHLC Then
If ( (refCheckOHLC - (cOpen + TickSize)) / hedgeTick) >= 1 Then
ohlcSum = ohlcSum + Int( (refCheckOHLC - (cOpen + TickSize)) / hedgeTick)
refCheckOHLC = refCheckOHLC - Int( (refCheckOHLC - (cOpen + TickSize)) / hedgeTick)
End If
End If
' OPEN -> HIGH
If (cHigh - TickSize) > refCheckOHLC Then
If ( ((cHigh - TickSize) - refCheckOHLC) / hedgeTick) >= 1 Then
ohlcSum = ohlcSum + Int( ((cHigh - TickSize) - refCheckOHLC) / hedgeTick )
refCheckOHLC = refCheckOHLC + Int( ((cHigh - TickSize) - refCheckOHLC) / hedgeTick )
End If
End If
' HIGH-> LOW
If (cLow + TickSize) < refCheckOHLC Then
If ( (refCheckOHLC - (cLow + TickSize)) / hedgeTick) >= 1 Then
ohlcSum = ohlcSum + Int( (refCheckOHLC - (cLow + TickSize)) / hedgeTick)
refCheckOHLC = refCheckOHLC - Int( (refCheckOHLC - (cLow + TickSize)) / hedgeTick)
End If
End If
' LOW -> CLOSE
If (cClose - TickSize) > refCheckOHLC Then
If ( ((cClose - TickSize) - refCheckOHLC) / hedgeTick) >= 1 Then
ohlcSum = ohlcSum + Int( ((cClose - TickSize) - refCheckOHLC) / hedgeTick )
refCheckOHLC = refCheckOHLC + Int( ((cClose - TickSize) - refCheckOHLC) / hedgeTick )
End If
End If
check = 2
End If

If (check = 2) Then
'Check O->L->H->C Second
' PREV CLOSE -> OPEN
If (cOpen - TickSize) > refCheckOLHC Then
If ( ((cOpen - TickSize) - refCheckOLHC) / hedgeTick) >= 1 Then
olhcSum = olhcSum + Int( ((cOpen - TickSize) - refCheckOLHC) / hedgeTick )
refCheckOLHC = refCheckOLHC + Int( ((cOpen - TickSize) - refCheckOLHC) / hedgeTick )
End If
ElseIf (cOpen + TickSize) <= refCheckOLHC Then
If ( (refCheckOLHC - (cOpen + TickSize)) / hedgeTick) >=1 Then
olhcSum = olhcSum + Int( (refCheckOLHC - (cOpen + TickSize)) / hedgeTick)
refCheckOLHC = refCheckOLHC - Int( (refCheckOLHC - (cOpen + TickSize)) / hedgeTick)
End If
End If
' OPEN -> LOW
If (cLow + TickSize) < refCheckOLHC Then
If ( (refCheckOLHC - (cLow + TickSize)) / hedgeTick) >= 1 Then
olhcSum = olhcSum + Int( (refCheckOLHC - (cLow + TickSize)) / hedgeTick)
refCheckOLHC = refCheckOLHC - Int( (refCheckOLHC - (cLow + TickSize)) / hedgeTick)
End If
End If
' LOW-> HIGH
If (cHigh - TickSize) > refCheckOLHC Then
If ( ((cHigh - TickSize) - refCheckOLHC) / hedgeTick) >= 1 Then
olhcSum = olhcSum + Int( ((cHigh - TickSize) - refCheckOLHC) / hedgeTick)
refCheckOLHC = refCheckOLHC + Int( ((cHigh - TickSize) - refCheckOLHC) / hedgeTick)
End If
End If
' HIGH -> CLOSE
If (cClose + TickSize) < refCheckOLHC Then
If ( (refCheckOLHC - (cClose + TickSize)) / hedgeTick) >= 1 Then
olhcSum = olhcSum + Int( (refCheckOLHC - (cClose + TickSize)) / hedgeTick)
refCheckOLHC = refCheckOLHC - Int( (refCheckOLHC - (cClose + TickSize)) / hedgeTick)
End If
End If
check = 1
End If

If (ohlcSum < olhcSum) Then
tics = tics + ohlcSum
refCheckOLHC = refCheckOHLC
Else:
tics = tics + olhcSum
refCheckOHLC = refCheckOLHC
End If
olhcSum = 0
olhcSum = 0
maestrom is offline  
Reply With Quote
Old 10-29-2008, 10:02 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Hi maestrom,

To use DataSeries you want to check this article: http://www.ninjatrader-support.com/H...iesObject.html

You first create your DataSeries in the Variables region of your code. Then you use the new DataSeries(this); in the Initialize(). Then you can finally use it in the OnBarUpdate(). To give it values you want to use .Set(). To retrieve values you want to use myDataSeries[0] for the current bar and myDataSeries[1] for the previous bar, etc.

Unfortunately we do not offer conversion services, but you could try one of the 3rd party NinjaScript Consultants here: http://www.ninjatrader.com/webnew/pa...injaScript.htm
NinjaTrader_Josh is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Historic Volatility scriabinop23 NinjaScript File Sharing Discussion 12 06-05-2010 09:01 AM
Volatility Stop nadcon NinjaScript File Sharing Discussion 2 04-02-2009 11:42 AM
Volatility Stop nick2112 Charting 1 06-25-2008 03:18 PM
Can somebody code the Volatility stop for NT nico_p Indicator Development 2 03-30-2008 08:47 AM
Historical Volatility Ratio simul316 Indicator Development 0 06-23-2007 06:57 PM


All times are GMT -6. The time now is 05:06 AM.