• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 chartish, Today, 04:43 PM
            0 responses
            7 views
            0 likes
            Last Post chartish  
            Started by Trader17, Today, 04:07 PM
            0 responses
            4 views
            0 likes
            Last Post Trader17  
            Started by GussJ, Today, 01:30 PM
            2 responses
            18 views
            0 likes
            Last Post GussJ
            by GussJ
             
            Started by GARZONJ, Today, 12:25 PM
            3 responses
            17 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Started by RandanAL, Today, 11:53 AM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X