Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

need help converting volatility indicator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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

    #2
    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
    Josh P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by popecapllc, 08-09-2023, 07:42 PM
    8 responses
    1,356 views
    0 likes
    Last Post Johng22
    by Johng22
     
    Started by ETFVoyageur, 04-30-2024, 02:04 PM
    11 responses
    101 views
    0 likes
    Last Post ETFVoyageur  
    Started by bubblegum, 03-18-2024, 10:41 AM
    3 responses
    46 views
    0 likes
    Last Post vjsworld  
    Started by JamesK1, Today, 02:48 PM
    1 response
    13 views
    0 likes
    Last Post JamesK1
    by JamesK1
     
    Started by llanqui, Today, 03:51 PM
    0 responses
    13 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Working...
    X