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

BarsInProgress always 1 in OnRender() after AddDataSeries()

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

    BarsInProgress always 1 in OnRender() after AddDataSeries()

    Hello,

    After I AddDataSeries() to my indicator, I understand that I can can use BarsInProgress to determine which dataseries is being processed in OnBarUpdate().

    Such as described here:


    However, for OnRender() it seems that BarsInProgress is always 1 (never 0... or very, very rarely).

    Is there something special I need to do?

    I've attached a simple example that outputs the BarsInProgress value during OnRender.

    Thanks!
    Attached Files
    Last edited by neoikon; 03-23-2017, 12:01 PM.

    #2
    Hello neoikon,

    Thank you for the post.

    Generally, for NinjaScript Properties such as the CurrentBar, BarsInProgress or other inherited properties you would need to store these as variables and access the Variable instead of the property directly. This is due to how the platform handles the event driven methods versus the other methods in the platform like OnRender.

    You could do something as simple as the following:

    Code:
    private int CurrentBIP = -1;
    
    protected override void OnBarUpdate()
    {
    	CurrentBIP = BarsInProgress;
    
    }
    
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    	if(CurrentBIP == 0)
    	{
    		
    	} else if (CurrentBIP == 1)
    	{
    		
    	}
    }
    Using OnRender would also entail that you access Price information and other variables in the correct way such as using GetClose, GetOpen etc.. http://ninjatrader.com/support/helpG...htsub=GetClose

    You can see the included SampleCustomRender or Pivots indicators for more examples of OnRender usage.


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

    Comment


      #3
      I tried what you said (updated code attached), but it seems to still only be set to 1 (except for right when you refresh the chart, it's 0 for 2-3 times).

      Is there something else I need to change?
      Attached Files
      Last edited by neoikon; 03-23-2017, 12:46 PM.

      Comment


        #4
        Hello neoikon,

        What is the outcome you are expecting from the prints in this situation? I believe there may be some confusion on what should happen here.

        OnRender would not be called for Historical bars, so you would only start seeing prints when you can see the chart, whichever BarsInProgress is being processed at that time. You should see a lot of output depending on the MarketData at the time of testing and would see the BIP 0 and 1 prints for each series only if the variable was set when OnRender was called.

        Perhaps it would be best to better understand what your goal is, potentially this is not the correct way to go about reaching that result. Generally, you would need to complete any specific BIP logic in OnBarUpdate where you are in sync and only Display results of stored variables from OnRender. The Pivots indicator does this by using Plots and then only renders values from those plots for the visible bars as one example.

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

        Comment


          #5
          For simplicity sake, say I want to add a DataSeries to the built in @ZigZag (I understand not modifying the "@" indicators, but just for this example).

          If I add a AddDataSeries() to the ZigZag, it breaks.

          Perhaps it's due to needing to be more explicit as to which dataseries with calls to ChartBars.FromIndex, IsValidDataPointAt(), Bars.Count, etc?

          Would ChartBars.FromIndex not be an issue?

          What about calling, Bars.GetClose(barIndex)? Am I guaranteed this will be the primary dataseries? (I'm thinking I need to use BarsArray[0].GetClose(barIndex) intead, correct?)

          EDIT: After some playing around and creating a global variable for CurrentBar and making sure I use BarsArray (instead of just Bars), things seem to be looking pretty promising!
          Last edited by neoikon; 03-23-2017, 02:32 PM.

          Comment


            #6
            Hello neoikon,

            Yes in contrast to an existing script that already has logic, adding a second series would likely break its logic. This could occur in any of the sections of its logic which could include OnBarUpdate, OnRender or OnMarketData events.

            Because the indicator was initially programmed to only use the primary series, you would likely need to work from a starting point and then debug the script through its logic until it works as expected. This would likely include commenting out all code and then adding in more conditions to ensure the existing logic works for the BIP it was intended to work for. After doing this process and making the indicator work again, you could then append your secondary series logic and make other changes. Getting the indicator to just work after adding the second series should be the primary goal before anything else because it will very likely either not work at all, or work very differently.

            Coming from the other direction or creating an entirely new script, you won't really run into this situation because you will very likely plan ahead and account for the second series to start with. I just wanted to mention this as converting an existing script and developing a new script can be extremely different processes.

            What I could suggest would be to either duplicate the ZigZag and comment out all logic, then work forward after adding the series, Or start with a fresh script and add your series to start with. You could then slowly copy parts of the ZigZag in and test each piece individually. Either approach would likely have a better success than just adding a series and trying to go from there.

            Based on your edit it sounds like you are making some progress, so if that starts to head a good direction I could suggest to continue working from that point as well, the main concern here will be debugging the existing logic to make sure it still works as you would expect it to.



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

            Comment


              #7
              Originally posted by neoikon View Post
              For simplicity sake, say I want to add a DataSeries to the built in @ZigZag (I understand not modifying the "@" indicators, but just for this example).

              If I add a AddDataSeries() to the ZigZag, it breaks.

              Perhaps it's due to needing to be more explicit as to which dataseries with calls to ChartBars.FromIndex, IsValidDataPointAt(), Bars.Count, etc?

              Would ChartBars.FromIndex not be an issue?

              What about calling, Bars.GetClose(barIndex)? Am I guaranteed this will be the primary dataseries? (I'm thinking I need to use BarsArray[0].GetClose(barIndex) intead, correct?)

              EDIT: After some playing around and creating a global variable for CurrentBar and making sure I use BarsArray (instead of just Bars), things seem to be looking pretty promising!
              Hello neoikon,
              I would be grateful if you could explain in detail how you resolved this issue, or post an example of the code, as I am having a similar issue when using OnRender with a secondary data series.

              Thank you.

              Comment


                #8
                Hello, just to follow up on this i wonder Jesse what is the more definitive response on the questions asked :

                Would ChartBars.FromIndex not be an issue?

                What about calling, Bars.GetClose(barIndex)? Am I guaranteed this will be the primary dataseries? (I'm thinking I need to use BarsArray[0].GetClose(barIndex) intead, correct?)


                According to the N8 help guide on ChartBars and Bars .... they refer to the Primary Bar series - so for onRender within the loop FromIndex ToIndex - these would only be referring to the Primary Series.

                It is possible that in other sections of OnRender one may wish to draw based upon the secondary series and as such would need to access a stored variable value of the BarsInProgress from OnBarUpdate.

                I ask this for clarity and confirmation as i have also worked on some of this in the scope of onRender.

                thanks

                Comment


                  #9
                  JUST WANT TO CONFIRM, IN CASE YOU DIDNT GET IT
                  YOU NEED TO USE BarsArray[0].GetClose(Index_0); TO ACCESS
                  THE BAG
                  TALLYHO

                  Comment


                    #10
                    NinjaTrader_Jesse I have employed youre solution utilizing BIP;
                    However,
                    The chart now seems to flash instead of updating instataneously, any way around this.
                    I did the same thing as him, just added addDataseris() To ZIG ZAG and adjusted Bars -> BarsArray[0] and used your BIP solution

                    Chart flash = Not Awesome
                    NinjaTrader_Jesse = The Most Awesome
                    Thanks,
                    Michael​

                    Comment


                      #11
                      Hello Entwaze,

                      If you made something that uses OnRender and are having a problem I would suggest to open a new thread and provide a sample of the code you made so that we can see what is being done. With the given details I am not certain what would make the chart flash.

                      You would otherwise need to comment out the code you made and try the script to find what part of the code is causing the flash, once that is known it would be easier to track down the problem.
                      JesseNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Waxavi, Today, 02:10 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post Waxavi
                      by Waxavi
                       
                      Started by TradeForge, Today, 02:09 AM
                      0 responses
                      11 views
                      0 likes
                      Last Post TradeForge  
                      Started by Waxavi, Today, 02:00 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post Waxavi
                      by Waxavi
                       
                      Started by elirion, Today, 01:36 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post elirion
                      by elirion
                       
                      Started by gentlebenthebear, Today, 01:30 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post gentlebenthebear  
                      Working...
                      X