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

Accessing Historical Values from AddPlot

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

    Accessing Historical Values from AddPlot

    I have a plot I have added to my indicator AddPlot(new Stroke(Brushes.AliceBlue, 0), PlotStyle.Dot, "Buys");

    When State == State.RealTime in the OnStateChange() method I am trying to access historical values of the Buys Series but I am getting argumentOutOfRange exceptions. The Count is > 0. Why is this throwing an error?

    #2
    Hello habibalex, thanks for writing in.

    There should not be any access to any Series<T> object before data starts processing. If you need to iterate through all of the historical values, it should be done in OnBarUpdate when State == State.Historical. By the time State == State.RealTime, the indicator would have ran through every bar on the chart.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      When State == State.RealTime, I thought all processing is complete? I am doing a BarsRequest when State == State.RealTime to process tick data for the current day. I cannot use TickReplay or Add 1 Tick Data series, as I need to load about 180 days of minute data on the chart. I only need tick data for the last couple days so that is why I am using a BarsRequest.

      Comment


        #4
        Hello habibalex, thanks for your reply.

        I was able to get the data from the list by using GetValueAt() on the series. Can you test the script I attached to see if this will work for you?

        I look forward to assisting.
        Attached Files
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Yes GetValueAt works. Values[0][i] does not work for i > 0. i need to SET the values, not get them
          Last edited by habibalex; 10-21-2020, 07:04 PM.

          Comment


            #6
            Hello habibalex, thanks for your reply.

            This worked for me:

            Code:
            for (int i = 0; i < Values[0].Count-1; i++)
            {
                Values[0][i] = -100;
                Print(Values[0].GetValueAt(i));
            }
            Please let me know if this does not resolve your inquiry.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              That still is not working for me. I am in the State.RealTime when I do the BarsRequest
              Code:
              barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((bars, errorCode, errorMessage) =>
              {
                  if (errorCode != ErrorCode.NoError)
                  {
                  // Handle any errors in requesting bars here
                  //NinjaTrader.Code.Output.Process(string.Format("Err or on requesting bars: {0}, {1}", errorCode, errorMessage), PrintTo.OutputTab1);
                      return;
                  }
              
              
                  try{
                      completeProcessing(bars.Bars, startAVPTime);
                  }
                  catch(Exception ex){
                      Print(ex.Message + " Delta_Regression.cs");
                  }
                  for (int i = closeD.Count - 1, j = 0; i > 0; i--, j++)
                  {
                      Print("getBars: " + i + " " + j);
                      Values[0][j] = closeD[i];
                  }
              
                  dataRequestState = 1;
              }));
              Last edited by habibalex; 10-22-2020, 03:59 PM.

              Comment


                #8
                Hello habibalex, thanks for your reply.

                What values are 'j' and 'i' getting up to versus the size of the closeD array? It's a indexing error being experienced that will need to be found through printing these values.

                I look forward to hearing of your results.
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  I updated the code above to have a print statement, it prints 0 fine, but fails on 1
                  getBars: 25892 0
                  getBars: 25891 1

                  Comment


                    #10
                    Hello habibalex, thanks for your reply.

                    Could you send me an example script to platformsupport at ninjatrader.com? Please Export the script and attach it to your email, referencing "Attn ChrisL 2792451" in the body of the email. Please make sure the test script does not include any third party scripts so I will be able to compile it properly.

                    I look forward to hearing from you.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello habibalex, thanks for your patience.

                      I am still testing your script. I should have a reply to you today after reviewing.

                      Best regards.
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello habibalex,

                        I found that we need to use TriggerCustomEvent when accessing the series while in a non data-driven method. I attached my example here.

                        Please let me know if I can assist any further.
                        Attached Files
                        Chris L.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by ETFVoyageur, Today, 04:00 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post ETFVoyageur  
                        Started by AaronKTradingForum, Today, 03:44 PM
                        1 response
                        6 views
                        0 likes
                        Last Post AaronKTradingForum  
                        Started by Felix Reichert, 04-26-2024, 02:12 PM
                        11 responses
                        77 views
                        0 likes
                        Last Post Felix Reichert  
                        Started by junkone, 04-28-2024, 02:19 PM
                        7 responses
                        82 views
                        1 like
                        Last Post junkone
                        by junkone
                         
                        Started by pechtri, 06-22-2023, 02:31 AM
                        11 responses
                        136 views
                        0 likes
                        Last Post Nyman
                        by Nyman
                         
                        Working...
                        X