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:	168
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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    58 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    80 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    43 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    101 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    61 views
    0 likes
    Last Post PaulMohn  
    Working...
    X