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

Advice On How to Programically Set an Indicator's Input Series

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

    Advice On How to Programically Set an Indicator's Input Series

    Hello,

    I am trying to build an indicator that displays Green dots (on the chart) showing the closing price of 1 minute ES 03-16 Bid bars. (FYI: I am building this indicator so that I can see this value on the Startegy Analyzer's chart even when I don't have the mentioned bars as my primary data series.)

    This indicator seems to work fine when I manually set its "Input Series" to "ES 03-16 (1 Min)" as shown by the green arrow in attached screenshot 1.jpg. However, the indicator stops working when I change the mentioned Input Series in 1.jpg

    I'm guessing the solution is to code my indicator so that its Input Series is automatically "1 minute ES 03-16 Bid Bars"?

    If so, what would I change about the indicator's code (shown below) to do this?

    (Also, if you need more details, the full code of the current version of my indicator can be found in the attached OneMinuteBidDotOnClose.zip file.)

    Thank you so much.

    Code:
            protected override void Initialize()
            {
    			Add("ES 03-16",PeriodType.Minute, 1, MarketDataType.Bid);
                Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Dot, "Plot0"));
                Overlay				= true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
              if (BarsInProgress == 1)
    		  {
    			Plot0.Set(Closes[1][0]);
    		  }
            }
    Attached Files

    #2
    Hi Kognam, here is the error message I am getting

    4/6/2016 3:27:39 PM,Default,Error on calling 'OnBarUpdate' method for indicator 'OneMinuteBidDotOnClose' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.,
    Thanks

    P.S.

    I did some additional testing and it seems the issue (and above log error message) only comes up when the primary data series is higher then 1 minute.
    It does not seem to come up when the primary data series is 1 minute or lower.
    Last edited by Matheyas5; 04-06-2016, 02:06 PM.

    Comment


      #3
      Hello Matheyas5,

      I believe the reason you are seeing that message is because your BarsInProgress is intended to be used in a different way. I am including an excerpt from the Help Guide page on BarsArray :

      Code:
      [FONT=Courier New]protected override void OnBarUpdate() 
      { 
       [B]// Ignore bar update events for the supplementary Bars object added above 
           if (BarsInProgress == 1) 
                return; [/B]
       
           // Pass in a Bars object as input for the simple moving average method 
           // Checks if the 20 SMA of the primary Bars is greater than 
           // the 20 SMA of the secondary Bars added above 
           if (SMA(20)[0] > SMA(BarsArray[1], 20)[0]) 
                EnterLong(); 
      }[/FONT]
      Emphasis mine. We can see in the above code that when BarsInProgress matches the bar we would like to reference in BarsArray, we exit immediately, so that the code doesn't try to use BarsArray[1] until it has had a chance to populate.

      Therefore, in your code sample, I would recommend changing

      Code:
      [FONT=Courier New]if (BarsInProgress [B]==[/B] 1)[/FONT]
      to

      Code:
      [FONT=Courier New]if (BarsInProgress [B]!=[/B] 1)[/FONT]
      As this is an involved topic, I am also including the Help Guide link to the "Multi Time Frame and Instruments" section.



      This section is very helpful for understanding how to use Indicators with multiple data series. Please let us know if there is any other way we can help.
      Jessica P.NinjaTrader Customer Service

      Comment


        #4
        Hi Jessica,

        I made the code change you recommended (quoted below).
        Now when I use the indicator on a chart with a primary data series of 10 minute Last bars the green dots only show up on the 10 minute bars.
        And when I use the indicator on a chart with a primary data series of 30 second Last bars the green dots only show up on the 30 second last bars.

        Any idea whats causing this issue?


        Therefore, in your code sample, I would recommend changing

        Code:
        if (BarsInProgress == 1)
        to

        Code:
        if (BarsInProgress != 1)

        Comment


          #5
          Hi Koganam,

          I just tried that and the same issue/error message still came up.

          (FYI: seems you left out the extra "r" in "CurentBars" in the code you posted in post 6#. My latest test did include adding the extra "r", but the same issue/error message still came up.)

          thnks

          Comment


            #6
            I just double check via recompiling it and running it again. Same results.

            The full source code is attached. Perhaps I coded something wrong within it that I did not realize?

            Thanks.
            Attached Files

            Comment


              #7
              Just tried the new version Koganam, then problem still comes up.

              Any thoughts on this Jessica?

              Thanks

              Comment


                #8
                Originally posted by koganam
                "ES 03-16" does not exist as an instrument in the current time frame. Use the current contract.
                ES 03-16 is the contract I want to backtest and use this indicator on during the backtest. I don't want to use it on the current contract (aka ES 06-16).
                All tests I've mentioned in this thread were using ES 03-16 for both BarsInProgress == 0 and BarsInProgress == 1

                koganam, I know your trying to help and I really appreciate it, but I kindly ask you don't
                respond to this thread untill Jessica or someone else from NT shares their thoughts OR untill you've tested the indicator yourself, got the results I am looking for and can attached the source code.

                Thanks.

                Thanks.
                Last edited by Matheyas5; 04-08-2016, 01:22 PM.

                Comment


                  #9
                  Hi kognam,

                  My apologies. I didn't notice you had tested the indicator and posted your results in post 12 until after I had pressed enter on post 13.

                  Anyway, your screenshot in post 12 shows the indicator only displays a blue dot showing the close price of the 1 minute Bid bar every half hour, rather then every minute. I am looking for it to display every minute.

                  Feel free to respond if you like, totally understood if your no longer willing Again, my sincere apologies.

                  Comment


                    #10
                    Thanks for the info Kognam.

                    Can you please post a full code example for an indicator that will display a green dot showing the closing bid price of a 1 minute bid bar every 1 minute (regardardless of what timeframe is used as the primary data series)?

                    For example, if the primary data series I was using on the chart was 10 minute Last bars, there would be ten green dots between each 10 minute Last bar.
                    And if the primary data series I was using on the chart was 10 seconds Last bars, there would be six 10 second Last bars between each green dot.

                    I'm sure there is a way to do this via the DrawDot() as you mentioned, however i've spent the past few hours trying to figure it out and have not had any success. Would really save me a lot of time if you posted the full code example.

                    Thanks you so much!

                    Comment


                      #11
                      Hi Kognam,

                      The main purpose of why I wanted to build this indicator is so that I can use it in the Strategy Analyzer. When using the Strategy Analyzer I cannot select a BarSeries in the area you showed in your screenshot other then the primary BarSeries.

                      Please post code of completed version of this indicator that won't have this issue.

                      thanks
                      Last edited by Matheyas5; 04-11-2016, 11:28 AM.

                      Comment


                        #12
                        Hello Matheyas5,

                        I believe everything koganam has said so far in this thread has been very helpful and in line with what I would have said.

                        I believe, in order to better understand what is happening with your code, that it may be useful at this point to create some trace code. I am providing a sample to show you what I mean.

                        protected override void OnBarUpdate()
                        {
                        Print(String.Format("At time {0}, BarsInProgress is {1}, Close is {2}", Time[0].ToLongTimeString(), BarsInProgress, Closes[1][0]));
                        }

                        If you could include that print statement in your code, and then send some lines of output from your Tools -> Output Window that occur near the times we are concerned with in the Strategy Analyzer, I believe it will be easier to assist further. I would highly recommend setting CalculateOnBarClose = false for this test.
                        Jessica P.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks for the info Jessica.

                          Before I run that code I just want to mention that I re-read post #1 of this thread and realized I could have written it a little clearer, my apologies for that. Anyway, just to be totally sure we are on the same page, here is a clearer description of what I am trying to accomplish and the issues coming up. (Note: The code I am referring to below is the same exact .zip file attached to post #1 of this thread.)

                          I am trying to make an indicator that gets the charts generated by the Strategy Analyzer to display Green dots showing the Closing Bid prices of 1 minute Bid Bars regardless of what Data Series is selected in the area of the Strategy Analyzer pointed to in red in attached 1.jpg. (Note: doing this in the Strategy Analyzer's charts is trickier then doing it in NT's regular charts because only one Data Series can be manually added in the Strategy Analyzer (as shown in attached 1jpg) unlike NT's regular charts where multiple data series can be added manually (as shown in attached 2.jpg):

                          For example, if the Data Series I selected in 1.jpg was 30 Second Last Bars then every other 30 second last bar would have a green dot on it, as shown in attached 3.jpg.
                          If the Data Series I selected in 1.jpg was 5 minute Last Bars then there would be 5 green gots between every 5 minute Last bar, as shown in attached 4.jpg.

                          Everything works fine when I select a Data Series of 60 seconds or lower in 1.jpg, however when I select a Data series above 60 seconds in 1.jpg the green dots don't appear and I get the following error message

                          Date,Category,Message,
                          4/11/2016 7:53:40 PM,Default,Error on calling 'OnBarUpdate' method for indicator 'OneMinuteBidDotOnClose' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                          Anyway, would you still like me to run the code from Post #21 of this thread?

                          Thanks again!
                          Attached Files

                          Comment


                            #14
                            Hello,

                            Thank you for the reply.

                            If you are trying to plot a dot at each 30 second increment regardless of the primary timeframe, you can use basically what you already have posted aside from checking that the correct data is there. This would produce a result if the primary was 30 seconds, every other bar would have a dot or every 1 minute. If the primary was 5 minutes, there would be 1 dot on each bar, but the value would be of the Last 30 second bar during that time frame because the value would be reset a few times each bar.

                            The syntax I tried was the following which produced the above result :

                            Code:
                            if (BarsInProgress == 1 && CurrentBars[0] > 0 && CurrentBars[1] > 0)
                            {
                                Value.Set(Closes[1][0]);
                            }
                            This would be on each of the 1 minute bars, if there is at least 1 bar on each series, plot the Close of the 1 minute series.

                            I have attached an image of the results on 30 seconds and 5 minutes.



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

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Aviram Y, Today, 05:29 AM
                            0 responses
                            2 views
                            0 likes
                            Last Post Aviram Y  
                            Started by quantismo, 04-17-2024, 05:13 PM
                            3 responses
                            25 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by ScottWalsh, 04-16-2024, 04:29 PM
                            7 responses
                            34 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by cls71, Today, 04:45 AM
                            0 responses
                            6 views
                            0 likes
                            Last Post cls71
                            by cls71
                             
                            Started by mjairg, 07-20-2023, 11:57 PM
                            3 responses
                            217 views
                            1 like
                            Last Post PaulMohn  
                            Working...
                            X