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

WHY it doesnot work when I enabled the strategy

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

    WHY it doesnot work when I enabled the strategy

    double a = this.High[0];
    double b = Math.Min(this.Open[0], this.Close[0]);
    double f = Math.Max(this.Open[0], this.Close[0]);
    double c = this.Low[0];
    double d = this.Open[0]-this.Close[0];
    double e = Math.Abs(d);
    double h = (this.Highs[0][0]-this.Lows[0][0])*BarsArray[0].Instrument.MasterInstrument.TickSize;
    double I= High[BarsSinceEntryExecution(0,"",0)]-Low[BarsSinceEntryExecution(0,"",0)];
    Print("Green : " + SampleGetHighLowByTimeRangeHigh.HighestHigh[0] + " Red: " + SampleGetHighLowByTimeRangeLow.LowestLow[0]);
    if((SampleGetHighLowByTimeRangeHigh.HighestHigh[0]-SampleGetHighLowByTimeRangeLow.LowestLow[0])<50){

    j=Math.Max(StartY,EndY);
    k=Math.Min(StartY,EndY);
    } else if ((SampleGetHighLowByTimeRangeHigh.HighestHigh[0]-SampleGetHighLowByTimeRangeLow.LowestLow[0])>50)
    {
    j=SampleGetHighLowByTimeRangeHigh.HighestHigh[0];
    k=SampleGetHighLowByTimeRangeLow.LowestLow[0];
    }
    double body = e;
    double tail = b - c;
    double head = a - f;




    WHY it doesnot work when I enabled the strategy , it was successfully complied??

    ANY reason??

    #2
    Hello stantenlee,

    When you say it does not work, what is the behavior you are seeing?

    Is there an error appearing on the Log tab of the Control Center?
    If so, what is the full error message?

    Is the calculated value not what you expect?
    If so, use Print() to print all the values used in the calculation to understand the behavior.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      the strategy cannot be enabled ,it would untick automatically after i tick it.
      the log was attached and the highlight part is the error
      the value was printed successfully with using the double z = BarsSinceEntryExecution(0,"",0);
      Print("HSI_I VALUE:" +z);
      Attached Files

      Comment


        #4
        Hello stanlee,

        The strategy will disable when a run time error is hit.

        The error means your code is referencing an object that has not been instantiated (does not exist.) Aka, the object being referenced is null.

        To troubleshoot this error, you will have to find the line of code that throws the error, and adjust the code once that part of code is identified.

        To Identify where the error is thrown:
        1. Add prints through out the script's OnBarUpdate method (and methods called from OnBarUpdate) so you can identify the specific line that throws the error.
        2. Test the procedure to reproduce the error
        3. Check the output window to note the last line of code hit
        Then you can test again to reproduce, but add prints that check which particular item in that line of code is null.

        Once you know the particular object being referenced which is null, the code would need to be adjusted in either of the following ways
        1. The object that is null is not referenced
        2. The code is modified so the object is not null (if it should not be null when your code needs to reference it.)
        If you need additional help,
        • Which line of code is throwing the error?
        • What object on that line of code is null?
        An example on this kind of error can be found below (does not have to be an Order object)

        JimNinjaTrader Customer Service

        Comment


          #5
          I am sorry to say that i wrongly recognized the error code. The true error code that caused me my "enable" not allowed. I print out the double z = BarsSinceEntryExecution(0,"",0);
          Print("HSI_I VALUE:" +z);
          it would print out -1 and the error occur when I try to enable it.High[-1] should be the reason that cause error. How can I fix it before there are execution loaded the strategy when I enabled???

          Comment


            #6
            Hello stantenlee,

            Code:
            double z = BarsSinceEntryExecution(0,"",0);
            Print("HSI_I VALUE:" +z);
            can be copied in a blank script's OnBarUpdate method and will not produce an error.

            High[-1] should not be used. High[0] is the high of the current bar, High[1] would be the high of the previous bar. We cannot check the high of a future bar that has not yet been processed.

            Working with Price Series - https://ninjatrader.com/support/help...ice_series.htm

            If you are referring to a different error, we need to know the specific error received and the line of code that throws the error to move forward:
            1. Please place prints throughout the strategy (after each line) and ensure the prints are unique.
            2. Open the Output window
            3. Test the strategy and check for the error in the log tab of the Control Center
            4. Copy the error message.
            5. Check your prints from the output window. The last print seen is the last line of code that was executed. The next line of code then would have thrown the error.
            6. Paste the error message, and copy/paste the line of code that threw the error.
            JimNinjaTrader Customer Service

            Comment


              #7
              what i mean is that my code is
              High[BarsSinceEntryExecution(0,"",0)], at the start it would become High[-1] as there is no execution before. I think this is the reason why error happened.So i am asking how to eliminate that

              Comment


                #8
                Hello stantenlee,

                For that type of error, you could check if (BarsSinceEntryExecution(0,"",0) > 0) before referencing High[BarsSinceEntryExecution(0,"",0)]

                JimNinjaTrader Customer Service

                Comment


                  #9
                  thanks for help

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by fx.practic, 10-15-2013, 12:53 AM
                  5 responses
                  5,403 views
                  0 likes
                  Last Post Bidder
                  by Bidder
                   
                  Started by Shai Samuel, 07-02-2022, 02:46 PM
                  4 responses
                  94 views
                  0 likes
                  Last Post Bidder
                  by Bidder
                   
                  Started by DJ888, Yesterday, 10:57 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by MacDad, 02-25-2024, 11:48 PM
                  7 responses
                  158 views
                  0 likes
                  Last Post loganjarosz123  
                  Started by Belfortbucks, Yesterday, 09:29 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post Belfortbucks  
                  Working...
                  X