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

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

    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 reynoldsn, Today, 04:40 PM
      0 responses
      4 views
      0 likes
      Last Post reynoldsn  
      Started by Philippe56140, 04-27-2024, 02:35 PM
      6 responses
      54 views
      0 likes
      Last Post bltdavid  
      Started by ETFVoyageur, Yesterday, 06:05 PM
      7 responses
      45 views
      0 likes
      Last Post ETFVoyageur  
      Started by betsuni_123, Today, 04:20 PM
      0 responses
      11 views
      0 likes
      Last Post betsuni_123  
      Started by Aquila_Welokk, 04-29-2024, 01:14 PM
      2 responses
      22 views
      0 likes
      Last Post Aquila_Welokk  
      Working...
      X