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 NullPointStrategies, Today, 05:17 AM
    0 responses
    38 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    64 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X