Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

i want real time each and evary value how many time repeated

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

    i want real time each and evary value how many time repeated

    if you don't any help me.i am beginner in ninjascript . planned to real time each and evary value how many time repeated using if ,else if funcation

    ex.
    09.54.02 close price is 18761
    18761 already in list automatically add to value and number of time repeated +1
    values number of time repeated
    18760 13
    18765 11
    18762 33
    18761 33
    18769 35
    18771 45
    18763 1
    09.54.03 close price is 18760
    18760 already in list automatically add to value and number of time repeated +1
    values number of time repeated
    18760 13
    18765 12
    18762 33
    18761 33
    18769 35
    18771 45
    18763 1
    09.54.04 close price is 18778
    18778 no already in list automatically add to value and number of time repeated 1
    values number of time repeated
    18760 13
    18765 12
    18762 33
    18761 33
    18769 35
    18771 45
    18763 1
    18778 1
    ​---------------------------------------------------------------------------------------------

    using System.Collections.Generic;
    using System.Windows.Media;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.NinjaScript.DrawingTools;
    using GuiTools = NinjaTrader.Gui.Tools;

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class PriceLevelCounter : Indicator
    {
    private Dictionary<double, int> tickCounts;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Price Level Counter";
    Name = "PriceLevelCounter";
    IsOverlay = false;
    DisplayInDataBox = true;
    Calculate = Calculate.OnPriceChange;
    }
    else if (State == State.DataLoaded)
    {
    tickCounts = new Dictionary<double, int>();
    }
    }

    protected override void OnBarUpdate()
    {
    if (tickCounts.ContainsKey(Close[0]))
    {
    tickCounts[Close[0]]++;
    }
    else
    {
    tickCounts.Add(Close[0], 1);
    }
    }

    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    int count = 0;
    foreach (var kvp in tickCounts)
    {
    double priceLevel = kvp.Key;
    count++;

    string text = string.Format("{0}: {1}", priceLevel, kvp.Value);
    Draw.TextFixed(this, "Count" + count, text, TextPosition.BottomRight, Brushes.White, new GuiTools.SimpleFont("Arial", 150), Brushes.Transparent, Brushes.Transparent, 0);
    }
    }
    }
    }

    ---------------------------------------------------------------------------------------------------------------

    but i output in overlaping . pls any reprogramming this

    Click image for larger version

Name:	Screenshot (22).png
Views:	129
Size:	167.2 KB
ID:	1257496
    Attached Files

    #2
    Aren't you wanting to overwrite the previous value on
    the lower right?

    This line,

    Draw.TextFixed(this, "Count" + count, text, TextPosition.BottomRight, Brushes.White,
    new GuiTools.SimpleFont("Arial", 150), Brushes.Transparent, Brushes.Transparent, 0);


    does not do that.

    Try replacing "Count" + count with just "Count",
    so that the same string is used every time.

    Comment


      #3
      Also, and this is sort of the less important point than it being illegible, but the more of those objects you pile up the slower the chart gets.
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Hello alagu,

        Thanks for your post.

        To clarify, are you wanting to update the text on the chart with the current text value you want to draw?

        If so, you would need to use the same tag name when calling Draw.TextFixed() so that the draw object is updated when it is called again instead of drawing a new drawing object, as bltdavid mentioned.

        "Count" would need to be used in your Draw.TextFixed() method instead of "Count" + Count.

        From the Draw.TextFixed() help guide: "if you pass in a value of "myTag", each time this tag is used, the same draw object is modified. If unique tags are used each time, a new draw object will be created each time."

        See this help guide page for more information about Draw.TextFixed(): https://ninjatrader.com/support/help..._textfixed.htm
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          overlapping issue solve but it shows only one price level repeated count i want each and evary price level repeated count

          Click image for larger version

Name:	Screenshot (23).png
Views:	122
Size:	179.6 KB
ID:	1257556

          i want to this output

          ex.
          18760 13
          18765 11
          18762 33
          18761 33
          18769 35
          18771 45
          18763 1

          Comment


            #6
            Hello alagu,

            Thanks for your notes.

            If you use Draw.TextFixed() and try to draw multiple text draw objects at the same location, the draw objects will overlap since they are all being drawn at the same location on the lower right corner of the chart window.

            Only 1 draw object could be drawn in a single location by using the same tag name when using Draw.TextFixed() as seen in the screenshot you shared, otherwise, drawing multiple drawings at the same location will cause the drawings to overlap in the lower right corner.

            ​You could consider using the Draw.Text() method and using unique tag names if you want to draw multiple draw objects on the chart window without them overlapping.

            Or, you could consider using SharpDX in OnRender() to custom render text objects on the chart at different locations.

            Draw.Text(): https://ninjatrader.com/support/help.../draw_text.htm

            Using SharpDX for Custom Chart Rendering: https://ninjatrader.com/support/help..._rendering.htm
            OnRender(): https://ninjatrader.com/support/help...htsub=onrender

            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            577 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X