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:	167
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 cmoran13, Yesterday, 01:02 PM
    0 responses
    23 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    16 views
    0 likes
    Last Post PaulMohn  
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    160 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    94 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    147 views
    2 likes
    Last Post CaptainJack  
    Working...
    X