Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw.HorizontalLine on chart with multiple data series

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

    Draw.HorizontalLine on chart with multiple data series

    I have an indicator that draws some horizontal lines on the price panel. However, it only works when I have one data series in the chart. The code looks like this:

    Code:
    Draw.HorizontalLine(this, "EMHigh", EMHigh, Brushes.Green,DashStyleHelper.Dash,3);
    Both these values are set in the State == State.Defaults section:

    Code:
    IsOverlay = true; DrawOnPricePanel = true;
    Code works fine with only one data series but when there are two (i.e. 5 min and 30 min), I get the following error:

    Code:
    System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource)
    at NinjaTrader.Gui.Chart.MultiEquidistant.Bar2Slot(Ch artBars chartBars, Int32 barIndex)
    at NinjaTrader.Gui.Chart.ChartControl.GetXByBarIndex( ChartBars chartBars, Int32 barIndex)
    at NinjaTrader.NinjaScript.DrawingTools.DrawingTool.C reateChartAnchor(NinjaScriptBase ownerNinjaScript, Int32 barsAgo, DateTime time, Double y)
    at NinjaTrader.NinjaScript.DrawingTools.Draw.DrawLine TypeCore[T](NinjaScriptBase owner, Boolean isAutoScale, String tag, Int32 startBarsAgo, DateTime startTime, Double startY, Int32 endBarsAgo, DateTime endTime, Double endY, Brush brush, DashStyleHelper dashStyle, Int32 width, Boolean isGlobal, String templateName)
    at NinjaTrader.NinjaScript.DrawingTools.Draw.Horizont alLineCore(NinjaScriptBase owner, Boolean isAutoScale, String tag, Double y, Brush brush, DashStyleHelper dashStyle, Int32 width)
    at NinjaTrader.NinjaScript.DrawingTools.Draw.<>c__Dis playClass4a.<HorizontalLine>b__49()
    at NinjaTrader.NinjaScript.DrawingTools.DrawingTool.D rawToggledPricePanel[T](NinjaScriptBase owner, Boolean isDrawOnPricePanel, Func`1 drawAction)
    at NinjaTrader.NinjaScript.Indicators.WeeklyExpectedM ove.OnStateChange()
    I've tried modifying the code to include DrawOnPricePanel as follows but I still get the same error.

    Code:
    Draw.HorizontalLine(this, "EMHigh", EMHigh, Brushes.Green,DashStyleHelper.Dash,3, DrawOnPricePanel);
    Thanks in advance.

    Nick

    #2
    Hello nduckste,

    I would suggest moving any Draw statement to the OnBarUpdate() section as in State.SetDefaults the data series has not been loaded.

    To draw only once in OnBarUpdate() you could use (assuming EMhigh is defined prior to this)

    if (CurrentBar == 0)
    {
    Draw.HorizontalLine(this, "EMHigh", EMHigh, Brushes.Green,DashStyleHelper.Dash,3);
    }


    Here is a link to what you can do in the various states:https://ninjatrader.com/support/help...tatechange.htm

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul,

      Thank you. That worked and makes sense. I had it State == State.Defaults section so as to only run it once checking CurrentBar == 0 works just as well.

      Cheers,

      Nick

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by punkiy2111, Today, 05:22 PM
      0 responses
      2 views
      0 likes
      Last Post punkiy2111  
      Started by secrettrader, Today, 03:36 PM
      0 responses
      7 views
      0 likes
      Last Post secrettrader  
      Started by t3chn0, Today, 01:03 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Started by jleira, Today, 02:27 PM
      0 responses
      22 views
      0 likes
      Last Post jleira
      by jleira
       
      Started by Kreyenhagen, Today, 01:54 PM
      2 responses
      21 views
      0 likes
      Last Post Kreyenhagen  
      Working...
      X