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

DrawLine error startBarsAgo out of Range

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

    DrawLine error startBarsAgo out of Range

    Im getting out of range error for a DrawLine and Im not sure why.

    here is the error,


    Error on calling 'OnBarUpdate' method for strategy 'MyCustomStrategy/16e4ec3489ac4e47a5dff5ac3572ba30': MyCustomStrategy.DrawLine: startBarsAgo out of valid range 0 through 250, was 418.

    Here is the code,

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class MyCustomStrategy : Strategy
    {
    private double highY;
    private double lowY;
    private double closeY;
    private int sessionCount;


    protected override void Initialize()
    {
    Add(PeriodType.Minute, 60);
    Add(PeriodType.Minute, 1);

    CalculateOnBarClose = true;

    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    DrawLine("highY" + sessionCount, false, Bars.BarsSinceSession, highY, 0, highY,Color.Black,DashStyle.Dash,2);
    DrawLine("lowY" + sessionCount, false, Bars.BarsSinceSession, lowY, 0, lowY,Color.Black,DashStyle.Dash,2);
    DrawLine("closeY"+ sessionCount, false, Bars.BarsSinceSession, closeY, 0, closeY,Color.Black,DashStyle.Dash,2);

    if(BarsInProgress == 1)
    return;

    // If there is a new session add one to session count.
    if(Bars.SessionBreak)
    sessionCount++;

    if(BarsInProgress == 2)
    {
    if(CurrentBar < 1)
    return;

    if(Bars.FirstBarOfSession)
    {
    highY = MAX(Highs[1],14)[0];
    lowY = MIN(Lows[1],14)[0];
    closeY = Closes[1][1];
    }



    }

    }


    }
    }

    #2
    Hi Gkonheiser,

    Since you are using a multi series script you will need to have a BarsInProgress check for the DrawLines().

    Let me know if this is the answer you are looking for.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hi Cal

      I moved the DrawLines under if(BarsInProgress == 2) but still have the error so thats probably what you mean. Could you explain further ?

      Comment


        #4
        GKhonsier,

        Try changing the BarsRequired to infinite when you apply strategy to the chart.

        If this does not resolve the issue the script will need to be debugged
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          hi Cal

          I found the problem. I am using DrawLine on a minute time frame which means I have 840 bars in one session and apparently the startBarsAgo range is 0 to 250. Is there a way to increase this limit or how would you get around this limit on a minute chart?

          Comment


            #6
            GKonheiser,

            Yes, you would need to change the Maximum Bars Look Back to infinite.
            You can do this through the script parameters when adding it to a chart or in the code via the Initialize section -
            http://www.ninjatrader.com/support/h...rslookback.htm
            Cal H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,221 views
            0 likes
            Last Post xiinteractive  
            Started by andrewtrades, Today, 04:57 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            6 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            9 views
            0 likes
            Last Post FAQtrader  
            Working...
            X