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

New pivot indicator

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

    New pivot indicator

    I actually want to show the last n days pivots on the current day's intraday chart. The following code is VERY slow and is unusable if I scroll into the past. Is there a way to do this?

    protected override void OnBarUpdate()
    {
    if (Bars.BarsSinceNewTradingDay >= 1)
    {
    Draw.Line(this, "tag1"+CurrentBar, true,0, PP.R3[0], 130, PP.R3[0], Brushes.Red, DashStyleHelper.Dot, 1);
    Draw.Line(this, "tag2"+CurrentBar, true,0, PP.R2[0], 130, PP.R2[0], Brushes.Red, DashStyleHelper.Dot, 1);
    Draw.Line(this, "tag3"+CurrentBar, true,0, PP.R1[0], 130, PP.R1[0], Brushes.Red, DashStyleHelper.Dot, 1);
    Draw.Line(this, "tag4"+CurrentBar, true,0, PP.Pp[0], 130, PP.Pp[0], Brushes.Blue, DashStyleHelper.Dot, 1);
    Draw.Line(this, "tag5"+CurrentBar, true,0, PP.S1[0], 130, PP.S1[0], Brushes.Green, DashStyleHelper.Dot, 1);
    Draw.Line(this, "tag6"+CurrentBar, true,0, PP.S2[0], 130, PP.S2[0], Brushes.Green, DashStyleHelper.Dot, 1);
    Draw.Line(this, "tag7"+CurrentBar, true,0, PP.S3[0], 130, PP.S3[0], Brushes.Green, DashStyleHelper.Dot, 1);

    Draw.Line(this, "tag8"+CurrentBar, true,0, PP.R3[1], 256, PP.R3[1], Brushes.Red, DashStyleHelper.Dot, 1);
    Draw.Line(this, "tag9"+CurrentBar, true,0, PP.R2[1], 256, PP.R2[1], Brushes.Red, DashStyleHelper.Dot, 1);
    Draw.Line(this, "tag10"+CurrentBar, true,0, PP.R1[1], 256, PP.R1[1], Brushes.Red, DashStyleHelper.Dot, 1);
    Draw.Line(this, "tag11"+CurrentBar, true,0, PP.Pp[1], 256, PP.Pp[1], Brushes.Blue, DashStyleHelper.Dot, 1);
    Draw.Line(this, "tag12"+CurrentBar, true,0, PP.S1[1], 256, PP.S1[1], Brushes.Green, DashStyleHelper.Dot, 1);
    Draw.Line(this, "tag13"+CurrentBar, true,0, PP.S2[1], 256, PP.S2[1], Brushes.Green, DashStyleHelper.Dot, 1);
    Draw.Line(this, "tag14"+CurrentBar, true,0, PP.S3[1], 256, PP.S3[1], Brushes.Green, DashStyleHelper.Dot, 1);
    }
    }

    Thanks.

    #2
    Hello chartish,

    The code you have provided would draw 15 lines on every single bar on the chart.

    If there were 100 bars on the chart this would be 1500 drawing objects. Likely there are way more than 100 bars on the chart.

    The amount of objects that must be drawn and kept in memory is extremely large.

    No, there would not be a way to render this extreme amount of objects in a faster way.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes, it certainly is possible to show the pivots for the last N days as long as you keep the value of N within reason. The level lines and labels should all be done in an OnRender loop. The code you posted is not a good approach.


      When you draw a text or line with a tag that is the same as that of an existing text or line, the properties of the previously created object are changed, but no new object is created;

      So, as long as you reuse the tags, your code would NOT be creating new drawing objects on every bar. The tag for each line must not change from bar to bar, so that when a new bar is added, you are just updating existing drawing objects and not adding to the memory load. In other words, DO NOT include the value of CurrentBar as part of the tag.

      The "just one more thing" question would be: Why would you want to do this?
      Last edited by Ricam; 05-10-2017, 02:43 PM.

      Comment


        #4
        Thanks Ricam. I plan on keeping n to about 3 or 4. The reason for doing this is to determine if prior pivots are still good support and resistance lines.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by EB Worx, 04-04-2023, 02:34 AM
        7 responses
        161 views
        0 likes
        Last Post VFI26
        by VFI26
         
        Started by Mizzouman1, Today, 07:35 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Radano, 06-10-2021, 01:40 AM
        20 responses
        616 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by i019945nj, 12-14-2023, 06:41 AM
        6 responses
        68 views
        0 likes
        Last Post i019945nj  
        Started by aa731, Today, 02:54 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X