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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        156 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        90 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        139 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        130 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        107 views
        0 likes
        Last Post CarlTrading  
        Working...
        X