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 SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        36 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        20 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        14 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        19 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        22 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X