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:	165
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 sjsj2732, Yesterday, 04:31 AM
    0 responses
    28 views
    0 likes
    Last Post sjsj2732  
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    284 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    281 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    132 views
    1 like
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    90 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Working...
    X