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

SMA on DataSeries using a 2nd Time Frame

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

    SMA on DataSeries using a 2nd Time Frame

    Dear all,

    I have the following setup:
    - daily default time frame on a stock (primary time frame)
    - 5 days time frame on the same stock (2nd time frame)

    I compute on the 2nd time frame the Abs(Close-Open), using "BarsInProgress == 1"
    As a consequence, it seems like that:
    - when I am in "BarsInProgress == 0", the dataseries value is set to 0 (and not "empty").
    - if I want to compute a moving average on the last x values of Abs(Close-Open), the result is obviously incorrect (it includes the "0" in the computation).

    How can i solve that problem? Is there a way to define a DataSeries for a specific time frame (in my case my secondary, asking to store a value only every 5 bars)?

    Thank you very much,
    Best

    Nicolas

    #2
    Hello,

    Try using Closes[][] instead of Close[] for your calculations


    Please let me know if I can be of further assistance.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Hi

      I am actually using Closes[][] and Opens[][]. Apologies for the lack of initial precision. I attach the all code so you can look at where I stand. I used an extensive number of "print" and that's where I spotted the issue with the generated dataseries beeing

      Thanks a lot,
      Best

      Nicolas

      Attached Files

      Comment


        #4
        Hello,

        Originally posted by nlaporte View Post
        - when I am in "BarsInProgress == 0", the dataseries value is set to 0 (and not "empty").
        Can you clarify which data series you are referring to? By default if no value is assigned to the dataseries it should return the closing price (this is a feature of NinjaScript to prevent a null reference exception)

        - if I want to compute a moving average on the last x values of Abs(Close-Open), the result is obviously incorrect (it includes the "0" in the computation).

        How can i solve that problem? Is there a way to define a DataSeries for a specific time frame (in my case my secondary, asking to store a value only every 5 bars)?
        You may find that creating a time filter allows you to store the correct data you're trying to get.


        Perhaps I need some further clarification as to your goals as I'm not certain I fully understand what is wrong.

        Please let me know if I can be of further assistance.
        LanceNinjaTrader Customer Service

        Comment


          #5
          Hi Lance,

          Looking at the code I sent you:
          1. I define dataseries as variables with no specification regarding to which timeframe they will be used for --- can a dataseries be defined for a specific timeframe?
          2. I feed the "myAbsOpenCloseSeries" only on "(BarsInProgress == 1)" BUT, to my surprise, each time there a new bar for the primary timeframe, "myAbsOpenCloseSeries" is set with a zero value ---- Am i missing something?
          3. In order to have a chart with data not equal to zero, I added the line "myAbsOpenCloseSeries[0] = myAbsOpenCloseSeries[1];" for "(BarsInProgress == 0)". it works well but it leaves the issue that any stats using the "myAbsOpenCloseSeries" is incorrect (ex: SMA).

          Hopefully i am a little clearer regarding my issue. The all idea of this post is to understand if created timeseries can only have bars related to their timeframe.

          Thanks a lot for your help (and patience )

          Nicolas

          Comment


            #6
            Hello,

            Originally posted by nlaporte View Post
            1. I define dataseries as variables with no specification regarding to which timeframe they will be used for --- can a dataseries be defined for a specific timeframe?
            Yes, the following will serve as a great example for doing so: http://ninjatrader.com/support/forum...ead.php?t=3572

            2. I feed the "myAbsOpenCloseSeries" only on "(BarsInProgress == 1)" BUT, to my surprise, each time there a new bar for the primary timeframe, "myAbsOpenCloseSeries" is set with a zero value ---- Am i missing something?
            Your data series is the size of the primary series and thus has 0s every time the second series is not updated. The above link should help you resolve this

            3. In order to have a chart with data not equal to zero, I added the line "myAbsOpenCloseSeries[0] = myAbsOpenCloseSeries[1];" for "(BarsInProgress == 0)". it works well but it leaves the issue that any stats using the "myAbsOpenCloseSeries" is incorrect (ex: SMA).
            Please let me know if the above example doesn't help with this as well.
            LanceNinjaTrader Customer Service

            Comment


              #7
              Lance,

              Thanks. The example file was exactly what I was looking for and it works fine.
              One question regarding the time frames: does the principal time frame must be the highest frequency or there is no constraint on that side. If you have a H1 and a H4, both can be primary?
              Best

              Nicolas

              Comment


                #8
                Nicolas,

                There is no constraint here. You can either have the H1 as primary or H4 as primary. You can Add() another bars array in any sequence/timeframe that you wish.
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  Thanks Lance

                  Nicolas

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Shansen, 08-30-2019, 10:18 PM
                  24 responses
                  939 views
                  0 likes
                  Last Post spwizard  
                  Started by Max238, Today, 01:28 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Started by rocketman7, Today, 01:00 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post rocketman7  
                  Started by wzgy0920, 04-20-2024, 06:09 PM
                  2 responses
                  28 views
                  0 likes
                  Last Post wzgy0920  
                  Started by wzgy0920, 02-22-2024, 01:11 AM
                  5 responses
                  33 views
                  0 likes
                  Last Post wzgy0920  
                  Working...
                  X