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
How to display values of my Series<> in data box
Collapse
X
-
Hello cre8able,
Thanks for your notes.
Only plot values will appear in the Data Box window.
You could add a plot to the script and assign your calculated value to the plot if you want it to appear in the Data Box window.
AddPlot: https://ninjatrader.com/support/help...t8/addplot.htm
Values: https://ninjatrader.com/support/help...nt8/values.htm
See the forum thread linked below for more information and sample code.
https://forum.ninjatrader.com/forum/...90#post1262590
- Likes 1
-
I was trying to get my data into the Data Box, so I added a "Values[0] = " statement, but received this error.
"Error on calling "OnBarUpdate" method on bar 50: Index was outside the bounds of the array.
I know this is a common error if you are asking for bars not in the array.
I know it's related to my statement of
PHP Code:if (CurrentBar < 50) return;
But I can't figure out where in my pretty simple code I went wrong. Any help is appreciated.
here is my code
PHP Code:public class PeakValley : Indicator
{
public override string DisplayName
{get {if (State == State.SetDefaults) return "PeakValley"; else return ""; }}
public Series<double> pricePeak, priceValley;
public Series<double> uOPeak, uOValley;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "PeakValley";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
}
else if(State == State.DataLoaded)
{
pricePeak = new Series<double>(this, MaximumBarsLookBack.Infinite);
priceValley = new Series<double>(this, MaximumBarsLookBack.Infinite);
uOPeak = new Series<double>(this, MaximumBarsLookBack.Infinite);
uOValley = new Series<double>(this, MaximumBarsLookBack.Infinite);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 50) return;
int lookback = 1;
FindPricePeak();
FindUOPeak();
FindPriceValley();
FindUOValley();
if(pricePeak[0] > 0)
Draw.Dot(this, "PricePeak" + Time[0].ToString(), true, lookback, High[lookback], Brushes.White);
if(priceValley[0] > 0)
Draw.Dot(this, "PriceValley" + Time[0].ToString(), true, lookback, Low[lookback], Brushes.White);
if(uOPeak[0] > 0)
Draw.Dot(this, "UO" + Time[0].ToString(), true, lookback, High[lookback] + 2, Brushes.Yellow);
if(uOValley[0] > 0)
Draw.Dot(this, "UO" + Time[0].ToString(), true, lookback, Low[lookback] - 2, Brushes.Yellow);
}
//==========================================================================================
private void FindPricePeak()
{
if(Close[0] < Open[0] && Close[1] > Open[1] && Close[2] > Open[2])
pricePeak[0] = High[0];
else
pricePeak[0] = 0;
Value[0] = pricePeak[0];
}​
Leave a comment:
-
Yes, you would need to assign a Value[] to any series to have it appear in the data box. You can assign as many Values as you like to appear in the data box starting at an index of zero.
Leave a comment:
-
Thanks JoshG. Does this hold true if I already have other Values[] in the indicator? As it stands, there are already Series<> objects ranging from Values[1] to Values[6] that are plotted on the chart.
Leave a comment:
-
Hello mbesha,
Thanks for your post.
You need to assign your series to 'Value'. Try this.
Code:if(VAt.IsValidDataPoint(0) && POC.IsValidDataPoint(0) && VAb.IsValidDataPoint(0)) { TPO_BLdiff_Series[0] = Convert.ToInt32(100*(POC[0]-VAb[0])); Value[0] = TPO_BLdiff_Series[0]; }
Leave a comment:
-
How to display values of my Series<> in data box
I have created a series for holding some values among my variables as follows:
private Series<int> TPO_BLdiff_Series;
and added the following code in the OnStateChange() method:
if (State == State.DataLoaded)
{
// "this" refers to the NinjaScript object itself. This syncs the Series object to historical data bars
// MaximumBarsLookBack determines how many values the Series<double> will have access to
TPO_BLdiff_Series = new Series<int>(this, MaximumBarsLookBack.Infinite);
}
For the OnBarUpdate() method, I have calculated values and added them to my series as follows:
//my code for calculating and storing values
if(VAt.IsValidDataPoint(0) && POC.IsValidDataPoint(0) && VAb.IsValidDataPoint(0))
{
TPO_BLdiff_Series[0] = Convert.ToInt32(100*(POC[0]-VAb[0]));
}
Now the hurdle I have been unable to overcome is how to display the values of my series in the data box. I don't know how to code the xml of the Properties region to achieve this so that if I hover my mouse cursor above a bar on the chart, I can see the value of TPO_BLdiff_Series for that bar in the data box. I have reached the limits of my programming know-how and would highly appreciate if someone could kindly help me to accomplish my desired task. Many thanks in advance.
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by lorem, Today, 09:18 AM
|
1 response
4 views
0 likes
|
Last Post
by lorem
Today, 09:30 AM
|
||
Started by bmartz, Today, 09:30 AM
|
0 responses
3 views
0 likes
|
Last Post
by bmartz
Today, 09:30 AM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
14 responses
3,244 views
0 likes
|
Last Post
by GussJ
Today, 09:28 AM
|
||
Started by ArkansasClint, Today, 09:28 AM
|
0 responses
0 views
0 likes
|
Last Post Today, 09:28 AM | ||
Started by hazylizard, Today, 08:38 AM
|
4 responses
12 views
0 likes
|
Last Post
by hazylizard
Today, 09:16 AM
|
Leave a comment: