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 Barry Milan, Yesterday, 10:35 PM
            5 responses
            16 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by DanielSanMartin, Yesterday, 02:37 PM
            2 responses
            13 views
            0 likes
            Last Post DanielSanMartin  
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            11 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            8 views
            0 likes
            Last Post nandhumca  
            Working...
            X