Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Understanding Value when it is not calculated

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

    Understanding Value when it is not calculated

    Suppose I have a code where the Value[0] is calculated only after say 10 bars are passed, example below:

    -----
    protected override void OnBarUpdate()
    {

    if (CurrentBar < 10)
    return;

    Value[0] = High[0] - Close[0];
    }

    ---

    1. If I use this indicator in a strategy, what would be values of Value[0] for the first 10 bars? Will be 0, or will be double.NaN ?

    2. What would Value.IsValidDataPoint(0) return for the first 10 bars?
    Last edited by uday12; 07-21-2018, 03:59 PM.

    #2
    Hello uday12,

    Thank you for your note.

    The value for the first 10 bars would be null, since its not being set.

    With if (CurrentBar < 10) at the top of OnBarUpdate, you would never process any code after this line, so Value.IsValidDataPoint(0) would never even be called. If you wanted to dig into this more, you could modify the script to what I’ve posted below and see what the output window says.

    Code:
    protected override void OnBarUpdate()
    {
    if (CurrentBar >10)
    {
    Value[0] = High[0] - Close[0];
    }
    Print(Value.IsValidDataPoint(0).ToString());
    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Alan.

      I was checking the NT 8 guide, and saw there are two related functions: IsValidDataPoint() and IsValidDataPointAt(). The difference was not clear from the documentations. Can you explain it?

      Comment


        #4
        Hello uday12,

        You would use IsValidDataPoint() if you wanted to know if the 2,000th bar was valid. From the most left bar, the first bar, counting to the right.

        You would use IsValidDataPointAt() if you wanted to know if 10 bars ago whether or not that point was valid. So counting to the left from the most recent bar.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by nandhumca, Today, 03:41 PM
        0 responses
        4 views
        0 likes
        Last Post nandhumca  
        Started by The_Sec, Today, 03:37 PM
        0 responses
        3 views
        0 likes
        Last Post The_Sec
        by The_Sec
         
        Started by GwFutures1988, Today, 02:48 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        6 responses
        33 views
        0 likes
        Last Post ScottWalsh  
        Started by frankthearm, Today, 09:08 AM
        10 responses
        36 views
        0 likes
        Last Post frankthearm  
        Working...
        X