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

one indicator, two intervals

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

    one indicator, two intervals

    I'm sure the answer is No...but I'll ask anyway.

    Is there any way for one instance of an indicator to process two different intervals for the same instrument?

    It will be running in Market Analyzer and not on a chart.

    :-)

    #2
    Hello TurtleTrader,

    Yes, you can have an underlying data series added to the script to use a different timeframe for calculations.

    Please see the link below on adding Multiple Timeframes and Instruments to your script -
    http://www.ninjatrader.com/support/h...nstruments.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      range

      Hi Cal,

      would that work for range bars also?

      for example 5 range and 10 range?

      Comment


        #4
        Yes, this would work for Range bars as well
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          error

          I'm getting an error

          Cannot apply indexing with [] to an expression of type 'double'

          Initialize:

          Add (PeriodType.Range, 10);

          OnBarUpdate;

          SMA(20)[1][0]

          Comment


            #6
            Hello,

            Thank you for the question.

            The error you are getting would be related to this statement:

            SMA(20)[1][0]

            The SMA is a IDataSeries by its self or SMA(20)
            The Double would be the index of the DataSeries or SMA(20)[1]

            You have an additional bracket and [0] at the end, so you are trying to add check a double at index 0 which a double does not have an index to check.

            You would just need to correct the syntax to reflect the SMA(20)[BarsAgo] to get a double value, or if you need a data series instead, use it without the index or just SMA(20)

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              reply

              OK, I'm confused...

              how would I get the SMA of the data series I added with Add (PeriodType.Range, 10)?

              Would it be SMA (BarsArray[1], 20) [0]?

              Comment


                #8
                Hello,

                Yes that is correct, Adding DataSeries will allow you to access the greater than 0 index locations of BarsArray or for specific sets of data such as Close Open High Low series, you could use any of the following:

                Closes[1]. Opens[1], Highs[1], Lows[1]




                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  CalculateOnBarClose = false;

                  OK, thank you...another question

                  when CalculateOnBarClose = false

                  and the indicator has 2 intervals, the primary and then a second one with an Add()

                  Both intervals on the same instrument, say CL 05-15

                  how does that affect the calling of method OnBarUpdate()?

                  Is it called twice for each tick? (I don't imagine so...but....)

                  What is the value of BarsInProgress when OnBarUpdate is called?

                  Comment


                    #10
                    also...

                    is this the correct syntax to get the current bar number for the added series?

                    BarsArray[1].CurrentBar

                    Comment


                      #11
                      Hello,

                      This is a very good question,

                      A quick answer is yes, both BarsInProgress are called for each tick. To further examine this I would recommend doing the following test on your end on a few various time frames so you can see the "big picture" on how BarsInProgress is working.

                      In a Test Indicator, place the following into the OnBarUpdate:

                      Print(BarsInProgress);

                      In Initialize, use Add and Add any secondary timeframe.

                      Now if you open the Tools -> Output Window and then load the test indicator on the chart, you will see the output from the test.

                      With CalculateOnBarClose = true, we would see something similar to the following assuming 1 minute bar and Adding 10 Range :


                      0
                      1
                      0
                      1
                      1
                      1
                      0
                      etc...


                      With it set to false we would see something like:

                      0
                      1
                      0
                      1
                      0
                      1
                      0
                      etc..

                      When In Doubt with BarsInProgress, it is a great tool to print the BarsInProgress value or also you can Print CurrentBar or CurrentBars[index] as a test to ensure everything is lining up in the chart as it did in your head.

                      For CurrentBar, simply use CurrentBar for the Primary, any secondary you can check using one of two checks. CurrentBars[1] would be the equivalant to CurrentBar but for the secondary series, or:

                      if(BarsInProgress == 1)
                      {
                      Print(CurrentBar)
                      }

                      This CurrentBar would refer to the CurrentBar only for the second series because this would only be called during the BarsInProgress 1 or the second series.


                      I look forward to being of further assistance.
                      Last edited by NinjaTrader_Jesse; 04-06-2015, 09:49 AM.
                      JesseNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Aviram Y, Today, 05:29 AM
                      4 responses
                      11 views
                      0 likes
                      Last Post Aviram Y  
                      Started by algospoke, 04-17-2024, 06:40 PM
                      3 responses
                      26 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by bmartz, 03-12-2024, 06:12 AM
                      3 responses
                      30 views
                      0 likes
                      Last Post NinjaTrader_Zachary  
                      Started by gentlebenthebear, Today, 01:30 AM
                      1 response
                      8 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by cls71, Today, 04:45 AM
                      1 response
                      7 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Working...
                      X