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 CaptainJack, 05-29-2026, 05:09 AM
        0 responses
        244 views
        0 likes
        Last Post CaptainJack  
        Started by CaptainJack, 05-29-2026, 12:02 AM
        0 responses
        157 views
        0 likes
        Last Post CaptainJack  
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        165 views
        1 like
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        249 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        200 views
        0 likes
        Last Post CarlTrading  
        Working...
        X