Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Determine input plot from FormatPriceMarker()

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

    Determine input plot from FormatPriceMarker()

    I have an indicator that has multiple plots and each may need to be formatted slightly differently for Market Analyzer display. For example, one may be a price and one may simply be a count, or a code to trigger a Market Analyzer condition.

    Is there a way to determine which plot is being run through FormatPriceMarker() at any given time? I was hoping the "InputPlot" would help give a selected plot index, but that seems to be always "0".

    In my case, I'm using the indicator within Market Analyzer. So, for a given column, there is a selected indicator and selected Plot for that indicator. Perhaps this is exposed somewhere?

    For now, my hack is to compare the current plot value to the value passed into FormatPriceMarker() and see if they are the same. If two plots are the same at any point, then this would not work, obviously.

    PHP Code:
    if (myPlot1.GetValueAt(CurrentBar) == value) ... 
    
    Thank you!

    #2
    Hello neoikon,

    Thanks for the post.

    I just inquired with our product management team if this is possible in any way. It doesn't seem like it is possible because we're only given a double value to work within FormatPriceMarker(). I will follow up on this thread when I have an answer from product management.

    Edit:
    There is no supported way to do per plot formatting. I will add a feature request for this item.

    Thanks in advance for your patience.
    Last edited by NinjaTrader_ChrisL; 07-19-2018, 02:01 PM.

    Comment


      #3
      Thank you for the reply. If nothing else, I was hoping there was a way to access the column's properties object to determine the context that it's is running under (the Indicator is selected and a particular plot is selected).

      Comment


        #4
        This is an old post. Having an updated FormatPriceMarkers() that was passed in the bar (could differ from CurrentBar in scrollback), and PlotIndex would be really nice to be able to do more with this. I didn't notice FormatPriceMarkers() was even available until recently, I have my own AddPlotLabels indicator that loops through all Indicators on a chart and adds a right hand margin with the Plot Labels. That's nice because each Indicator doesn't need to be modified to support it. But it's nice in some cases to append this to the ChartLabel perhaps. The below snippets that can be added to your chosen Indicators does just that with the caveats that it has to guess on the plot, the cache helps it pick the "First one" in AddPlot order if there was overlaps and does not have awareness when the chart is being scrolled in history..

        Just sharing in case anyone else finds this useful.

        Code:
               #region PriceMarkers
                // To use PriceMarkers, add a RefreshPidCache() into your OnBarUpdate()
                //
                //protected override void OnBarUpdate() {
                //    try {
                //        RefreshPidCache();
                //    } catch { }
                //}
        
                private Dictionary<double, int> pidMarkerCache = new Dictionary<double, int>();
                private void RefreshPidCache(int barAgo = 0) {
                    if (State != State.Realtime)
                        return;
        
                    Dictionary<int, double> old = new Dictionary<int, double>();
                    foreach (var kv in pidMarkerCache)
                        old[kv.Value] = kv.Key;
        
                    for (int pid = 0; pid < Plots.Count(); pid++) {
                        double val = Values[pid][barAgo];
                        if (Values[pid].IsValidDataPoint(barAgo) && !Double.IsNaN(val)) {
                            double oldval;
                            if (old.TryGetValue(pid, out oldval))
                                pidMarkerCache.Remove(oldval);
        
                            if (!pidMarkerCache.ContainsKey(val) || pidMarkerCache[val] > pid) // Don't override earlier plots.
                                pidMarkerCache[val] = pid;
                        }
                    }
                }
        
                public override string FormatPriceMarker(double price) {
                    // Shows the Plotname instead of the given price.
                    int pid = 0;
        
                    if (pidMarkerCache.TryGetValue(price, out pid)) {
                        return $"{price:N} - {Plots[pid].Name}";
                    }
        
                    int barAgo = 0;
                    for (pid = 0; pid <= Plots.Count(); pid++) {
                        if (pid == Plots.Count())
                            break;
        
                        double val = Values[pid].GetValueAt(CurrentBar - barAgo);
        
                        if (val == price) {
                            return $"{price:N} - {Plots[pid].Name}";
                        }
                    }
        
                    // Databox display when scrolling over older bars, and when not found just return a default.
                    return price.ToString("N");
                }
                #endregion
        ​

        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