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!
See more
See less

Partner 728x90

Collapse

How does NT know which plot goes with which values?

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

  • butt_toast
    replied
    Originally posted by hedgeplay View Post

    "I was able to make a strategy with WPF buttons and multiple data series"
    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!

    HedgePlay
    Thank you so much for your support!

    Can't wait till I'm knowledgeable enough to pay it forward one day.

    Leave a comment:


  • hedgeplay
    replied
    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
    "I was able to make a strategy with WPF buttons and multiple data series"
    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!

    HedgePlay
    Last edited by hedgeplay; 07-25-2021, 12:34 PM.

    Leave a comment:


  • hedgeplay
    replied
    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

    HedgePlay
    Attached Files
    Last edited by hedgeplay; 07-25-2021, 12:20 PM.

    Leave a comment:


  • butt_toast
    replied
    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
    Thanks!

    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:


  • hedgeplay
    replied
    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;
    And now the output window prints: "Indicator 'anIndi': Error on calling 'OnBarUpdate' method on bar 5: Index was outside the bounds of the array."
    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

    Leave a comment:


  • butt_toast
    replied
    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
    ES 5000 volume bars, for 3 Days
    Attached Files

    Leave a comment:


  • hedgeplay
    replied
    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.
    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
    Last edited by hedgeplay; 07-25-2021, 11:24 AM.

    Leave a comment:


  • butt_toast
    replied
    Originally posted by hedgeplay View Post
    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.

    HedgePlay
    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;
    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.
    Attached Files

    Leave a comment:


  • bltdavid
    replied
    Originally posted by butt_toast View Post
    Sorry 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.
    No apologies necessary.

    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.

    Leave a comment:


  • hedgeplay
    replied
    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.

    HedgePlay
    Last edited by hedgeplay; 07-25-2021, 11:02 AM.

    Leave a comment:


  • butt_toast
    replied
    Originally posted by hedgeplay View Post
    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
    I appreciate your help so much.

    It's now telling me: Cannot apply indexing with [] to an expression of type 'double'

    Leave a comment:


  • hedgeplay
    replied
    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:


  • butt_toast
    replied
    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.
    Sorry 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.

    Leave a comment:


  • butt_toast
    replied
    Originally posted by hedgeplay View Post
    The "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
    Thank you so much for replying.

    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:


  • bltdavid
    replied
    Originally posted by butt_toast View Post
    To test this I changed the order around in both locations, however the plotted indicator remained unchanged even after removing and reapplying to the chart.
    Both locations?

    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 funk10101, Today, 09:43 PM
0 responses
2 views
0 likes
Last Post funk10101  
Started by pkefal, 04-11-2024, 07:39 AM
11 responses
36 views
0 likes
Last Post jeronymite  
Started by bill2023, Yesterday, 08:51 AM
8 responses
44 views
0 likes
Last Post bill2023  
Started by yertle, Today, 08:38 AM
6 responses
25 views
0 likes
Last Post ryjoga
by ryjoga
 
Started by algospoke, Yesterday, 06:40 PM
2 responses
24 views
0 likes
Last Post algospoke  
Working...
X