• 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

Indexing problems

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

  • eDanny
    replied
    Accessing 50 bars back (roclength) in a loop is not a very good idea until you have at least 50 bars to access..

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    Hello bradc343,

    Thank you for your note.

    Without the full code we're unable to test on our end.

    If you'd like to upload the full code I can take a look and see if anything jumps out. Or if you'd prefer to email a copy, send to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and the files.

    I look forward to your reply.

    Leave a comment:


  • bradc343
    replied
    Thanks for advice

    Thnak you so much for your help but I am still having problems. I have replaced my line of code with: if(CurrentBars[0]<10 || CurrentBars[1] < 10 || CurrentBars[2] <10)
    that didnt work for me I still got the error: Index was outside the bounds of the array.
    No matter what number I put in there I got the same error. I tried 50, 200 and 400. I even tried replacing if(CurrentBars[0]<10 || CurrentBars[1] < 10 || CurrentBars[2] <10) with if (CurrentBar < 50){return;} that didnt work. I got the same error. I am not giving up on this code I need to learn how to solve this problem. Is there something else I am doing wrong? Am I initializing something wrong or calling the rsi data wrong or do I need to use if (BarsInProgress == 1) line f code..

    Thank you so much in advance

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    Hello bradc343,

    Thank you for your note.

    You should include a current bar check for the additional data series.

    For example if you add the following to the top of your code, does your script run as expected?

    Code:
    if(CurrentBars[0]<10 || CurrentBars[1] < 10 || CurrentBars[2] <10) return;
    You would want to see the following link for more information,
    https://ninjatrader.com/support/foru...ead.php?t=3170

    I look forward to your reply.

    Leave a comment:


  • bradc343
    started a topic Indexing problems

    Indexing problems

    So I have been searching the forum for a couple days on this topic and the problems I am having but cant seem to find a solution. I am try to find the average of the Rate of Change indicator over a certain period and on Two different data series at the same time. It complies but every time I run it I get the" Error on calling 'OnBarUpdate' method for indicator 'test' on bar 2: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

    this is my code can you see any problems:

    #region Variables
    // Wizard generated variables
    private int roclength = 50; // Default setting for MyInput0
    private int actroclength = 50;
    private double sum = 0;
    private double sum2 = 0;
    private double avg = 0;
    private double avg2 = 0;
    private double num = 0;
    private double dom = 0;
    private double dom2 = 0;
    private double dom3 = 0;
    private double dom4 = 0;


    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {

    Add("NQ 12-17", PeriodType.Minute, 1);
    Add("ES 12-17", PeriodType.Minute, 1);
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Overlay = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired || CurrentBars[2] <= BarsRequired || CurrentBars[3] <= BarsRequired)
    return;

    /*if (CurrentBar < 2)
    {
    return;
    }*/

    double[] roc = new double[roclength];
    double[] roc2 = new double[roclength];
    double[] corr = new double[roclength];
    double[] corr2 = new double[roclength];

    for(int i = roclength; i > 0; i--)
    {
    roc[i] = ROC(BarsArray[1],actroclength)[i];
    roc2[i] = ROC(BarsArray[2], actroclength)[i];
    }

    for(int j = roclength; j > 0; j--)
    {
    sum += roc[j];
    sum2 += roc2[j];
    }

    avg = sum/roclength;
    avg2 = sum2/roclength;

    Plot0.Set(avg);
    }

    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Plot0
    {
    get { return Values[0]; }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int Roclength
    {
    get { return roclength; }
    set { roclength = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int Actroclength
    {
    get { return actroclength; }
    set { actroclength = Math.Max(1, value); }
    }
    #endregion

Latest Posts

Collapse

Topics Statistics Last Post
Started by edmata1109, Yesterday, 10:36 PM
0 responses
5 views
0 likes
Last Post edmata1109  
Started by StevenNelson, 10-11-2019, 05:51 AM
2 responses
14 views
0 likes
Last Post ManIp
by ManIp
 
Started by TazoTodua, Yesterday, 12:29 PM
2 responses
24 views
0 likes
Last Post TazoTodua  
Started by sdauteuil, Yesterday, 03:16 PM
0 responses
8 views
0 likes
Last Post sdauteuil  
Started by Zenersev, Yesterday, 02:11 PM
0 responses
5 views
0 likes
Last Post Zenersev  
Working...
X