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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        81 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        42 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        64 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        66 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        54 views
        0 likes
        Last Post CarlTrading  
        Working...
        X