Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to calculate SMA of my custom variable

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

    #16
    Hello nleitman,

    The SMA saved to mySMA2 should be producing a value of 5.

    Are you doing further assignments on the vByM after it is set to 5?

    I recommend that you create a new test script for testing and only add the one series and the one SMA indicator. (Reducing often finds the mistake in the code)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      The reason the first few values of SMA weren't 5 is because I exited the function right away when CurrentBar is 0 because of the above error. When I assign vByM immediately, I get the proper results:

      vByM 5
      mySMA2[0]5
      vByM 5
      mySMA2[0]5
      vByM 5​

      Comment


        #18
        Hi Chelsea, I solved it. The calculation of vByM has maxvol - minvol in the denominator, and sometimes this is 0. It's 0 on the first iteration and can be 0 later on If those 2 values are identical. I added a check to prevent divide by 0 and now it's working as expected. Being able to use Print() was a big help, so thanks with that and your overall support.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        597 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        343 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        556 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        555 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X