Announcement

Collapse
No announcement yet.

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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        75 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        152 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        162 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        101 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        289 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X