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 pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      148 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Started by mattbsea, Today, 05:44 PM
      0 responses
      5 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      33 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      5 views
      0 likes
      Last Post tkaboris  
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,282 views
      0 likes
      Last Post Leafcutter  
      Working...
      X