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

NinjaScript Buggy and Inacurate. Please Help !!!

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

    NinjaScript Buggy and Inacurate. Please Help !!!

    Hello,

    I created a test indicator (accepting the default values of the wizard just to have a bare minimum indicator, in order to debug the odd behavior)

    The resulting created indicator code and the test code:

    protected override void OnBarUpdate()
    {
    Print("");

    for (int idx =0; idx < 20; idx++)
    {
    Print("Value before : " + Close[idx]);
    }
    Print("");

    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    Plot0.Set(Close[0]);
    }

    After loading this to a "3Minutes YM Chart, Connected to simulator", I get the following odd result:

    Value before : 10594


    1. The print shows only one value (the above value)
    2. This value is not even the last value showing on the chart ( 10729 is the last value).
    3. 10 minutes, 30 minutes and An hour later, I still get the same single value.

    I changed the code to the following:

    protected override void OnBarUpdate()
    {
    Print("Value After : " + Close[0]);
    Print("Value After 2: " + Close[1]);
    Print("Value After 3: " + Close[2]);
    Print("");

    for (int idx =0; idx < 20; idx++)
    {
    Print("Value before : " + Close[idx]);
    }
    Print("");

    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    Plot0.Set(Close[0]);
    }

    The result (some 10 minutes later):

    Value After : 10594


    That's it!??? No need to tell you that this is very odd and extremely frustrating.

    I desperately need your help and solution to this bug as all my work is currently suspended until this is resolved.

    Obi

    #2
    First, you need to convert the Close[] to a string before you print it out
    Code:
    Close[0].ToString();
    Second, you should have the following statement before your for loop.
    Code:
    if(CurrentBar < 20)
        return;
    The reason for this is you don't want to cause an exception by trying to access data that doesn't yet exist on the chart.

    hope this helps
    mrlogik
    NinjaTrader Ecosystem Vendor - Purelogik Trading

    Comment


      #3
      Hi Obi, I already responded to your email sent to our support inbox.

      Thanks for your input mrlogik.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Hi NinjaTrader_Bertrand and Mr.Logik,

        The following still give the same result as explained earlier:

        protected override void OnBarUpdate()
        {
        Print("Value After : " + Close[0].ToString());
        Print("Value After 2: " + Close[1].ToString());
        Print("Value After 3: " + Close[2].ToString());
        Print("");

        // for (int idx =0; idx < 20; idx++)
        // {
        // Print("Value before : " + Close[idx]);
        // }
        // Print("");

        // Use this method for calculating your indicator values. Assign a value to each
        // plot below by replacing 'Close[0]' with your own formula.
        Plot0.Set(Close[0]);
        }

        Result:

        Value After : 10594

        As you can see, hours after I reported the issue, I'm still getting the same single value.

        Can you please have a look at this. It's blocking everything.

        Obi

        Comment


          #5
          I did not see that you added this to your code:

          if(CurrentBar < 20)
          return;
          RayNinjaTrader Customer Service

          Comment


            #6
            Check the LOG tab as well for errors
            mrlogik
            NinjaTrader Ecosystem Vendor - Purelogik Trading

            Comment


              #7
              MrLogik, NT_Ray, NT_Bertrand,

              Thanks for the tips. The "Bar checking condition" did the trick.

              However, now the data get retrieved once (1 call to "getData"). But no runs in the subsequent "OnBarUpdate"s.
              Looking in the Log tab, suggested by MrLogik, reveals the following error:

              "ERRor on calling the 'OnBarUpdate' method for Indicator 'EJ' on bar 100. Index was outside the bounds of the array."

              I understand there is an Array overflow somewhere. When I increase the MAX_DATA to 200, the error persist with 200 instead of 100. There clearly is a relation there.
              It seems as if the internal index (iterator) isn't being reset during subsequent calls. Is this correct or am I missing something else?

              The 'prints' output stops with the last element of the Array. The last 'print' (with the time) never executes (see below).

              protected override void OnBarUpdate()
              {
              if (CurrentBar < _MAX_DATA_POINTS)
              return;

              getData( Close );

              // EJPlot.Set( _data[ 0, 1] );
              for (int idx = 0; idx < _Solutions.Length; idx++)
              {
              Print("Data Nr." + idx + " : " + _Data[idx, 1].ToString() );
              }

              Print("<><><> " + DateTime.Now.ToString("HH:mm:ss") + " <><><>");
              }

              Thanks in advance for your help,
              Obi
              Last edited by Obi; 02-16-2009, 08:54 AM.

              Comment


                #8
                Obi,

                We are not sure what you are doing with these Data[] arrays. You need to check your loop and ensure you do not try to access an invalid index value.

                You will need to debug it. Please see this sample on using try-catch blocks: http://www.ninjatrader-support2.com/...ead.php?t=9825
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by usazencort, Today, 01:16 AM
                0 responses
                1 view
                0 likes
                Last Post usazencort  
                Started by kaywai, 09-01-2023, 08:44 PM
                5 responses
                603 views
                0 likes
                Last Post NinjaTrader_Jason  
                Started by xiinteractive, 04-09-2024, 08:08 AM
                6 responses
                22 views
                0 likes
                Last Post xiinteractive  
                Started by Pattontje, Yesterday, 02:10 PM
                2 responses
                20 views
                0 likes
                Last Post Pattontje  
                Started by flybuzz, 04-21-2024, 04:07 PM
                17 responses
                230 views
                0 likes
                Last Post TradingLoss  
                Working...
                X