Can't wait till I'm knowledgeable enough to pay it forward one day.
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 does NT know which plot goes with which values?
Collapse
X
-
Originally posted by hedgeplay View Post
Can't wait till I'm knowledgeable enough to pay it forward one day.
-
Originally posted by butt_toast View Post
Thanks!
I was able to make a strategy with WPF buttons and multiple data series
Time to play with the dog
Congrats. That is no small feat.
On Mutliple data series indis this is the line that often trips people up for hours... "if (CurrentBars[0] < 5 || CurrentBars[1] < 5 || CurrentBars[2] < 5)"
Here on this indi, this one left me scratching my head until I finally noticed the AddLine() statement in OSC() where the code in OBU() said an AddPlot() statement should be.
"Time to play with the dog"
Always a great idea!
HedgePlayLast edited by hedgeplay; 07-25-2021, 12:34 PM.
Leave a comment:
-
Second, you might have confused AddLine() which is great as the center line but often no need to reference in OUB() ..
Will AddPlot() which you really do want as the first Addxx() object in OSC().SetDefaults so that Value[0] (Values[0][0] ) will Plot the value you are assigning it in OBU().
So OSC() SetDefaults.
Code:. { if (State == State.SetDefaults) { Description = @""; Name = "anIndi"; Calculate = Calculate.OnBarClose; IsOverlay = false; DisplayInDataBox = true; PaintPriceMarkers = true; [B]/// Many parms deleted.. Do not add this complexity unless you really need it .. /// will often trip you up when you overlook a needed change in parms. [/B] IsSuspendedWhileInactive = true; AddPlot(Brushes.Blue, "MyPlot"); [B]/// I added the plot line you really wanted.. [/B] AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine); [B] /// was "please just plot .." , use the NT default example. Also, as the LAST in the list[/B] } .
In OBU()
Code:. protected override void OnBarUpdate() { // /if (CurrentBars[0] < 5 || CurrentBars[1] < 5 || CurrentBars[2] < 5) return;[B] // Delete, too many arrays referenced when only one dataSeries was added [/B] if(CurrentBar < 0) return; if(CurrentBar > Count-50) // Can remove this conditional .. limits output to only last 50 bars { double aPleasePlotThisLocal = -0.2; //please plot anything aPleasePlotThis[0] = aPleasePlotThisLocal; Value[0] = aPleasePlotThis[0]; } } .
Updated example indi attached
HedgePlayAttached FilesLast edited by hedgeplay; 07-25-2021, 12:20 PM.
Leave a comment:
-
Originally posted by hedgeplay View Post
Ok. First, "good on ya"
Good homework and very important code to know use >>> "if (CurrentBars[0] < 5 || CurrentBars[1] < 5 || CurrentBars[2] < 5)"
In this case you only had one data series loaded ( CurrentBars[0] ) so the conditional tests to both CurrentBars[1] and CurrentBars[2] will drive that OBU() indexing error because those bar arrays do not exist until you load more data series in OSC().Configure above.
So in this case "if( CurrentBar < 0 )" or "if( CurrentBar < 30 )" might be all you need.
But as soon as you add more data series to an indi you will want a version of the example you found.
HedgePlay
Still no dice.
I swapped out the line you mentioned with the code you mentioned, and the error in the output window has changed to: "Indicator 'anIndi': Error on calling 'OnBarUpdate' method on bar 30: Index was outside the bounds of the array."
The number of hours I've sunk into getting a simple plot to plot has taken half of my Sunday so before I throw my computer out of the window I am going to have to step away.
I was able to make a strategy with WPF buttons and multiple data series but I can't even get a line to plot in an indicator after several hours, there has to be something I'm missing here. Maybe my frustration levels are too high at the "wasted" hours.
Time to play with the dog and forget about my inability to get one line to plot in an indicator.
Leave a comment:
-
Originally posted by butt_toast View Post
That got it to compile, now the output window prints: "Indicator 'anIndi': Error on calling 'OnBarUpdate' method on bar 0: Index was outside the bounds of the array."
Googled that, found a potential solution on this forum:
Code:if (CurrentBars[0] < 5 || CurrentBars[1] < 5 || CurrentBars[2] < 5) return;
Good homework and very important code to know use >>> "if (CurrentBars[0] < 5 || CurrentBars[1] < 5 || CurrentBars[2] < 5)"
In this case you only had one data series loaded ( CurrentBars[0] ) so the conditional tests to both CurrentBars[1] and CurrentBars[2] will drive that OBU() indexing error because those bar arrays do not exist until you load more data series in OSC().Configure above.
So in this case "if( CurrentBar < 0 )" or "if( CurrentBar < 30 )" might be all you need.
But as soon as you add more data series to an indi you will want a version of the example you found.
HedgePlay
Leave a comment:
-
Originally posted by hedgeplay View Post
What Instrument, Bar Type and Bar Period is on your current test chart? something like " ES 1 Minute Bars, for 5 Days
Oh, by the way.. Hi David. Happy Sunday to you!
HedgePlay
Leave a comment:
-
Originally posted by butt_toast View Post
That got it to compile, now the output window prints: "Indicator 'anIndi': Error on calling 'OnBarUpdate' method on bar 0: Index was outside the bounds of the array."
And now the output window prints: "Indicator 'anIndi': Error on calling 'OnBarUpdate' method on bar 5: Index was outside the bounds of the array."
I've attached the .cs file.
Oh, by the way.. Hi David. Happy Sunday to you!
HedgePlay
Last edited by hedgeplay; 07-25-2021, 11:24 AM.
Leave a comment:
-
Originally posted by hedgeplay View PostSwap your OBU() for this one..
Code:protected override void OnBarUpdate() { double aPleasePlotThisLocal = 1.0; /// [B]changed the name of this double .. should not match/override the data series name. [/B] aPleasePlotThis[0] = aPleasePlotThisLocal; //please plot anything Value[0] = aPleasePlotThis[0]; }
If that does not do it attach a *.cs file that compiles with but still does not plot.
If it does not compile then as David said we will need to see the full real code you are trying to get to compile ( maybe a stripped down version of the real one will all basic/solvable compile errors resolved.) and the first few compiles errors left.
HedgePlay
Googled that, found a potential solution on this forum:
Code:if (CurrentBars[0] < 5 || CurrentBars[1] < 5 || CurrentBars[2] < 5) return;
I've attached the .cs file.Attached Files
Leave a comment:
-
Originally posted by butt_toast View PostSorry I had initially included code from a tutorial with a question more specific to that tutorial.
I removed the code from the tutorial because I didn't want to share the author's IP and edited my question to be more generic.
I have since posted some code that I created instead of the tutorial code.
In fact, the issue is with my explanation.
I should have elaborated more.
I presume, you did these two edits:
1. Swap the AddPlot lines.
2. Swap the indexes for the plot assignments.
If you make the changes at both locations, you effectively cancelled out
the changes and I'd expect the indicator to show the same visual plots.
When you made changes at both locations, the edit at the 2nd location will
re-align the plots back to the existing assignments -- that is, the edit at the
2nd location effectively reverts the intended effect of the 1st edit.
- Likes 1
Leave a comment:
-
Swap your OBU() for this one..
Code:protected override void OnBarUpdate() { double aPleasePlotThisLocal = 1.0; /// [B]changed the name of this double .. should not match/override the data series name. [/B] aPleasePlotThis[0] = aPleasePlotThisLocal; //please plot anything Value[0] = aPleasePlotThis[0]; }
If that does not do it attach a *.cs file that compiles with but still does not plot.
If it does not compile then as David said we will need to see the full real code you are trying to get to compile ( maybe a stripped down version of the real one will all basic/solvable compile errors resolved.) and the first few compiles errors left.
HedgePlayLast edited by hedgeplay; 07-25-2021, 11:02 AM.
Leave a comment:
-
Originally posted by hedgeplay View PostEasiest question I will address all day.
Change this line: Value[0] = aPleasePlotThis;
To this: Value[0] = aPleasePlotThis[0]; /// Add [0] at the end
HedgePlay
It's now telling me: Cannot apply indexing with [] to an expression of type 'double'
Leave a comment:
-
Easiest question I will address all day.
Change this line: Value[0] = aPleasePlotThis;
To this: Value[0] = aPleasePlotThis[0]; /// Add [0] at the end
HedgePlay
Leave a comment:
-
Originally posted by bltdavid View Post
Both locations?
Your testing sounds inconclusive to me.
Without seeing the code, I would chalk that up as: you made no changes at all.
I removed the code from the tutorial because I didn't want to share the author's IP and edited my question to be more generic.
I have since posted some code that I created instead of the tutorial code.
Leave a comment:
-
Originally posted by hedgeplay View PostThe "Values" Array.
Value[0] ( note the absence of the 's' ) seen in most indicators is just a reference to Values[0][0].
Current value (E.g. [0] ) of the second plot can be found in Values[1][0].
https://ninjatrader.com/support/help...t8/?values.htm
HedgePlay
Am I even in the ballpark here?
That is a head scratcher.
Once I get this to plot anything I feel like I can mess with it and get the ball rolling but I'm just spinning my wheels here.
I bought the NinjaScript Programmer's Launch Pad ebook and the first tutorial skips right over this topic and I feel like just getting something to plot would be the natural first step.
Code:public class anIndi : Indicator { private Series<double> aPleasePlotThis; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @""; Name = "anIndi"; Calculate = Calculate.OnBarClose; IsOverlay = false; 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; AddLine(Brushes.Black, 1, "please just plot something, anything"); } else if (State == State.Configure) { aPleasePlotThis = new Series<double>(this); } } protected override void OnBarUpdate() { double aPleasePlotThis = 1.0; //please plot anything Value[0] = aPleasePlotThis; } }//end class
Last edited by butt_toast; 07-25-2021, 10:47 AM.
Leave a comment:
-
Originally posted by butt_toast View PostTo test this I changed the order around in both locations, however the plotted indicator remained unchanged even after removing and reapplying to the chart.
Your testing sounds inconclusive to me.
Without seeing the code, I would chalk that up as: you made no changes at all.
Leave a comment:
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by mgco4you, Today, 09:46 PM
|
0 responses
1 view
0 likes
|
Last Post
by mgco4you
Today, 09:46 PM
|
||
Started by Rapine Heihei, Today, 08:19 PM
|
1 response
8 views
0 likes
|
Last Post Today, 08:30 PM | ||
Started by Rapine Heihei, Today, 08:25 PM
|
0 responses
6 views
0 likes
|
Last Post Today, 08:25 PM | ||
Started by f.saeidi, Today, 08:01 PM
|
1 response
9 views
0 likes
|
Last Post Today, 08:17 PM | ||
Change colour of Stop market and limit orders to red and green via indicator script
by Rapine Heihei
Started by Rapine Heihei, Today, 07:51 PM
|
0 responses
8 views
0 likes
|
Last Post Today, 07:51 PM |
Leave a comment: