• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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]

                http://www.ninjatrader.com/support/h...ightsub=Closes


                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 Zenersev, 10-19-2019, 02:11 PM
                      7 responses
                      48 views
                      0 likes
                      Last Post NinjaTrader_PatrickG  
                      Started by Lancer, Today, 10:39 AM
                      4 responses
                      24 views
                      0 likes
                      Last Post Lancer
                      by Lancer
                       
                      Started by koganam, Today, 11:50 AM
                      2 responses
                      11 views
                      0 likes
                      Last Post koganam
                      by koganam
                       
                      Started by koganam, Today, 10:33 AM
                      4 responses
                      14 views
                      0 likes
                      Last Post koganam
                      by koganam
                       
                      Started by FREEN, Today, 10:17 AM
                      3 responses
                      11 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Working...
                      X