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 rdtdale, Today, 01:02 PM
      0 responses
      1 view
      0 likes
      Last Post rdtdale
      by rdtdale
       
      Started by alifarahani, Today, 09:40 AM
      3 responses
      15 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by RookieTrader, Today, 09:37 AM
      4 responses
      18 views
      0 likes
      Last Post RookieTrader  
      Started by PaulMohn, Today, 12:36 PM
      0 responses
      6 views
      0 likes
      Last Post PaulMohn  
      Started by love2code2trade, 04-17-2024, 01:45 PM
      4 responses
      40 views
      0 likes
      Last Post love2code2trade  
      Working...
      X