Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SMA producing NAN result.

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

    SMA producing NAN result.

    In my script I have declared 6 double series call them A, B, C, D, E, and F for simplicity.

    Within OnBarUpdate I then have:

    A[0] = High[0] - Low[0] ;
    B[0] = Math.Abs(Close[0] - Open[0]) ;

    C[0] = A[0] - B[0] ;
    D[0] = SMA(C,6)[0] ; // This SMA produces a proper result

    E[0] = C[0] / B[0] ; // This is just C normalized to B, i.e. (A - B) / B
    F[0] = SMA(E,6)[0] ; // This Produces the NAN result


    All of the series A through E produce proper results but series F gives NAN for some reason.

    If, in series E, I replace B[0] with a constant such as:

    E[0] = C[0] / 9.5 ;

    Then F produces a correct result.

    F[0] = SMA(E,6)[0]; // Produces a correct result when B[0] is replaced with a constant.

    So why, in the series F, is the SMA choking on the division by B[0], yet the series E is just fine with the division by B[0]?

    Thank you for your insights and fixes.
    Last edited by Dr Kerry; 11-10-2023, 01:19 PM.

    #2
    Hello Dr Kerry,

    From the given sample I don't see anything specifically wrong. Are you certain that you are getting populated values in the E series? Adding a print right after setting it would be a good way to make sure the series is populated before passing it to the SMA. I would otherwise suggest making a small sample script that has those series and math and then attach it so that we can see the full extent of what you had done.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    47 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    22 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    33 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X