Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by elirion, Today, 01:36 AM
      0 responses
      3 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by gentlebenthebear, Today, 01:30 AM
      0 responses
      4 views
      0 likes
      Last Post gentlebenthebear  
      Started by samish18, Yesterday, 08:31 AM
      2 responses
      9 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by Mestor, 03-10-2023, 01:50 AM
      16 responses
      391 views
      0 likes
      Last Post z.franck  
      Started by rtwave, 04-12-2024, 09:30 AM
      4 responses
      34 views
      0 likes
      Last Post rtwave
      by rtwave
       
      Working...
      X