Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Seemingly random inconsistencies with Strat Analyzer

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

    Seemingly random inconsistencies with Strat Analyzer

    I've been attempting to execute a function passed in an object, first as lambda then without arguments. But when i try this, it never works well. Sometimes it works, and other times it cannot access BarsArray[0] and I have no idea why.

    I've now removed all instances of randomized values from my code, trying to iron this out.

    I click run on the analyzer, it backtests and produces a result.
    I click it again with no changes, and I get various error when the code is trying to access BarsArray[0]. This is the primary series and should always be available, as I have full data for the instrument. I've placed all sorts of null checks and it throws erros without executiong the null check prints

    The behavior alternates almost every other click between running the backtest. With Try catch the execution continues but a lot of bars arer

    What would cause this behavior? It's becoming very difficult to debug when it works


    Data loads fine: BEGIN DataLoaded CurrentBars[0] -1 BarsArray[0].Count 25620 BarsArray[2].Count 25602 >> barsType length 25602
    Code:
    string msg = " aaaa ";
    try
    {
    msg = " TRY "+Time[0];
    // Check if BarsArray and BarsArray[0] are not null
    if (BarsArray[0] == null || BarsArray[1] == null || BarsArray[2] == null)
    {
    Print(Time[0] + " BarsArray or one of its elements is null.");
    return FunctionResponses.NoAction;
    }
    "Error in CalculateOrderFlowRate rt Object reference not set to an instance of an object. aaaa "

    Then if i remove Time[0]

    Code:
    string msg = " aaaa ";
     msg = " TRY  using BarsInProgress "+BarsInProgress ;
                     // Check if BarsArray and BarsArray[0] are not null
                    if (BarsArray[0] == null || BarsArray[1] == null || BarsArray[2] == null)
                    {
                        Print(Time[0] +  " BarsArray or one of its elements is null.");
                        return FunctionResponses.NoAction;
                    }
                    BackBrush = Brushes.Cyan;​
    "Error in CalculateOrderFlowRate rt Object reference not set to an instance of an object. TRY using BarsInProgress 0
    T3​"

    In the above example, it wont even check for null values before it throws the error? In the screen shot, cyan is where it works and not painted is where it cant find the series.

    Any tips?
    Last edited by Skifree; 09-28-2024, 06:23 PM.

    #2
    Hello Skifree,

    The error Object reference not set to an instance of an object means something you tried to use was null when you used it. I can't tell from your code what may be wrong, you will likely need to add additional prints to see which object is null and where in the code that is happening. You likely should remove the functions for now and make sure all of your logic works without adding any extra C# items like functions. Once you know it works and has no errors you can experiment with deconstructing the code into functions.

    Comment


      #3
      I eventually scrapped the whole idea I had and no longer am tying to pass functions - It's not about the error - I'd understand if it didn't work, but how could my code possibly fail every other run without any random values being used? NT is applying some level of inconsistency. I ended up tracing all of the code back to absolutely nothing, counting the number of passes the code across various branches and I kept getting small differences for the same timeframe.

      If you note in this thread, https://forum.ninjatrader.com/forum/...-volume-on-vps I'm having yet another problem. I'm running a strategy now on my desktop, live trading MGC DEC24. But when I try to run the exact same strategy on my VPS, it just won't load MGC Volumetric - no errors or anything. How could that be? When I run MGC in the templates, it works. When I swap MGC for Silver, it works.

      What is the NT doing or failing to do?

      Comment


        #4
        Hello Skifree,

        I wouldn't be able to say without a concrete sample that demonstrates the exact code and also shows what object was null. If you are no longer having the problem without the functions it may have been a result of how the script was coded.

        Regarding the other post, I see you just posted that today so that is still in the queue. Once one of the team members is assigned that case and has time to work it they will post a reply.

        Comment


          #5
          My understanding is that anything within the namespace or strategy can always access BarsArray[0]. Is that not true?

          Comment


            #6
            Hello Skifree,

            That is not true, the namespace is just a namespace which can hold separate classes. Inside the strategy class some areas of the script can access BarsArray but only after data has been loaded and OnBarUpdate is being called.

            Comment


              #7
              To be more clear, assume all of this is after data has been loaded. If I'm passing a lambda to a custom class and that class shares the same name space as the strategy class, should they both have access once the lambda class is added and initialized, and the function being executed is within the main strategy, shouldn't the primary series be available?

              Comment


                #8
                Hello Skifree,

                The namespace doesn't matter in that case, you are passing an object to the class from the strategy, it could be in any namespace. Only the strategy itself has the NinjaScript context so depending on what you are doing and how that class is built that may be part of the problem. If you are set on using the methods and class I would suggest making an extremely simple example script where you have a class with a single method and only that method is being called from the strategy in the way that produces the error. We can then look at that with the full context to get a better idea why that happened.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                61 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                40 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                21 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                23 views
                0 likes
                Last Post TheRealMorford  
                Started by Mindset, 02-28-2026, 06:16 AM
                0 responses
                51 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Working...
                X