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

Multiple timeframe indicator

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

    Multiple timeframe indicator

    Hi,
    I'm trying to create a Swing object (in Swing Indicator class) based on the daily timeframe from within a new indicator which will be used on the 1 minute timeframe. The reason I do this so that I have access to the daily swings from within the lower 1 minute timeframe. I create the time series as follows....

    I've declared the Swing object in the class as follows:
    Swing swingsD1;

    I create the daily data time series:

    AddDataSeries(this.Instrument.FullName, Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);

    How do I pass the bar data series into the Swing object? As follows(??):

    swingsD1 = new Swing(BarsArray[1], 2);

    The problem is that I get an error that there is no constructor that takes 2 arguments. Yet I can see the constructor in the read only Swing indicator class (ships with Ninjatrader 8):

    public Swing Swing(ISeries<double> input, int strength)
    {
    if (cacheSwing != null)
    for (int idx = 0; idx < cacheSwing.Length; idx++)
    if (cacheSwing[idx] != null && cacheSwing[idx].Strength == strength && cacheSwing[idx].EqualsInput(input))
    return cacheSwing[idx];
    return CacheIndicator<Swing>(new Swing(){ Strength = strength }, input, ref cacheSwing);
    }

    I'd appreciate any help
    Thankyou,
    iq
    Last edited by iq200; 03-15-2017, 05:40 AM.

    #2
    Hello,

    Thank you for posting.

    In this case, you are using the new keyword and for NinjaScript indicators, this would not be correct as you will never actually create a new indicator object. The platform would handle creating instances of the indicators, you would just need to use a reference to that:

    Code:
    swingsD1 = Swing(BarsArray[1], 2);
    Otherwise, your syntax is correct aside from the new keyword, passing the series in this way would be used as input for the indicator.

    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello,

      Thank you for posting.

      In this case, you are using the new keyword and for NinjaScript indicators, this would not be correct as you will never actually create a new indicator object. The platform would handle creating instances of the indicators, you would just need to use a reference to that:

      Code:
      swingsD1 = Swing(BarsArray[1], 2);
      Otherwise, your syntax is correct aside from the new keyword, passing the series in this way would be used as input for the indicator.

      Please let me know if I may be of further assistance.
      Thanks Jesse. Once I have loaded the daily bars, using AddDataSeries how can I check how much data has been loaded? I am using Visual Studio to debug but I can't see how to get the number of bars that have loaded.

      Comment


        #4
        Hello,

        Thank you for the reply.

        Generally, you would utilize CurrentBar or CurrentBars[BIP] to check what bar is being processed. There are samples in each page.

        You can also use Count to see what the Count of the series is: http://ninjatrader.com/support/helpG...ries_count.htm


        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello,

          Thank you for the reply.

          Generally, you would utilize CurrentBar or CurrentBars[BIP] to check what bar is being processed. There are samples in each page.

          You can also use Count to see what the Count of the series is: http://ninjatrader.com/support/helpG...ries_count.htm


          Please let me know if I may be of further assistance.
          Say I have 2 days of data in my primary series. I was thinking that I could use the overloaded method that allows you to specify the number of bars to load:

          AddDataSeries(string instrumentName, BarsPeriod barsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)

          I am trying to build the daily support and resistance levels from the last 5 years, so can I not then load say 5 years of daily data using the above function ? This would avoid having to unnecessarily load in the 5 years of data into my primary series because I wouldn't be using it and would slow down the build of my chart. After all, I am only using the higher timeframe to build the levels.

          Is there any other mechanism or method that allows me to do what I am asking as I am wanting to load the primary chart with the levels very quickly?
          Last edited by iq200; 03-15-2017, 11:21 AM.

          Comment


            #6
            Hello,

            Thank you for the additional details.

            In this case, you would use the overload you had mentioned to load more Bars than the primary. You can utilize the following syntax to add a series in this way:

            Code:
            AddDataSeries("AAPL",new BarsPeriod() { BarsPeriodType = BarsPeriodType.Day, Value = 1 }, 3000,"Default 24 x 7", true);
            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello,

              Thank you for the reply.

              When passing the BarsArray, this would map the standard OHLC values to the indicators price series. In the case of the pivots indicator specifically, this has a check to determine if it has an indicator being used or a price series as input. If a price series is used the High and Low of that series is used. You can review the Pivots indicators logic to confirm this or review other logistical items on how it works.

              Regarding MarketDataType.Last, this is the type of data being added, this can be Last Ask or Bid.

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

              Comment


                #8
                Originally posted by NinjaTrader_Jesse View Post
                Hello,

                Thank you for the reply.

                When passing the BarsArray, this would map the standard OHLC values to the indicators price series. In the case of the pivots indicator specifically, this has a check to determine if it has an indicator being used or a price series as input. If a price series is used the High and Low of that series is used. You can review the Pivots indicators logic to confirm this or review other logistical items on how it works.

                Regarding MarketDataType.Last, this is the type of data being added, this can be Last Ask or Bid.

                I look forward to being of further assistance.
                Thanks Jesse, I played around with some code and data and found out the answers
                I think you just missed my message deletion or posted at around the same time..

                Thanks for your help.

                Comment


                  #9
                  I've loaded 5 days of 1 minute data into a chart and applied my indicator which is loading secondary data.

                  I have a weird problem. Basically I am loading up 1000 bars of secondary daily data using the AddDataSeries described above.. In the OnBarUpdate function, I have the following code:
                  if (BarsInProgress == 1)
                  {
                  int CurBar = CurrentBar;
                  if (CurBar == (BarsArray[1].Count - 1))
                  {
                  }
                  }
                  I put a break point (using VS) at the int CurBar = CurrentBar; line. The weird thing is that I can see BarsArray[1].Count is 1000. However if I change the breakpoint to a conditional breakpoint where CurBar is 998 VS breaks. However if I change the condition to 999 (the last value of data loaded) the code doesn't break. Whats going on here?

                  The second thing I wanted to ask is, does the historical data get loaded into the BarsArray incrementally as the OnBarUpdate gets called for each CurrentBar or does it all get loaded at once at the beginning? The reason I ask is that if I try to examine BarsArray[1] at any value above CurrentBar the VS QuickQuickwatch displays an exception but the value at or below CurrentBar can be examined.
                  Last edited by iq200; 03-17-2017, 08:15 AM.

                  Comment


                    #10
                    Hello,

                    Thank you for the question.

                    I believe what you are seeing would be expected, the Count is guaranteed to be Less than or equal to the Count - 1. This would also relate to the Calculate setting, depending if this was set to OnBarClose or OnEachTick.

                    Regarding the data, this would be incremental, although the whole series is actually loaded. OnBarUpdate is called for every bar starting at index 0, that would mean on the first bar you could not access 1 barsAgo because there is not yet 1 bars ago to access.

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

                    Comment


                      #11
                      Jesse,
                      Hmmm I'm a bit confused. I have Calculate set to OnBarClose. I'm looking at data 5 days back from 16 March 2017 i.e. up to yesterday. I load up 1000 daily bars data which I assume ends at and including 16 March 2017. Therefore I would expect CurrentBar to go incrementally from 0 to 999 on each call of OnBarUpdate where 999 is 16 March 2017. Is this wrong? I don't understand why the last call to OnBarUpdate ends at CurrentBar = 998.Where did CurrentBar=999 disappear to?
                      Thanks for all your help
                      Regards,
                      Imran

                      Comment


                        #12
                        Hello,

                        Thank you for the reply.

                        This would just be an item which you need to note that happens, this is also documented in the help guide: the Count is guaranteed to be Less than or equal to the Count - 1.

                        This would mean it can be either 1 less than the count, or 2 or more less than the count, in your specific example that would be 999 or 998 depending on the CalculateOnBarClose setting used.

                        Please let me know if I may be of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          HI Jesse Thanks for your reply. I did read the section on the count. I can understand it could be 2 less than count if I was looking at live data when 'todays' session had not closed. Would you be able to tell me under what circumstances will the count be 2 less than the count especially as I am looking at the historical data.
                          Thanks,
                          iq

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by xiinteractive, 04-09-2024, 08:08 AM
                          6 responses
                          22 views
                          0 likes
                          Last Post xiinteractive  
                          Started by Pattontje, Yesterday, 02:10 PM
                          2 responses
                          15 views
                          0 likes
                          Last Post Pattontje  
                          Started by flybuzz, 04-21-2024, 04:07 PM
                          17 responses
                          229 views
                          0 likes
                          Last Post TradingLoss  
                          Started by agclub, 04-21-2024, 08:57 PM
                          3 responses
                          17 views
                          0 likes
                          Last Post TradingLoss  
                          Started by TradingLoss, 04-21-2024, 04:32 PM
                          4 responses
                          45 views
                          2 likes
                          Last Post TradingLoss  
                          Working...
                          X