Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

price and repeated count overlap

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

    price and repeated count overlap

    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", 8), Brushes.Transparent, Brushes.Transparent, 0);
    }
    }
    }
    }
    ​-------------------------------------------------------------------------------------

    i am plan to design my indicator is each price level how many time LTP repeated and repeated count

    Click image for larger version

Name:	Screenshot (22).png
Views:	163
Size:	167.2 KB
ID:	1257112
    but price and repeated count overlap . (for your clear view i put in 300px).pls how to solve this overlap

    i want this type of output in my chart

    5040 304
    5041 234
    5043 221
    5044 231
    5045 199
    ....... .....
    ....... .....
    ​​​​​​​....... .....
    ​​​​​​​....... .....
    ​​​​​​​....... .....

    #2
    Hello alagu,

    Its not recommended to call Drawing objects in OnRender(). You should only be rendering with SharpDX (using RenderTarget.DrawText()) in OnRender().


    Call drawing objects like Draw.TextFixed() from OnBarUpdate().

    In your for loop, instead of making separate strings, concatenate new lines to an existing string using \r\n to make new lines.

    Code:
    string myString = string.Empty;
    
    for (int i = 0; i < 2; i++)
    {
    myString += "\r\nNew Line " + i.ToString();
    }
    
    // myString now has 3 lines
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 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
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X