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" , text, TextPosition.BottomRight, Brushes.White, new GuiTools.SimpleFont("Arial", 150), Brushes.Transparent, Brushes.Transparent, 0);
    }
    }
    }
    }

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

    but it output shows only one price repeated count. i want each price repeated count

    Click image for larger version

Name:	Screenshot (23).png
Views:	150
Size:	179.6 KB
ID:	1257575


    i want like this output
    18760 13
    18765 11
    18762 33
    18761 33
    18769 35
    18771 45
    18763 1



    #2
    You need an aggregate string that contains
    all string values you want to print -- you pass
    this one string to one call to Draw.TextFixed,
    and you'll see all lines in the string printed to
    the chart.

    How do you do this?
    Easy, use the newline '\n' character to separate
    each line.

    Inside your foreach loop inside OnRender.
    append each line to the aggregate string.
    the trick is, append a newline character '\n'
    after each string.

    Code:
    string aggrString = null;
    foreach (var kvp in TickCounts)
        aggrString += string.Format("{0} {1}\n", kvp.Key, kvp.Value);
    
    Draw.TextFixed(this, "Count", aggrString ....
    See that '\n' character in string.Format?

    That's the critical piece.

    Comment


      #3
      Hello alagu,

      Thanks for your notes.

      I see you have already created a forum thread regarding this inquiry and the link to the already-created thread is below. Please see the reply posted on the thread below.

      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


      That said, bltdavid has provided a good approach to how you could go about accomplishing this if you want to use the Draw.TextFixed() method.

      You could find an example script demonstrating the use of \n with Draw.TextFixed() on this forum thread: https://forum.ninjatrader.com/forum/...403#post838403
      <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
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 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
      548 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      549 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X