• 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

BarsInProgress not updating

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

    BarsInProgress not updating

    I just finished a MTF indicator. Everything works great...unless I try to do anything with BarsInPogress==0. What happens is...when the indicator is applied to the chart, BarsInProgress takes a very long time before it registers 0.

    Code:
    if( (charttype=="Current" && BarsInProgress==0) || (charttype!="Current" && BarsInProgress==1) )
    I have watched a print statement in the output window to see what BarsInProgress was. The value stays at 1 for extended periods of time, instead of alternating as expected (the instrument does not change...i.e. EURUSD base chart is 5min, HTF can be 240min. So, the data coming in is from the a single instrument.

    The ONLY thing I have been able to do to break the BarsInProgress==1 cycle is to switch the period to something else, and then switch back. Once that happens, the problem goes away and BarsInProgress starts alternating between 0 and 1 as expected.

    I am having this exact same problem in NT8 also.

    Is there a reason why this would happen?

    #2
    Hello,

    Thank you for the post.

    Without more details of the overall logic in OnBarUpdate it would be difficult to say what is happening based on the description. Have you at this point tried commenting out all of your logic, and using a simple print from OnBarUpdate to check that the OnBarUpdate is being called correctly with the series added?

    I would suggest trying your print that you have shown without the charttype variable, or condition and just the BarsInProgress. You could place this as the first line in OBU. It would be important to comment your OBU logic out during this test in case that is changing the result.

    Based on your description, it sounds like this could either be that OnBarUpdate is actually not being called correctly, or that something in the script may be holding the logic and preventing it from reaching the BarsInProgress 0 like it should be.

    If you have a sample you can provide with a test situation, I could take a look at the result to see if I can note anything, but really the suggestion above should be able to paint a better picture of whats happening.

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

    Comment


      #3
      Here is the necessary code in OnBarUpdate():

      Code:
      if (CurrentBars[0] < Count-1 || CurrentBars[1] < Count-1) {return;}
                  
                  if(Count < 50)
                  {
                      Print("Chart has less than 50 bars  --  Will retry on next tick");
                      return;
                  }
                 
                  if(Open.Count < Count - 1) { Print("Data array not initialized"); return; }
      
      Print("charttype: "+cahrttype.ToString()+"   BarsInProgress: "+BarsInProgress.ToString());
      
      if( (charttype=="Current" && BarsInProgress==0) || (charttype!="Current" && BarsInProgress==1) )
                  {
                       //do stuff
                  }
      When the input [charttype] is set to ["Current"], and the indicator is applied to the chart, the output window repeatedly displays the following:
      charttype: "Current" BarsInProgress: 1
      charttype: "Current" BarsInProgress: 1
      charttype: "Current" BarsInProgress: 1
      charttype: "Current" BarsInProgress: 1
      charttype: "Current" BarsInProgress: 1
      charttype: "Current" BarsInProgress: 1
      charttype: "Current" BarsInProgress: 1
      charttype: "Current" BarsInProgress: 1
      It never displays BarsInProgress equal to 0. If I switch timeframes, then it displays the following:
      charttype: "Current" BarsInProgress: 0
      charttype: "Current" BarsInProgress: 1
      charttype: "Current" BarsInProgress: 0
      charttype: "Current" BarsInProgress: 1
      charttype: "Current" BarsInProgress: 0
      charttype: "Current" BarsInProgress: 1
      charttype: "Current" BarsInProgress: 0
      charttype: "Current" BarsInProgress: 1
      I was expecting BarsInProgress to be displaying 0 at some point without needing to switch chart periods after applying the indicator.

      Comment


        #4
        Hello,

        Thank you for the reply.

        It seems like you have found the problem, or that your variable is controlling how OnBarUpdate is executing. From what you have provided I don't see what specifically that may be changing but if you have determined that this variable changes the outcome, this is a good place for you to start debugging the script.

        As noted, checking if the script is working by printing from OnBarUpdate with no condition will let you know the platform is working right. Now that you know this, you can review the logic you created to see why that is happening. Likely some check of this property is preventing BIP 0 from reaching your print, so I would suggest looking at all logic before that print that uses this variable. Very likely you would need to add more prints and output the value of the cahrttype and trace how this is being used in your logic.


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

        Comment


          #5
          But...that is my point. I followed the recommended procedures and the glitch is happening. You can see the code. Anything that would impede the BIP=0 would happen right there. Additionally, if there was something in my code that was causing the problem...why does the problem vanish completely if I switch timeframes or instruments? All that does is effectively re-apply the indicator to another chart. If it was something in my code, it should do the same thing after the timeframe or instrument had been changed.

          Here is the code for the user inputs related to this issue:

          Code:
          private string charttype = "Current";
                      private PeriodType chty = PeriodType.Minute;
                      [Description("Chart Type")]
                      [GridCategory("VS-One")]
                      [Gui.Design.DisplayName("01 Chart Type")]
                      [TypeConverter(typeof(TyoChart))]
                      public string ChartTy{
                          get { return charttype; }
                          set {
                              charttype = value; 
                              switch (charttype){
                                  case "Current":    chty = PeriodType.Minute;     break;
                                  case "Tick":       chty = PeriodType.Tick;        break;
                                  case "Volume":  chty = PeriodType.Volume;     break;
                                  case "Range":     chty = PeriodType.Range;     break;
                                  case "Second":     chty = PeriodType.Second;     break;
                                  case "Minute":     chty = PeriodType.Minute;     break;
                                  case "Day" :    chty = PeriodType.Day;         break;
                                  case "Week":     chty = PeriodType.Week;     break;
                                  case "Month":     chty = PeriodType.Month;     break;
                                  case "Year":     chty = PeriodType.Year;     break;
                                  case "Renko":     chty = PeriodType.Renko;     break;
                              }
                          }
                      }
                      
                      private int usePeriod = 240;
                      [Description("Period")]
                      [GridCategory("VS-One")]
                      [Gui.Design.DisplayName("02 Period")]
                      public int UPeriod{
                          get { return usePeriod; }
                          set { usePeriod = Math.Max(1, value); }
                      }
          
          internal class TyoChart : StringConverter
                      {
                          public override bool GetStandardValuesSupported(ITypeDescriptorContext itdc) {return true;}
                          public override bool GetStandardValuesExclusive(ITypeDescriptorContext itdc) {return true;}
                          public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext itdc)
                          {
                              return(new StandardValuesCollection(new String[] {"Current","Tick","Volume","Range","Second","Minute","Day","Week","Month","Year","Renko"}));
                          }
                      }
          And this is the code that adds the alternate bar series in Initialize():
          Code:
          Add(chty,usePeriod);
          There is nothing else to it. Basically, if a user leaves the defaults in place...the indicator adds a default minute based chart to keep from having an error in the Add(). And in OnBarUpdate(), the charttype variable being still set to "Current" makes sure the if statement flags true when BIP=0. But...BIP never equals 0 unless I change the timeframe or instrument. I have watched the log for several minutes just to see. And...this problem did not exist before the code I have posted here was added. Do I need to specifically add the base chart? The support docs don't say it needs to be done. Do you see anything that could possibly be causing this problem?

          Comment


            #6
            Hello,

            Thank you for the additional details.

            Yes, in this case, I would expect this outcome based on the use of dynamically adding series from a user property. This is not something that was specifically documented to avoid in nt7 but we do recommend to avoid this. Although you can form the syntax to be this way, it will produce problems in various areas of use. We specifically say to not do this going forward in the NT8 help guide as it is known to cause problems.

            The solution should be to add all series that would potentially be used, and then control the logic from OnBarUpdate with your user input. Depending on the user input, that would determine the BIP to use. It would no longer be BIP 0-1, but 0- the amount of series added that would ever possibly be used.

            The alternative would be to ensure to set the properties before applying it. For example, in a new chart open the indicator window, select the indicator and press new, configure it and press OK not apply. If you now need to change the indicators settings, open the indicator panel and remove the indicator, click apply, and repeat the adding process again. an F5 refresh will never work while using a dynamic series like this as well as editing and reapplying the same instance.


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

            Comment


              #7
              I was afraid of that. Adding all the series that could be potentially used is not reasonable. At a base I would need to add several dataseries for each different chart type. I would end up with a minimum of about 30 dataseries, which would just waste a lot of RAM unnecessarily.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by superkolleech, Today, 12:46 AM
              1 response
              10 views
              0 likes
              Last Post MojoJojo  
              Started by davidwade, Today, 02:51 AM
              0 responses
              2 views
              0 likes
              Last Post davidwade  
              Started by aviat72, 04-26-2020, 09:41 PM
              10 responses
              90 views
              0 likes
              Last Post kissandfly  
              Started by healthooa, Today, 01:28 AM
              0 responses
              7 views
              0 likes
              Last Post healthooa  
              Started by harjinderjit, Yesterday, 08:24 PM
              0 responses
              20 views
              0 likes
              Last Post harjinderjit  
              Working...
              X