Any thoughts?
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!
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
NinjaTrader
Why does my code keep breaking?
Collapse
X
-
Why does my code keep breaking?
I am working on developing an indicator, starting with a base indicator that works perfectly fine, and the second I use an additional declaration or try to use an array it completely breaks and when debugging in Visual Studio it won't get to OnBarUpdate().
Any thoughts?Tags: None
-
Originally posted by cfp462 View PostError on calling 'OnBarUpdate' method for indicator 'nameofindicator' on bar 1: Index was outside the bounds of the array.
Comment
-
//
// Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
using System.Linq;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// The Test4 (Simple Moving Average) is an indicator that shows the average value of a security's price over a period of time.
/// </summary>
[Description("")]
public class Test4 : Indicator
{
#region Variables
private int period = 14;
private bool draw = true;
private double x = 0;
private int i = 10;
private int[] signals = new int[10];
private int sum = 0;
#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(new Plot(Color.Orange, "Test4"));
Overlay = false;
}
/// <summary>
/// Called on each bar update event (incoming tick).
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
Value.Set(0);
else
{
if (FirstTickOfBar)
draw = false;
if ('xyz happens; not calling anything crazy here just Close, Open, High etc.')
{
draw = true;
DrawDot("tag1"+CurrentBar, true, 0, Close[0], Color.Lime);
for(int n=0; n< 10; n++)
{
signals[n] = signals[n + 1];
}
signals[0] = 1;
}
if ('xyz happens; not calling anything crazy here just Close, Open, High etc.')
{
draw = true;
DrawDot("tag1" + CurrentBar, true, 0, Close[0], Color.Red);
for(int n=0; n< 10; n++)
signals[n] = signals[n + 1];
signals[0] = 0;
}
sum = signals.Sum();
Value.Set(sum);
}
}
Comment
-
Originally posted by cfp462 View Post//
// Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
using System.Linq;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// The Test4 (Simple Moving Average) is an indicator that shows the average value of a security's price over a period of time.
/// </summary>
[Description("")]
public class Test4 : Indicator
{
#region Variables
private int period = 14;
private bool draw = true;
private double x = 0;
private int i = 10;
private int[] signals = new int[10];
private int sum = 0;
#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(new Plot(Color.Orange, "Test4"));
Overlay = false;
}
/// <summary>
/// Called on each bar update event (incoming tick).
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
Value.Set(0);
else
{
if (FirstTickOfBar)
draw = false;
if ('xyz happens; not calling anything crazy here just Close, Open, High etc.')
{
draw = true;
DrawDot("tag1"+CurrentBar, true, 0, Close[0], Color.Lime);
for(int n=0; n< 10; n++)
{
signals[n] = signals[n + 1];
}
signals[0] = 1;
}
if ('xyz happens; not calling anything crazy here just Close, Open, High etc.')
{
draw = true;
DrawDot("tag1" + CurrentBar, true, 0, Close[0], Color.Red);
for(int n=0; n< 10; n++)
signals[n] = signals[n + 1];
signals[0] = 0;
}
sum = signals.Sum();
Value.Set(sum);
}
}
Comment
-
Hello cfp462,
Thanks for your note.
What does your for loop look like now?
It appears you were attempting to shift the values for signal back 1.
This should happen with
for (int i=1; i<9; i++)
signal[n] = signal[n+1];
Let me know if this does not resolve your inquiry.Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by johntraderuser2, Today, 02:34 AM
|
0 responses
6 views
0 likes
|
Last Post Today, 02:34 AM | ||
Started by IanS00, 03-27-2024, 11:24 AM
|
2 responses
12 views
0 likes
|
Last Post Today, 02:00 AM | ||
Started by Mariawilcoxi, Today, 01:32 AM
|
0 responses
4 views
0 likes
|
Last Post
by Mariawilcoxi
Today, 01:32 AM
|
||
Started by gleichnerany, Today, 01:17 AM
|
0 responses
5 views
0 likes
|
Last Post
by gleichnerany
Today, 01:17 AM
|
||
Started by WHICKED, 03-27-2024, 12:33 PM
|
4 responses
47 views
0 likes
|
Last Post Today, 12:28 AM |
Comment