Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator 'SMA': Error on Calling OnBarUpdate

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

    Indicator 'SMA': Error on Calling OnBarUpdate

    Hi,

    I am getting two errors. How do I handle/debug these two errors:

    Error 1: My strategy disables when I get the following two errors:
    2020-10-27 16:04:53:685|3|4|Indicator 'SMA': Error on calling 'OnBarUpdate' method on bar 2532: 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.
    2020-10-27 16:04:53:706|3|4|Strategy 'STFUTTRENDFOLLOW': Error on calling 'EventHandlerBarsUpdate' method: Object reference not set to an instance of an object.

    Error 2: I don't see any errors and my strategy is still running or enabled. Last night I left my strategy to run, however this morning I noticed that strategy didn't get into any trades after 3:46AM last night. Which is very odd behavior because it was getting into trades when I left it to run. Please see attached my log file.

    Error 3. Error received from TD Ameritrade account activity stream: Invalid Key … I tried reconnecting with TD Ameritrade already.

    Thanks,
    Attached Files
    Last edited by bjunaid; 10-27-2020, 01:32 PM.

    #2
    Hello bjunaid, thanks for writing in.

    It looks like you are seeing some bugs we experienced in march with the Invalid Key message. Please take these steps:

    Uninstall/Reinstall NinjaTrader.
    Go to the Windows Control Panel and uninstall NinjaTrader. After you have uninstalled, get the latest download here and run the executable:

    https://ninjatrader.com/GetStarted

    Please test your strategy after completing this.

    For the trades the strategy is taking, you would need to use the Print method to find if the strategy is reaching it's conditions or not. If you add a Print within your condition do you see anything the next day? e.g.

    if(<EntryCondition>)
    {
    Print("Entry Condition True");
    EnterLong();
    }

    I look forward to assisting.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I already have the latest version of NT8 installed. Is there another way to tackle the TD Ameritrade error because it takes time to restore all the indicators and reset everything.

      I also want to know about Error#1. Could you tell me why the SMA would give error OnBarUpdate and how I can fix this issue or get around it.

      Comment


        #4
        Hello bjunaid, thans for your reply.

        For the first problem with the custom script, is this reproducible consistently on your script i.e. does it happen every time you enable the strategy? I can test it on my installation if you can export this script and send it into "platformsupport at ninjatrader.com" referencing "Attn ChrisL 2806901"

        For the connection issue, are you completely unable to connect to TDA at the moment? Please send us your full log and trace files so I can have a look at the problem:
        • Open your NinjaTrader folder under, "Documents" (sometimes called, "My Documents")
        • Right click on the 'log' and 'trace' folders and select Send To> Compressed (zipped) Folder.
        • Send the 2 compressed folders as attachments to this email.
        • Once complete, you can delete these compressed folders.
        Please attach these zip files to your email as well.

        I look forward to hearing from you.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Chris,

          Yes I can send you the script, log and trace files.

          Error # 1: Doesn't happen every time but happen often.

          Error # 3: I was able to fix this error I just had to delete the NSF file in DB folder and now it works fine.

          Error # 4: There are a new error(s) which happened last night. My chart was frozen around 3am in the morning.
          2020-10-28 03:11:28:798|3|4|Strategy 'STFUTTRENDFOLLOW': Error on calling 'OnBarUpdate' method on bar 2145: Collection was modified; enumeration operation may not execute.
          2020-10-28 03:11:28:811|3|4|Strategy 'STFUTTRENDFOLLOW': Error on calling 'OnBarUpdate' method on bar 2145: Collection was modified; enumeration operation may not execute.
          2020-10-28 03:11:28:814|3|4|Strategy 'STFUTTRENDFOLLOW': Error on calling 'OnBarUpdate' method on bar 2145: Collection was modified; enumeration operation may not execute.
          2020-10-28 03:11:28:935|3|16|Chart rendering failed. There is likely a problem with a chart object's OnRender method. D2D error = 'HRESULT: [0x88990016], Module: [SharpDX.Direct2D1], ApiCode: [D2DERR_PUSH_POP_UNBALANCED/PushPopUnbalanced], Message: The push and pop calls were unbalanced.

          Error # 5: Connection lost and my strategy became disabled.

          I am soo glad that I am running these scripts on simulation account. After all these errors with NT system, I don't think that I will ever have the confidence to run my strategies in real time and risk real money. Sorry I am just frustrated after spending 8 months hoping one day the strategy will work without any errors.

          Comment


            #6
            Hi Chris,

            I was able to figure out solutions for most of the errors. I need help with the following errors:

            Error #1: Fixed
            Error#2: Fixed
            Error#3: Fixed
            Error#4: Error on calling 'OnBarUpdate' method on bar 2145: Collection was modified; enumeration operation may not execute.
            I need to know what causes this error. I have certain arrays that I am looping through an array in my code of total buy volume and sell volume. What can I do to solve this problem.

            Error#5: Connection Lost. Would you able to provide with an example of strategy that completely handles the connection lost issues and handling of position in an unmanaged approach. I have searched the forums and I didn't find enough examples and documentation available to combine all the bits and pieces together. I have tried the recalculate approach but it gave me devastating results which made my Sim account over drawn by -$212K within seconds.

            Error#6. I am using StreamWriter in my strategy and I am running it on multiple instruments to log enrtries and exits. Following error occurred today, I understand what this error is but I don't know how to handle this error.
            Error on calling 'OnExecutionUpdate' method on bar 6624: The process cannot access the file '.....Documents\NinjaTrader 8\10-30-20-STFUTUNMANTRAIL_EntryLog.txt' because it is being used by another process.

            Please reference the error/issue # I have specified in this forum so it helps me solve each issue separately.

            Thanks



            Comment


              #7
              Hello bjunaid

              Error#4: Error on calling 'OnBarUpdate' method on bar 2145: Collection was modified; enumeration operation may not execute.
              I need to know what causes this error. I have certain arrays that I am looping through an array in my code of total buy volume and sell volume. What can I do to solve this problem.
              This is a common C# error, the part after the bar number: : Collection was modified; enumeration operation may not execute.
              This generally means that you have used a foreach loop on a collection and then modified that collection during the iteration of the collection. A for loop would be used to avoid this error. You can hit this error in some cases by calling NinjaScript syntax like the DrawingTools collection. If you have more details on what code was used when this was generated we could review that.



              Error#5: Connection Lost. Would you able to provide with an example of strategy that completely handles the connection lost issues and handling of position in an unmanaged approach. I have searched the forums and I didn't find enough examples and documentation available to combine all the bits and pieces together. I have tried the recalculate approach but it gave me devastating results which made my Sim account over drawn by -$212K within seconds.
              I am not certain that there is a "complete" sample of a strategy, that would be highly depending on the use case. The samples that our support provides are mainly just simple concept examples. The resolution here would really depend on the extent of your connection loss in combination with your strategies logic. The connection loss causes the connection handling settings to run. If you recalculate that causes the start behavior to run. Depending on your logic, you may or may not be able to use recalculate because one of the start behaviors would need to match your logic and how your historical processing works. If you choose to do nothing that can in some cases work, but again that depends on your logic and the amount of time the loss was for. If it is for a long time you may be doing invalid calculations at that point if nothing is recalculated or reloaded.



              Error#6. I am using StreamWriter in my strategy and I am running it on multiple instruments to log enrtries and exits. Following error occurred today, I understand what this error is but I don't know how to handle this error.
              Error on calling 'OnExecutionUpdate' method on bar 6624: The process cannot access the file '.....Documents\NinjaTrader 8\10-30-20-STFUTUNMANTRAIL_EntryLog.txt' because it is being used by another process.
              You would need to write individual files based on the speed at which writing is happening in scripts that use the same file. If there is going to be any times where two scripts try to access the file this would happen. An alternative approach would be to use an addon and the Account level subscription to the OnExecutionUpdate. There is a sample of that concept in the following link. You would move the writing executions from the strategies to a single addon and run that from State.Active to observe an account.
              https://ninjatrader.com/support/help...ount_class.htm


              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Hi Chris,

                Thanks so much for your reply, I really appreciated your detailed response.

                Error#4: I was able to fix this. I forgot that I actually did have "Foreach" statements in my code.

                Error#5: Connection Lost I have been able to change the statement to handle this part of the error. However it would be great if you can provide me with a some more guidance or real sample strategies that can handle these type of connection errors.

                Error #6: I am looking into your solution and I have an idea to work around this error.

                Error # 7: I am getting Over Fills on my orders by a lot sometimes even 400 Contracts and I lost $212K last week in seconds due to this errorin sim account. How can I handle this in unmanaged approached. I have read other threads on this forum but I couldn't find any example of how to go about handling this. This is an extremely serious and dangerous error. I thought it was a connection problem but it is not and strangely this error doesn't occur even once in Market Replay. Why and How can this error occur? Could you please provide me with a working example of handling this error.

                Error #9 New: My Ninja Trader crashed or closed by itself sometime between last night and this afternoon. How do I handle this type of situation, in case I had open positions?

                Question # 1: I would like to close all open my position created by my strategy, incase my strategy encounters an error and becomes disabled. Should I create a secondary strategy to monitor my primary strategy. What would you recommend for this type of scenario?


                Thanks,
                Last edited by bjunaid; 11-01-2020, 06:40 PM.

                Comment


                  #9
                  Update...

                  Error # 7: Looks like, I was able to fix this error. I was submitting multiple exit orders at the same time, had to enter a Boolean to turn on/off exit submissions. There is still an issue of connection lost problem, which I am not sure how to go about handling. Also, If you know a better way to handle overfills, please let me know. I will much appreciate it.

                  Comment


                    #10
                    Hello bjunaid,

                    Error #9 New: My Ninja Trader crashed or closed by itself sometime between last night and this afternoon. How do I handle this type of situation, in case I had open positions?
                    Being that the timespan was about a half a day could make finding the problem a little more difficult. I would suggest to check on the platform more frequently if you can, this would be important when a live trade is in place or you are testing new items/custom items. You can add some form of email/sms notification keep you posted on whats happening while you are away. You could then know more quickly if something is wrong or if you don't have a recent update you would know to look at the platform. You can also look at using remote desktop applications like teamviewer or microsoft RDC to connect to your PC while outside of the office.

                    To manage a live position after you see some problem, you can use the platform (if possible) to close the position. You would otherwise contact your brokers orders desk.

                    To get an idea of what happened you would first want to take a look at the log files to see if any errors are showing up. This is also generally a good time to ask our support for a hand in looking through the logs by using the Help -> Email support option and including the logs/description of what happened and when it happened.

                    You may want to also see if any windows programs you were using were closed, did windows restart or update? If the PC restarted or went to sleep that could be a reason for the platform being closed or having an error. These would be good items to also check.


                    Question # 1: I would like to close all open my position created by my strategy, incase my strategy encounters an error and becomes disabled. Should I create a secondary strategy to monitor my primary strategy. What would you recommend for this type of scenario?
                    That really depends on what caused the issue. If its connection issues then you likely wouldn't be able to fix the situation with another script, if the platform is having trouble being connected you likely won't be able to manage positions or know about changes from the platform.
                    If connection is not part of the issue and it was just some error, you could potentially use an addon for that purpose or to monitor an account for a position and close it. Another strategy won't see another strategies orders so that would not be a good choice for a monitoring script. An indicator could be used in that case with the addon account class. https://ninjatrader.com/support/help...ount_class.htm

                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Jesse for you reply. I really appreciate it.

                      I have looked at the Addon Framework educational section. I do plan to work on that.

                      Comment


                        #12
                        Thanks Jesse for you reply. I really appreciate it.

                        I have looked at the Addon Framework educational section. I do plan to work on that.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by dpomhgbqwduk, Today, 08:55 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post dpomhgbqwduk  
                        Started by GARZONJ, Today, 05:47 PM
                        2 responses
                        8 views
                        0 likes
                        Last Post GARZONJ
                        by GARZONJ
                         
                        Started by babouin77, Today, 02:57 PM
                        1 response
                        17 views
                        0 likes
                        Last Post NinjaTrader_PatrickH  
                        Started by frasg, Today, 03:04 PM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_PaulG  
                        Started by tonynt, Today, 02:56 PM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_ChrisL  
                        Working...
                        X