Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Price levels with concentrated Ticks

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

    Price levels with concentrated Ticks

    I am trying to developt an indicator which marks price level with high concentrated tick by calculating the average tick activity over the past LookBack bars and compares it to tick activity within the most recent 30 Seconds window.
    If tick activity at a price exceeds the Threshold (double) , it is for marking.

    In other word, indicator motitors tick velocity and marks price level which doubled the tick size,

    Logically, below code should work, but I am facing the code overly takes time, marking oldest bars only. And not marking correctly.

    I am not not sure whether my approach is correct... Any advise or suggestion for correction?

    .

    Code:
    AddPlot(new Stroke(Brushes.Yellow, 2), PlotStyle.Hash, "DPOC_Line");
    
    
    protected override void OnMarketData(MarketDataEventArgs e)
    {
    if (Bars.Count < LookBack)
    return;
    
    if (e.MarketDataType == MarketDataType.Last && e.Price != 0)
    {
    double price = e.Price;
    DateTime currentTime = DateTime.Now;
    
    if ((currentTime - lastResetTime).TotalSeconds >= NumberOfSeconds)
    {
    lastResetTime = currentTime;
    
    if (tickHistory.Count >= LookBack)
    tickHistory.Dequeue();
    
    int totalTickCount = tickVelocityMap.Values.Sum();
    tickHistory.Enqueue(Math.Max(totalTickCount, 1)); // Prevent zero values
    
    
    if (totalTickCount > Threshold)
    Print(" Tick History Updated -> New Count: " + tickHistory.Count);
    }
    
    if (!tickVelocityMap.ContainsKey(price))
    {
    tickVelocityMap[price] = 1;
    }
    else if (tickVelocityMap[price] < Threshold * 2) limit unnecessary growth
    {
    tickVelocityMap[price]++;
    }
    
    
    if (tickVelocityMap[price] % 50 == 0)
    Print(" Tick Recorded at Price: " + price + " | Current Tick Count: " + tickVelocityMap[price]);
    }
    }
    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < LookBack)
    return;
    
    markedPriceLevels.Clear(); // Reset markers for current bar
    
    
    double avgTickSpeed = Math.Max(tickHistory.Average() / (LookBack * 2), 1);
    double calculatedThreshold = avgTickSpeed * (Threshold / 10);
    
    
    if (Math.Abs(calculatedThreshold - avgTickSpeed) > 5)
    {
    Print(" Debug: avgTickSpeed Calculation -> " + avgTickSpeed);
    Print(" Debug: Adjusted Threshold Value -> " + calculatedThreshold);
    }
    
    foreach (var kvp in tickVelocityMap)
    {
    if (kvp.Value > calculatedThreshold)
    {
    markedPriceLevels.Add(kvp.Key);
    Print(" Marked Price: " + kvp.Key + " | Tick Speed: " + kvp.Value + " (Threshold: " + calculatedThreshold + ")");
    }
    }
    
    
    if (markedPriceLevels.Count > 0)
    {
    foreach (double price in markedPriceLevels)
    {
    Draw.Text(this, "Marker_" + CurrentBars[0] + "_" + price, "✦", 0, price, Brushes.Yellow);
    }
    }
    }
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> DPOC_Line
    {
    get { return Values[0]; }
    }​
    Jan​
    Last edited by Janet8; 05-08-2025, 07:44 PM.

    #2
    Hello Janet8,

    Thank you for your post.

    Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients.

    I notice the code you've provided uses Dequeue and Enqueue methods, which are part of C#, but are not specific to NinjaTrader. The NinjaScript Support department does not provide C# programming education services, so we wouldn't be able to assist with the use of these methods.

    We are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior

    When working with any issue, it is important to take steps to isolate the issue so that the exact line causing the behavior can be found.
    This is a process of elimination and a process of debugging by adding prints.

    First, its great to create a copy of the script so that the original work is kept safe.
    Below is a link to a video that demonstrates making a copy of script.


    Once the copy is created, the copy can be modified in any way without losing the original work.

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

    The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.
    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    The next step is to start commenting out code.
    Its helpful to think about when the error is occurring to target areas, and comment code from everywhere else quickly.

    If at any point after removing some code, the error stops, add the last removed item back.

    If the error is occurring while the script is loading, the issue is likely somewhere in OnStateChange(). In this situation its best to remove any logic in OnBarUpdate, remove any custom methods and classes, and remove as may properties as possible, while still being able to reproduce the error.

    Other members of the forum may be able to offer advice, and you can also contact a professional NinjaScript Consultant who would be eager to modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services.

    Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    547 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    323 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    99 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    543 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    545 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X