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

Acessing and plotting previous data

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

    Acessing and plotting previous data

    How do I get an indicator to plot data that is 7 days old and in sync with current time of day? As well be able scroll back and view previous days delayed info.
    e.g. plot Monday 19, 7:30 data as current day Monday 26, 7:30
    I have tried indexing using the following, but will not show previous data:
    int index = CurrentBar-(Bars.GetBar(DateTime.Now.AddDays(-7))+1;

    #2
    Hello jt888,

    Thanks for your post and welcome to the forums!

    I'm not sure I understand what you are trying to accomplish. Do you have a chart example that you can illustrate with?
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Sorry, no chart sample. What I am trying to do is plot an indicator with week old data as if it were current data. Indicator would be showing Tuesday 20/09/16 as if it were Tuesday 27/09/16 on Tuesday 27/09/16 using a 1 minute chart. e.g. MACD indicator data for Tuesday 20th @ 7:00 am would be plotted as if it were Tuesday 27th @ 7:00 am and Tuesday 27th @ 7:00 am being the current time and bar. As well, have previous bars showing week old data for that time and bar.
      Tried indexing and plotting indicator, as well as setting Maximum bars look back to infinite but nothing shows up.
      int index = CurrentBar-(Bars.GetBar(DateTime.Now.AddDays(-7))+1;
      MACD(12,26,9).Diff[index]

      Comment


        #4
        Hello jt888,

        What I recommend is that you print out, on a bar by bar basis, the value of index and see if it is as you expected. You are using the index as a barsago value for the macd diff series. Are you ensuring that you are not trying to access a barsago value that does not yet exist? (as indicated by errors in the "log" tab of the NinjaTrader control center). Are you also assigning the macd diff series to a plot?
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          I now have indicator working with previous data at current bar. It will plot MACD (previous week day data) from point of indicator being loaded and forward. All works good from that point. It is processing and plotting correct data just nothing prior to bar in which indicator was loaded. No errors showing up in log. How do I get indicator to plot bars ago data occurring prior to loading? If I put in a value of 20 for bars ago everything works fine. Added code below.





          protected override void Initialize()
          {
          Add(new Plot(Color.Green, "Macd"));
          Add(new Plot(Color.DarkViolet, "Avg"));
          Add(new Plot(new Pen(Color.Navy, 2), PlotStyle.Bar, "Diff"));

          Add(new Line(Color.DarkGray, 0, "Zero line"));

          fastEma = new DataSeries(this, MaximumBarsLookBack.Infinite);
          slowEma = new DataSeries(this, MaximumBarsLookBack.Infinite);
          }

          /// <summary>
          /// Calculates the indicator value(s) at the current index.
          /// </summary>
          protected override void OnBarUpdate()
          {

          if(CurrentBars[0] < BarsRequired)
          return;

          int index = CurrentBar-Bars.GetBar(DateTime.Now.AddDays(-7))+1;
          //int index = 20;
          /*
          if (CurrentBar == 0)
          {
          fastEma.Set(Input[0]);
          slowEma.Set(Input[0]);
          Value.Set(0);
          Avg.Set(0);
          Diff.Set(0);
          }
          else
          {

          */
          fastEma.Set((2.0 / (1 + Fast)) * Input[index] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
          slowEma.Set((2.0 / (1 + Slow)) * Input[index] + (1 - (2.0 / (1 + Slow))) * slowEma[1]);

          double macd = fastEma[0] - slowEma[0];
          double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1];

          Value.Set(macd);
          Avg.Set(macdAvg);
          Diff.Set(macd - macdAvg);
          // }
          }

          Comment


            #6
            Hello jt888,

            Thanks for your post.

            Please add a screenshot that shows the issue and also attach the source file for review. The source file can be found in Documents>Ninjatrader7>bin>Custom>Indicator> and will have a .CS extension.

            To post a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

            Click here for instructions

            Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

            Click here for detailed instruction
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Indicator was load at 7:25. Starts plotting at close of bar and plots at the close of every bar following. Indicator is plotting MACD bars ago at approximately a week ago. The problem I am having is that nothing is being plotted prior to 7:25. I appreciate the help.
              Code and window snap shot attached.
              Thank You,
              Jim
              Attached Files

              Comment


                #8
                Hello jt888,

                Thanks for your post.

                The issue is related to using DateTime.Now and would recommend that you use Time[0] instead. However the trick is going to be to wait until you have 7 days of data loaded before trying to access and plot the data from 7 days ago.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Hello jt888,

                  Alternatively, if you want to just use a standard MACD you can use the "displacement" feature of the indicator to shift the indicator. In the indicator parameters is the row "Displacement" where you can enter a specific number of bars to shift the indicator.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    The Time[0] solved the problem. THANKS.
                    I will now use it in calculating shift for a standard MACD.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by corman, Today, 02:02 PM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by Uregon, Today, 12:12 PM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Kate  
                    Started by kerplunk1899, Today, 10:03 AM
                    1 response
                    18 views
                    0 likes
                    Last Post NinjaTrader_Kate  
                    Started by rexsole, Today, 10:20 AM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_RyanS  
                    Started by pjsmith, Today, 03:01 AM
                    6 responses
                    18 views
                    0 likes
                    Last Post bltdavid  
                    Working...
                    X