Help with ninjatrader scripting

Discussion in 'App Development' started by w4rn1ng, Dec 5, 2016.

  1. w4rn1ng

    w4rn1ng

    Dear programmers, i need some help with ninjatrader 8 scripting.


    Please forgive my ignorance.

    So, i'm playing up with the code, basically a simple test indicator, with 2 outputs:
    "Outputx" and "Outputxx".

    Now, as we can see in the first image, i put the code:

    Outputx[0]=High[0];
    Outputxx[0]=Low[0];

    And we can see the two lines of the indicator below the chart, working well.


    The thing i don't understand, if i put something before these commands, such as:

    indi[0][0]=0;

    (indi is defined as "public double[][] indi;"), so everything works fine in the compiler, no errors or anything like that.

    However, when i put this line, the indicator on chart disappear.
    I can't understand why?
    Whenever i work with other doubles that are not the outputs, the indicator stop working all together.

    Any idea of what's going on?
     
    • wut.png
      wut.png
      File size:
      165.3 KB
      Views:
      24
  2. algofy

    algofy

    NinjaTrader has a really good support forum for developers, you're likely to get a better response there.
     
  3. w4rn1ng

    w4rn1ng

    Thanks for the suggestion, just posted there too ;)
     
  4. dartmus

    dartmus

    Try commenting out or even better try deleting the parts you added to the indicator, until you reach the point the indicator works again. Then add each line slowly and check to make sure everything is still working before you increase the complexity to a level where you can't locate what's wrong.
     
  5. w4rn1ng

    w4rn1ng

    Ok look at this, i just take a working indicator (ATR), i made a copy of it (ATRx), and make the following modifies:

    added "private Series<double> speeda;" and "speeda[0]=1;"

    and magically everything stop working.
     
  6. terr

    terr

    Disclaimer: I have never done any Ninjatrader scripting, but, AFAIU, Ninja script is C#.

    In C#, the line

    private Series<double> speeda;

    declares an object speeda but does not create an instance of it. Thus, when you do

    speeda[0]=1;

    You are referring to a null object, and getting an exception. Try changing the line to be

    private Series<double> speeda = new Series<double>();

    depending on how the Series<T> object is programmed, that may still get you an index-out-of-range exception at your assignment statement, but at least the object will be defined.
     
    dartmus likes this.
  7. w4rn1ng

    w4rn1ng

    Dear terr, thanks for your help.

    Apparently i managed to fix the situation, using the following code for declaring an array:

    double [] indi = new double[10]; //instead of just double[] indi;
    or also
    double [,] indi = new double[10,10]; // instead of double[][] indi;

    I must say i don't know a lot about coding but somehow we did it! :)