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

Indicator sometimes disappearing

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

    Indicator sometimes disappearing

    Hi everyone

    I’ve got an indicator (of my own devising) that works fine – except for a strange problem I can’t solve.

    In Variables, I declare the following:

    Code:
    private int len = 8;
    private int period = 6;
                                          
    private int zHighCounter = 0;
    private int zLowCounter = 0;
    Then, in OnBarUpdate, there’s this code:

    Code:
    if(conditions)
                                                                              
      {ZHighCounter = 0;}
                                                            
      else
                                                                              
      ZHighCounter++;
    “ZHighCounter++” does the job great.

    The problem arises when I reset a parameter, say, in Indicators. Obviously, ZHighCounter and ZLowCounter will show the number of instances counted. But if either of them shows a count greater than either ‘Len’ or ‘Period’ (the two ‘conventional’ variables) then the indicator won’t appear and remains ‘invisible’ until I manually reset the figures against ZHighCounter and ZLowCounter to zero, or at least, figures lower than the variables.

    I’d be very grateful to hear about some code that I can insert that could solve this problem.

    I hope I’ve explained the situation clearly.

    Much obliged in advance.

    #2
    Hello arbuthnot,

    With the code snippet that you sent it is hard to tell what would be causing this. Are you using those variables for modify the plot?

    Or could you post a toy version of your Indicator replicating the issue so that we may look into this further?
    Last edited by NinjaTrader_JC; 08-27-2013, 01:00 PM.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thanks very much, JC, for getting back to me on this.

      I'll try to devise a (working!) toy version and hope to post it in the next few days.

      Comment


        #4
        Hi again JC

        I've now had an opportunity, following your suggestion, to code up a toy indicator that replicates the same problem as in my original one.

        Below is the full code.

        I'm also attaching an image showing an 'indicator-less' chart with a box showing the counters from the Indicator Box.

        The chart is USDCHF 10 range. There's more chance of seeing this happening on a range bar chart where the instrument is currently trending strongly.

        The problem is that after going into the Indicator Box, unless the Counters are reset to zero (or, at least, values lower than the WMA parameters) the indicator disappears.

        I'd be very grateful for any suggestions as to how to correct this problem.

        Thanks very much in advance.

        Code:
        public class StepsToyIndicator01 : Indicator
            {
                #region Variables
        
                    private int zHighCounter = 0;
                    private int zLowCounter = 0;
        
                #endregion
        
        
                protected override void Initialize()
                {
                    Add(new Plot(new Pen(Color.Green, 3), PlotStyle.Line, "HighLine"));
                    Add(new Plot(new Pen(Color.Brown, 3), PlotStyle.Line, "LowLine"));
                    Add(new Plot(new Pen(Color.DarkViolet, 3), PlotStyle.Line, "MidLine"));
                    Overlay    = true;
                }
        
        
                
                protected override void OnBarUpdate()
                {
        
        
                    
            if (CurrentBar < 20)
                        return;
            
                    
                    if(WMA(8)[0] > WMA(16)[0])
                        
                    {ZLowCounter = 0;}
                    
                    else
                        
                    ZLowCounter++;
                    
        //-------------------------------------------------------
                    
                    
                    if(WMA(8)[0] < WMA(16)[0])
                        
                    {ZHighCounter = 0;}
                    
                    else
                        
                    ZHighCounter++;
                    
                    
                    HighLine.Set(High[ZHighCounter]);
                    LowLine.Set(Low[ZLowCounter]);
                    MidLine.Set( (High[ZHighCounter] + Low[ZLowCounter]) / 2 );
                    
                }
        
                #region Properties
                
                [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                public DataSeries HighLine
                {
                    get { return Values[0]; }
                }
        
                [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                public DataSeries LowLine
                {
                    get { return Values[1]; }
                }
                
                [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                public DataSeries MidLine
                {
                    get { return Values[2]; }
                }
                
                [Description("")]
                [GridCategory("Parameters")]
                public int ZHighCounter
                {
                    get { return zHighCounter; }
                    set { zHighCounter = Math.Max(0, value); }
                }
        
                [Description("")]
                [GridCategory("Parameters")]
                public int ZLowCounter
                {
                    get { return zLowCounter; }
                    set { zLowCounter = Math.Max(0, value); }
                }
                
                #endregion
        Attached Files

        Comment


          #5
          Hello arbuthnot,

          Thanks for the sample.

          Running your indicator I do not have any problems unless I change the CalculateOnBarClose or (COBC) false. Then I get the following message inside of the Log tab of the Control Center.

          Error on calling 'OnBarUpdate' method for indicator 'StepsToyIndicator01' on bar 20: 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.

          This is going to be due to trying to access data that does not exist. Looking at how your code is setup, you may want to keep CalculateOnBarClose (COBC) set to true, so something like this will not happen, otherwise you may want to add a check like the "if (CurrentBar < 20)" to see if the ZLowCounter or ZHighCounter is going to be greater than the amount of bars that are loaded (CurrentBar).

          Happy to be of further assistance.
          JCNinjaTrader Customer Service

          Comment


            #6
            Thanks very much, JC.

            I always keep CalculateOnBarClose = true as I don't think my PC could handle COBC = false.

            The problem occurs much less frequently in this toy indicator (in which I pared down the coding as much as possible) than in my original, which is a lot more elaborate. In my original version, the indicator disappears more often than not if anything is changed in 'Indicators'.

            I now realise that my NT7 is having some technical issues (such as the Output window not being visible) and conceivably the problems are related, though I doubt it. I'm addressing these in another thread now.

            When these other problems are sorted out and I can make headway with this problem, I'll report back to this thread.

            Comment


              #7
              Hello arbuthnot,

              If you are not able to see the Output Window, you may want to try to uninstall and reinstall NinjaTrader to make sure all the files have been updated properly.
              JCNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by traderqz, Today, 12:06 AM
              10 responses
              18 views
              0 likes
              Last Post traderqz  
              Started by algospoke, 04-17-2024, 06:40 PM
              5 responses
              46 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by arvidvanstaey, Today, 02:19 PM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Zachary  
              Started by mmckinnm, Today, 01:34 PM
              3 responses
              5 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by f.saeidi, Today, 01:32 PM
              2 responses
              9 views
              0 likes
              Last Post f.saeidi  
              Working...
              X