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

Using a Timer on Second Bar Series - Startup Errors

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

    Using a Timer on Second Bar Series - Startup Errors

    Hi,

    I'm using a timer to trigger an event that displays 5 minute volume on my range chart, and I am getting errors in my trace log on startup (below)

    I am fairly sure that I have the timer events setup correctly, its probably what I am doing in the timer event that is the problem. The timer and the events are created in OnStartup() and in my Initialize() I do this -

    Add(PeriodType.Minute, 5);
    volTimer.Start();

    In the timer event I refer to the array VOL(BarsArray[1])[0] which I suspect is the cause of the error, as if the array is not created before the first timer event is triggered?

    Do I need to check the array size or something else first?

    Thanks,
    Will.

    Error Log
    --------------

    at NinjaTrader.Data.DataSeries.get_Item(Int32 barsAgo)
    at NinjaTrader.Indicator.IndicatorBase.get_Item(Int32 barsAgo)
    at NinjaTrader.Indicator.Wills5MinuteVolume.displayVo lume()
    at System.Windows.Forms.Timer.OnTick(EventArgs e)
    at System.Windows.Forms.Timer.TimerNativeWindow.WndPr oc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    2014-03-31 19:08:43:625 in OnUnhandledThreadException
    2014-03-31 19:08:43:625 *************** unhandled exception trapped ***************
    2014-03-31 19:08:43:625 Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    2014-03-31 19:08:43:625 at System.Collections.ArrayList.get_Item(Int32 index)
    at NinjaTrader.Data.DataSeries.get_Item(Int32 barsAgo)
    at NinjaTrader.Indicator.IndicatorBase.get_Item(Int32 barsAgo)
    at NinjaTrader.Indicator.Wills5MinuteVolume.displayVo lume()
    at System.Windows.Forms.Timer.OnTick(EventArgs e)
    at System.Windows.Forms.Timer.TimerNativeWindow.WndPr oc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    #2
    Will, would the outcome change if you're not starting the timer in Initialize() but OnStartUp(), so after the bars array is added and ready?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      No, Bertrand, unfortunately.

      That was where I had it originally and that seems to be worse. It doesnt seem to happen on every chart, but when its in OnStartup() it seems to happen more.

      Either way, its still happening.

      Thanks...

      Comment


        #4
        Hi Will with Initialize() getting called multiple times I would not start the timer there. You update the volume with the timer for realtime only, correct? Would you mind sending me the script to support at ninjatrader dot com so I could give this a quick run here?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Yes, no problem, I will do that shortly.

          Comment


            #6
            Hi, Its sent now,
            Thanks,
            Will.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bc24fl, 08-30-2019, 01:58 PM
            4 responses
            259 views
            0 likes
            Last Post PaulMohn  
            Started by sugalt, Today, 04:02 AM
            0 responses
            6 views
            0 likes
            Last Post sugalt
            by sugalt
             
            Started by tradingnasdaqprueba, 04-09-2024, 09:52 AM
            6 responses
            30 views
            0 likes
            Last Post tradingnasdaqprueba  
            Started by PaulMohn, Today, 02:06 AM
            1 response
            7 views
            0 likes
            Last Post PaulMohn  
            Started by Mindset, Today, 01:27 AM
            0 responses
            6 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X