Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy compiles but does not work - One code line causes error

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

    Strategy compiles but does not work - One code line causes error

    Hi all,

    The attached strategy (simple test strategy: MA1 crosses MA2) worked fine.

    When I add some further calculations (row 91-92) the strategy still compiles but does not work anymore when added to the chart (you can test this easily by commenting out these two lines).

    My troubleshooting did not lead to anything I am afraid. Has anyone experienced a similar problem before? Is there any reference I can use to fix this?

    Thank you,
    P

    aaaMB05.zip

    #2
    Originally posted by pennywise View Post
    Hi all,

    The attached strategy (simple test strategy: MA1 crosses MA2) worked fine.

    When I add some further calculations (row 91-92) the strategy still compiles but does not work anymore when added to the chart (you can test this easily by commenting out these two lines).

    My troubleshooting did not lead to anything I am afraid. Has anyone experienced a similar problem before? Is there any reference I can use to fix this?

    Thank you,
    P

    [ATTACH]n1059469[/ATTACH]
    Wrong location. You should be populating both delta and Avg_Delta series in OnBarUpdate(). You should probably be able to assign Avg_Delta where it is.

    Comment


      #3
      Thank you, koganam, that's a fair point. I understand the difference and clearly have to pay more attention to this.

      Unfortunately, the strategy still does not show anything when I un-comment these two lines (while in OnBarUpdate).

      Is there anything else you can think of?

      Comment


        #4
        Hello pennywise

        Are there errors appearing on the Log tab of the Control Center when enabling the strategy?

        Use prints to debug the script and understand the behavior.

        Below is a link to a forum post that demonstrates using prints to debug a script.


        If you print SMA_FAST[1], SMA_SLOW[1], SMA_FAST[0], and SMA_SLOW[0] slow, are you finding that for a specific bar there should be an entry?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks ChelseaB,

          The Log showed the following error message:
          2019-06-04 19:20:04:154|3|4|Strategy 'aaaMB03': Error on calling 'OnBarUpdate' method on bar 1: Object reference not set to an instance of an object.

          This hinted to missing instantiation and I added the following to the code:
          delta = new Series<double>(this, MaximumBarsLookBack.Infinite);
          Which solved the problem.

          Thanks a lot.
          P

          Comment

          Latest Posts

          Collapse

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