• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error:Error on calling 'OnExecutionUpdare'

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

    Error:Error on calling 'OnExecutionUpdare'

    Hello,

    I can't make my strategy in backtesting to work, In log I see next error:
    Strategy 'MyTest/-1':Error on calling 'OnExecutionUpdate' method on bar 1364: index was outside the bounds of the array.

    Any cause for this? Thanks
    Code:
    protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"MyTest.";
                    Name                                        = "MyTest";
                    Calculate                               = Calculate.OnBarClose;
                    EntriesPerDirection                     = 1;
                    EntryHandling                           = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy            = true;
                    ExitOnSessionCloseSeconds               = 30;
                    IsFillLimitOnTouch                      = false;
                    MaximumBarsLookBack                     = MaximumBarsLookBack.TwoHundredFiftySix;
                    OrderFillResolution                     = OrderFillResolution.Standard;
                    Slippage                                = 0;
                    StartBehavior                           = StartBehavior.WaitUntilFlat;
                    TimeInForce                             = TimeInForce.Gtc;
                    TraceOrders                             = false;
                    RealtimeErrorHandling                   = RealtimeErrorHandling.StopCancelClose;
                    StopTargetHandling                      = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade                     = 10;
    }
    }

    #2
    Hello soma8,

    Below I am providing a link to the NinjaTrader 8 Beta section of the forums (for future reference).
    http://ninjatrader.com/support/forum...splay.php?f=59

    The error appears to be coming from OnExecution and involves calling an invalid index. For example calling [1] on a collection, array, or data series where the object does not have two elements.

    However, you have not included the OnExecution method from your script. I recommend that you look closely at OnExecution and try commenting out any calls to specific indexes and see if this stops the error. (This would let you know what line of code is causing the error)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      I have an issue with this kind of error:

      Error on calling 'OnStateChange' method: Index was outside the bounds of the array.

      I have experienced this kind of error before but in section OnBarUpdate. OnStateChange occurance is new to me has anybody experienced this kind of error before. Are there some examples what is causing it?

      Thank you fro your feedback

      Miroslav

      Comment


        #4
        Hello miroslav,

        There are not many things that are collections that would be accessed in OnStateChange. I'm not aware of an existing example.

        But if you were to try and call PlotBrushes on an index that doesn't exist that would likely cause an error.
        Code:
        protected override void OnStateChange()
        {
        	if (State == State.Historical)
        	{
        		Print(PlotBrushes[5][0].ToString());
        	}
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          thank you for your feedback. Mean while I found out that is causing an error. It is ploting of the lines which are calculate in separate script but the script has Error on calling 'OnBarUpdate' method on bar 2: Object reference not set to an instance of an object.

          The issue is that it is conversion from NT7 to NT8 and ini NT7 line script was using userdefined methods which is not supported in the NT8 version.

          Comment


            #6
            A client and I are experiencing a crash of Ninja from an unhandled Exception inside OnExecutionUpdate. There was nothing obvious in the code there doing any indexing.

            This is from the Trace file:


            2017-11-13 10:17:32:812 ERROR: Strategy 'mlRenkoColorChange/114749769': Error on calling 'OnExecutionUpdate' method on bar 6: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
            2017-11-13 10:17:32:814 *************** unhandled exception trapped ***************
            2017-11-13 10:17:32:814 Object reference not set to an instance of an object.
            2017-11-13 10:17:32:819 System.NullReferenceException: Object reference not set to an instance of an object.
            at NinjaTrader.NinjaScript.NinjaScriptBase.Update(Int 32 idx, Int32 bip)
            at NinjaTrader.NinjaScript.NinjaScriptBase.TickReplay OrUpdate()
            at NinjaTrader.NinjaScript.NinjaScriptBase.SetState(S tate state)
            at NinjaTrader.Gui.NinjaScript.StrategyRenderBase.Set State(State state)
            at NinjaTrader.Gui.Chart.ChartControl.<>c__DisplayCla ss83_0.<StrategyEnable>b__3(Object o)
            at System.Threading.ExecutionContext.RunInternal(Exec utionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
            at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
            at System.Threading.QueueUserWorkItemCallback.System. Threading.IThreadPoolWorkItem.ExecuteWorkItem()
            at System.Threading.ThreadPoolWorkQueue.Dispatch()
            Cheers,
            saltminer

            Comment


              #7
              Hello saltminer,

              To confirm, you are checking all indexes exist before using them?

              You are using TriggerCustomEvent() for synchronizing before using any series data in a non-data-driven method such as OnExecution()?

              Below is a publicly available link to the help guide on TriggerCustomEvent().
              https://ninjatrader.com/support/help...ustomevent.htm

              May I have an export of a reduced script with only the bare minimum code to reproduce the behavior?


              To export a NinjaTrader 8 NinjaScript do the following:
              1. Click Tools -> Export -> NinjaScript...
              2. Click the 'add' link -> check the box(es) for the script(s) you want to include
              3. Click the 'Export' button
              4. Enter a unique name for the file in the value for 'File name:'
              5. Choose a save location -> click Save
              6. Click OK to clear the export location message

              By default your exported file will be in the following location:
              • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>


              Below is a publicly available link to the help guide on Exporting NinjaScripts.
              http://ninjatrader.com/support/helpG...-us/export.htm
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi Chelsea,
                I'm familiar with TriggerCustomEvent but have never used it for OnExecutionUpdate.
                I'll give it a try.

                Cheers,
                saltminer

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by davidnorton, Today, 04:29 AM
                0 responses
                2 views
                0 likes
                Last Post davidnorton  
                Started by maggie3, Today, 02:05 AM
                0 responses
                3 views
                0 likes
                Last Post maggie3
                by maggie3
                 
                Started by qewcool, Today, 01:14 AM
                0 responses
                3 views
                0 likes
                Last Post qewcool
                by qewcool
                 
                Started by fredrikn, 05-08-2019, 04:01 AM
                17 responses
                669 views
                1 like
                Last Post emtrader  
                Started by zacharydw00, Yesterday, 10:19 PM
                0 responses
                3 views
                0 likes
                Last Post zacharydw00  
                Working...
                X