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

Indexing Problem

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

    Indexing Problem

    I am trying index the last high or low occurrence of ZigZag as the variable for Range, in order to find the range of price since the last high or low ZigZag. (Range1 is a custom indicator finding the difference between High and Low over its period).

    I believe my problem lies when int zigzag returns a value of -1. I'm stuck on work arounds on how to prevent an index value of -1, to avoid a crash.

    int zigzag = (Math.Min(ZigZag(DeviationType.Points,VARIABLE1,fa lse).HighBar(0, 1, 1000), ZigZag(DeviationType.Points,VARIABLE1,false).LowBa r(0, 1, 1000)));

    Value.Set(Range1(zigzag)[0]);

    #2
    Hello contrlr,

    You could try using Math.Max() to ensure the value is 1 or greater. (I'm not certain what the parameter in Range1() is used for, is this used a period as in number of bars?)

    For example:
    Print(Math.Max(1, zigzag).ToString());

    Below is a publicly available link to the Microsoft documentation on Math.Max().
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I've adjusted to Math.Min to reference Math.Max, and I am still getting the same problem. The indicator prints correctly in a chart (I used VARIABLE1 = 50), but when I optimize with as little as 30;50;10, it crashes.

      Range1() parameter is the period

      int zigzag= Math.Min((Math.Max(1,ZigZag(DeviationType.Points,V ARIABLE1,fa lse).HighBar(0, 1, 1000))),(Math.Max(ZigZag(DeviationType.Points,VARI ABLE1,false).LowBa r(0, 1, 1000), 1)));

      Value.Set(Range1(zigzag)[0]);

      Comment


        #4
        Hello contrlr,

        What is the value that is printing?

        Is it 1 or above?

        Are you certain this value is what is causing the crashing?

        Have you set this to a hard value and prevented the crashing?

        When you say crashing, is NinjaTrader completely shutting down with a windows error?

        Or is the script sending an error to the log and aborting the backtest, or becoming disabled when running live?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Here is the expanded code including Range1:

          int zigzag= Math.Min(
          (Math.Max(1,ZigZag(DeviationType.Points,V ARIABLE1,false).HighBar(0, 1, 1000))),(Math.Max(1,ZigZag(DeviationType.Points,VA RI ABLE1,false).LowBar(0, 1, 1000)))
          );

          double max = MAX(zigzag)[0];
          double min = MIN(zigzag) [0];

          Value.Set((max-min)/TickSize);


          What is the value that is printing? Prints above 1 in the chart

          Are you certain this value is what is causing the crashing? If I remove this part of the strategy, it optimizes normally

          When you say crashing, is NinjaTrader completely shutting down with a windows error? yes

          Or is the script sending an error to the log and aborting the backtest, or becoming disabled when running live? no

          Comment


            #6
            Hello contrlr,

            Specifically I am asking if the issue is an indexing error.

            If you use a hard coded 1, does this prevent the crashing?

            If I were to add just the code you have posted and set a data series to the calculated value with no other code, would I be able to reproduce the behavior?

            If so, I will give this a test on my end.

            I see that you are setting Value, however, this is a strategy and not an indicator, is this correct?

            Value is a special series that is created for the primary plot in an indicator. I'm not certain this should be usable in a strategy, however, I would recommend using a less ambiguous way of setting this by setting the actual data series.

            Do you mean to be setting the data series?

            Below is a publicly available link to the help guide on the DataSeries class.
            Last edited by NinjaTrader_ChelseaB; 12-28-2017, 04:30 PM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Just for clarity, what I am trying to do is find the last occurence of Zig High/Low, use that as the period to find the Range of price since the last Zag High/Low. I attached an image of what it looks like in a chart.

              If you use a hard coded 1, does this prevent the crashing? If I remove the variable and replace with 50, the issue is still the same.

              If I were to add just the code you have posted and set a data series to the calculated value with no other code, would I be able to reproduce the behavior? This might be the case, but the I am trying to use the last instance of Zig High/Low as the period for MIN/MAX, and the regular price data as the data series.

              If so, I will give this a test on my end.

              I see that you are setting Value, however, this is a strategy and not an indicator, is this correct? It is an indicator that I am using in a larger strategy. Without this indicator in the strategy, it optimizes normally.

              Comment


                #8
                image

                Comment


                  #9
                  Hello contrlr,

                  Thank you for your patience.

                  Can you attach a screenshot of the error that shows up from windows when you optimize?

                  Can you attach the indicator and strategy to your response or send them over to platformsupport[at]ninjatrader[dot]com with 'ATTN: Patrick H' in the subject line and a reference to this thread in the body of the email?

                  You can attach your strategy to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your strategy > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.

                  I look forward to your response.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Pattontje, Yesterday, 02:10 PM
                  2 responses
                  14 views
                  0 likes
                  Last Post Pattontje  
                  Started by flybuzz, 04-21-2024, 04:07 PM
                  17 responses
                  229 views
                  0 likes
                  Last Post TradingLoss  
                  Started by agclub, 04-21-2024, 08:57 PM
                  3 responses
                  17 views
                  0 likes
                  Last Post TradingLoss  
                  Started by TradingLoss, 04-21-2024, 04:32 PM
                  4 responses
                  43 views
                  2 likes
                  Last Post TradingLoss  
                  Started by cre8able, 04-17-2024, 04:16 PM
                  6 responses
                  56 views
                  0 likes
                  Last Post cre8able  
                  Working...
                  X