Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Median Indicator Confusion

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

    Median Indicator Confusion

    So, I created 2 Median Indicators by modifying the stock CurrentDayOHL indicator. The first one (awoMedian) is pretty straightforward and it works just fine. The second one (awoMedianDayWeek) works as it is at the moment, but if you uncomment all the lines I've commented out, it plots nothing. I was trying to use the existing series of Highs and Lows to calculate a median for the past 5 day period. I was hoping to avoid adding a second BarsArray.

    I had to do some gymnastics with the Math.Min and Math.Max since they can only have 2 inputs, but it compiled just fine. Other than that, I can't figure out what I'm missing.

    Anyone have thoughts?
    Attached Files

    #2
    Hello,

    Thank you for the post.

    For this type of item, you would need to look in the New -> NinjaScript Output Window to see what specifically is happening. In this case, you are getting an error:

    Indicator 'AWO Median Day/Week': Error on calling 'OnBarUpdate' method on bar 0: Index was outside the bounds of the array.
    It looks like you have defined 2 plots, but in your properties, you use more than two plots which create an error.

    You set CurrentMedianWeekly[0] in OnBarUpdate which is the incorrect index because the property lists:

    Code:
    public Series<double> CurrentMedianWeekly
    {
       get { return Values[B][3][/B]; }
    }
    You have added two plots, you would need at least 2 more plots added to create enough indexes to reach 3.

    You could either remove unused properties and re adjust the Values index to be correct, or add two more plots and retain the same properties:

    AddPlot(new Stroke(Brushes.SeaGreen, DashStyleHelper.DashDot, 2), PlotStyle.Square, "Median");
    AddPlot(new Stroke(Brushes.SeaGreen, DashStyleHelper.DashDotDot, 2), PlotStyle.Square, "SomePlot");
    AddPlot(new Stroke(Brushes.SeaGreen, DashStyleHelper.DashDotDot, 2), PlotStyle.Square, "SomePlot2");
    AddPlot(new Stroke(Brushes.SeaGreen, DashStyleHelper.DashDotDot, 2), PlotStyle.Square, "Weekly Median");



    I look forward to being of further assistance.

    Comment


      #3
      Thanks for pointing me in the right direction. I'll get to work on changing that.

      Comment


        #4
        By chance did you get this weekly version of this working and if so could you share?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        581 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        338 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X