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

Strange Indicator Issue

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

    Strange Indicator Issue

    In trying to code a simple one minute percent change, I am coming up with an error that I'm sure is simple to fix, but alas, I have not been able to.

    the concept is as follows:

    Add(PeriodType.Day, 1); // Add day Bars object (default), index = 1


    CalculateOnBarClose =
    false;

    BarsRequired =
    2;

    double oneMinPercChange = ((Closes[0][0]-Closes[0][1]) /
    Closes[1][0]) * 100;



    I am using prior close as my reference price so that I can tell if a stock went from -5 to -7 relative to previous 4:00 PM (as opposed to what it may have done based on today's news or earnings stories).

    The " * 100 " is just for visuals when I am looking at charts etc.

    So there you have it, one minute price change, simple enough. Only it will sometimes, for what i can tell is no good reason, drop the actual % price change and instead return the last price.

    Example: for AAPL it will return 325.35, which of course did not happen.


    Any ideas or tips here?


    Thanks in advance.


    Andrew

    #2
    Hello,

    Thanks for the note.

    Who often does this happen?

    Also, how are you displaying this, are you displaying it in a plot?

    I look forward to assisting you further.

    Comment


      #3
      I am displaying this in a plot; how would this affect or change the value? the line in my strategy reads like this

      if (MinuteWeightPlot(0).plotMinuteWeight[0] >= 40
      && oneMinPercChange().plotOneMinPercChange[0] >= 4)

      and then enter long or short or whatever it requires...can this be changed to make the values more in line with what I am expecting.

      Thanks in advance Brett.

      Regards,

      Andrew

      Comment


        #4
        Hello,

        It matters if you do not set a plot. If you do not set a plot it will be replaced with the current close price. You want to make sure to set this plot each OnBarUpdate.

        Let me know if I can be of further assistance.

        Comment


          #5
          I am setting a plot on each on bar update but the problem is there nonetheless, so nothing has changed. Help still requested.

          Comment


            #6
            Hello,

            In this case we would need to debug your code.

            Wouild try with Print() which bar this occurs on and the variables that are outputed and you calculate to check to see where the problem is.

            If after using the below steps and debugging your still running into issue narrowing it down you can send the code to me and I can take a quick look.

            Debugging your NinjaScript Code

            Comment


              #7
              I have used said output window all day, how can i send the code to you for your review?

              thanks,

              andrew

              Comment


                #8
                alabell, I'm not sure your formula for calculating the percent change is correct. Why are you dividing by the daily price? A percent change needs to reference the initial value and the final value, and nothing else.

                Please try this code:
                Code:
                protected override void OnBarUpdate()
                {
                    double pctChg = (Close[0] - Close[1])/Close[1] * 100;
                    Plot0.Set(pctChg);
                }
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Thanks for your message Austin.

                  Your response is correct in one way, but not in the way I am using the indicator.

                  The calc I am creating returns the % change in a stock over one minute, relative to yesterday's 4PM close.

                  It is useful for measuring the price change (in percentage) that the market is attributing to a company's valuation after an overnight news event, for example.

                  "After Goldman downgraded the stock, it opened at -6%. It is now trading -10%, and the 4 percent drop happened in 3 or 4 minutes. Perhaps I would like to buy some here."

                  At any rate, it is the same calc as

                  Index:

                  [0] are minute bars, [1] are day bars.


                  (Closes[0][0] - Closes[1][0]) / Closes[1][0] //percentChangeSincePriorClose[0][0]

                  minus

                  (Closes[0][1] - Closes[1][0]) / Closes[1][0] //percentChangeSincePriorClose[0][1]

                  Again, thank you for the inquiry. I am hoping Brett will see something in my code that is causing the % change to be completely off at times. I am still stumped.

                  Regards.
                  Last edited by alabell; 08-28-2011, 08:34 AM.

                  Comment


                    #10
                    alabell, does this occur on a regular basis? If so, what sort of circumstances trigger these odd prints?
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      Given your description, I think that yesterday's close should be Closes[1][1], not Closes[1][0].

                      Comment


                        #12
                        What's critical here to know is the time stamp for all series, and whether accessing is done historical or real time.

                        See here for a description of this:
                        How Bar Data is Referenced in a MultiSeries script.

                        To identify time stamps, use something like:
                        Print("Primary Series time: " + Times[0][0] + " Secondary Series time: " + Times[1][0]);
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          thanks folks for the comments. i'm on the east coast so i just got power back I am going to look this over in the coming hours. I will respond with what I find but I thank all for the suggestions; i think the concept that I may need to use closes [1][1] for my [index][bar number] because it is in backtest may be a very promising lead and i can test it with the above mentioned time code.

                          Thanks again folks, will report back.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by bortz, 11-06-2023, 08:04 AM
                          47 responses
                          1,603 views
                          0 likes
                          Last Post aligator  
                          Started by jaybedreamin, Today, 05:56 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post jaybedreamin  
                          Started by DJ888, 04-16-2024, 06:09 PM
                          6 responses
                          18 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by Jon17, Today, 04:33 PM
                          0 responses
                          4 views
                          0 likes
                          Last Post Jon17
                          by Jon17
                           
                          Started by Javierw.ok, Today, 04:12 PM
                          0 responses
                          12 views
                          0 likes
                          Last Post Javierw.ok  
                          Working...
                          X