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

Problems with Counting…

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

    Problems with Counting…

    Hi everyone

    First, to state that I’m using Renko bars.

    I’ve got an indicator which detects pivots if the pivot is the highest for the surrounding n bars. That works fine and I can draw a diamond over the pivots.

    What I want to achieve is each time a pivot is detected, to place the CurrentBar number into a data series.

    This is the essentials of the code:


    Code:
    Variables
    
    private int Counter = 1;
    private int pivotRadius = 4;
                
    private DataSeries PivotSeries;
    
    Initialize
    
    PivotSeries = new DataSeries(this);
    
    OnBarUpdate
            {
                ...
                
                if(
                    HighestBar(High, PivotRadius * 2) == PivotRadius
                    && High[PivotRadius] >= High[PivotRadius * 2]
                    )
                
                {
                    PivotSeries[Counter] = CurrentBar;
                    Counter++;
                    DrawDiamond("Diamond" + CurrentBar, true, PivotRadius, High[PivotRadius] + 2 * TickSize, Color.Brown);
                }
    
                if( CurrentBar >= Count - 2 )
    
                {
                        for (int i = 1; i <= 10; i++)
                    {
                        Print( PivotSeries[i] );
                    }
                }
    I'm not seeing correct results for the data series in the Output Window, and I guess this must be down to something wrong with the counting method.

    Any help with this would be much appreciated.

    #2
    Hi arbuthnot,

    A data series syncronizes to the primary series. There are likely a lot of blank elements in this data series.

    It may help if you use a List instead of a custom data series.

    Below is a publicly available link to info on lists.
    http://www.dotnetperls.com/list
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks very much, Chelsea, for your help.

      You're of course quite right about the data series. As you say, it locks in to the primary series.

      Thanks for the link about Lists in C#. I can imagine it would take about ten years of experimentation before I get that right!

      I've just thought of another approach using the MRO method with data series and that may preclude this problem.

      If this works, I'll post back to this thread.

      Comment


        #4
        Hi again Chelsea

        My idea about using the MRO method has worked a treat! Please see the new code below:

        Code:
        if (CurrentBar < Count - 2)
                        return;
                    
                    for (int i = 1; i <= LookBack; i++)
                    
                {
                    PivotSeries[i] = MRO(delegate {return
                    
                        HighestBar(High, PivotRadius * 2) == PivotRadius
                        && High[PivotRadius] >= High[PivotRadius * 2]
                        
                    ;}, i, 250) + PivotRadius;
                }    
        
                    for (int j = 1; j <= 10; j++)
                            {
                                Print( PivotSeries[j] );
                                DrawDiamond("Diamond" + CurrentBar, true, (int) PivotSeries[j], High[ (int) PivotSeries[j]], Color.Brown);
                            }
        I'd forgotten how powerful MRO really is and there's no problem about synchronizing with the primary series.

        Although I'm printing the right numbers, the only problem now is one I had right before: in the second loop, I'm trying to draw a diamond on each pivot, but now only the last diamond (I think) is drawn.

        Could you kindly point out where I've gone wrong?

        Thanks again.

        Comment


          #5
          Hi arbuthnot,

          As you loop through for (int j = 1; j <= 10; j++), the CurrentBar value will not change as this will reflect the current bar that is processing.

          This means that the tag used will be the same everytime DrawDiamond is called, which causes the diamond to be overwritten instead of added.

          If you are wanting to draw a diamond using j as a bars ago value use:

          DrawDiamond("Diamond" + (CurrentBar-j), true, PivotSeries[j], High[ (int) PivotSeries[j]], Color.Brown);
          DrawDiamond(string tag, bool autoScale, int barsAgo, double y, Color color)

          I'm going to make an assumption that PivotSeries[j] holds a current bar value. I think you may be wanting CurrentBar-PivotSeries[j].

          Also, is PivotSeries a List<int> or a List<double>?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thanks again, Chelsea - and as always - for your prompt and highly detailed reply!

            Actually, I'd just worked out (in fact, remembered) another way of doing this:

            Code:
            DrawDiamond([B]j.ToString() [/B]+ CurrentBar, ...
            But I didn't know about your approach, which I'll make a careful note of.

            To answer your question, Chelsea, I didn't use the 'List' concept at all, defining PivotSeries (which does hold a current bar value) conventionally:

            Code:
            private DataSeries PivotSeries;
            
            PivotSeries = new DataSeries(this);
            
            for (int i = 1; i <= LookBack; i++)
                        
                    {
                        PivotSeries[i] = MRO...
            Anyway, whether by accident or design, the numbers I'm printing out are precisely the distances from the right of the chart to each pivot and the dots are drawn over the pivots confirming this anyway.

            Much obliged to you for looking at these problems and for your suggestions.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            3 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            6 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Working...
            X