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:
    [INDENT]Draw.HorizontalLine(this, "EMHigh", EMHigh, Brushes.Green,DashStyleHelper.Dash,3);[/INDENT]
    Both these values are set in the State == State.Defaults section:

    Code:
    [INDENT]IsOverlay = true;
    DrawOnPricePanel = true;[/INDENT]
    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:
    [INDENT]Draw.HorizontalLine(this, "EMHigh", EMHigh, Brushes.Green,DashStyleHelper.Dash,3, DrawOnPricePanel);[/INDENT]
    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

    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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      81 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      68 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      55 views
      0 likes
      Last Post CarlTrading  
      Working...
      X