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

Indicator is reprocessing old bars...?

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

    Indicator is reprocessing old bars...?

    Hi, I am new to indicator and strategy development and am seeing some behavior I don't understand.

    I modified the prepackaged BuySellVolume indicator to expose a third public property which is a data series that contains the order delta for each bar (Buys-Sells).

    I am debugging with some Print statements, which print the CurrentBar and my calculated value for the preceding bar. It runs along fine for a bit until it reaches some point where it freaks out and quickly spits out some values from old bars with incorrect values in quick succession? You can see the bars in red below were already processed before hand.

    What can cause an indicator to reprocess old bars?

    ( It is possible that this only happens when I am running a strategy on top of the indicator, I haven't been able to narrow that down 100% yet. My Indicator and strategy both calculate on EachTick

    ...
    CurrentBar is 9793 delta for BarID: 9792 was: 8
    CurrentBar is 9794 delta for BarID: 9793 was: -89
    CurrentBar is 9795 delta for BarID: 9794 was: 34
    CurrentBar is 9796 delta for BarID: 9795 was: -11
    CurrentBar is 9797 delta for BarID: 9796 was: -27
    CurrentBar is 9798 delta for BarID: 9797 was: -147
    CurrentBar is 9790 delta for BarID: 9789 was: -240
    CurrentBar is 9791 delta for BarID: 9790 was: 0
    CurrentBar is 9792 delta for BarID: 9791 was: 0
    CurrentBar is 9793 delta for BarID: 9792 was: 0
    CurrentBar is 9794 delta for BarID: 9793 was: 0
    CurrentBar is 9794 delta for BarID: 9793 was: 0

    CurrentBar is 9799 delta for BarID: 9798 was: 40
    CurrentBar is 9800 delta for BarID: 9799 was: 88
    ....
    Last edited by NickyD; 11-16-2017, 11:36 AM.

    #2
    Hello NickyD,

    If you create a script that just prints Current bar (and or the time of the bar) and add the indicator directly to a chart, are you able to reproduce this behavior? (If so, let me know and I will try and reproduce on my end)

    Does your script have multiple data series?

    If this can only be reproduced using this specific script and not the test script that just prints the bar number, may we test an export of this script?

    To export a NinjaTrader 8 NinjaScript do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message

    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>


    Below is a link to the help guide on Exporting NinjaScripts.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yeah, it does not seem to happen when running the test script or my indicator alone. It only starts to happen when I enable the strategy. I guess I am doing something wrong in there.


      To your question about multiple DataSeries - Yes, the indicator has three data series, two of which are created by AddPlot and a third which I've explicitly created. All three of which are public properties of the indicator.


      I have been manually adding all the indicators I use to the chart and then loading my strategy. Is that an invalid workflow? Should I always be programatically adding the indactors the strategy references to the chart through the strategy code if I want to see them visually as well?
      Attached Files
      Last edited by NickyD; 11-16-2017, 12:40 PM.

      Comment


        #4
        Hello NickyD,

        Are you printing for all series or have you added code in your script to only print when BarsInProgress 0 is processing?

        Likely you are viewing the CurrentBars value for two different series intermittently.

        If not, you might try starting from a script that does not have the behavior and adding code to it from this script until the behavior starts to find what is causing the behavior.
        Last edited by NinjaTrader_ChelseaB; 11-16-2017, 01:34 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Sorry, I think I misunderstood what you meant by multiple Data Series... I am only using one DataSeries as input for my chart and indicator. (It's a 3 Tick Range Chart). That is the only data series that act as inputs to the indicator. The indicator has multiple properties that are defined as public Series<double> Sells, public Series<double> Buys, public Series<double> DeltaVolumes. The PRINT statements I am using only print values from the variable which underlies my public Series<double> DeltaVolumes property.

          So in that context, I don't have to worry about BarsInProgress, right?


          After I sent you the sample code, I switched the strategy code from this:

          else if (State == State.DataLoaded)
          {
          }
          else if (State == State.Historical)
          {
          myBuySell = BuySellWithCD(2);
          }

          -----------------------------------------------------------

          else if (State == State.DataLoaded)
          {
          myBuySell = BuySellWithCD(2);
          AddChartIndicator(myBuySell);
          }
          else if (State == State.Historical)
          {
          }

          The later is correct, right? It seems to have helped so far...

          Comment


            #6
            Yeah, those changes to the strategy code seemed to have fixed it, I haven't had a previous bar show up in the output since... ( a new problem popped up but I'll probably ask about that in a different thread).

            So I guess I have two final questions:
            1) Instantiating an instance of my indicator in the strategies If (State==State.Historic ) is clearly wrong, right? State.DataLoaded is where it should be since it uses current and realtime market data.

            2) Is it ok to add indicators to charts manually if the strategy is using that same indicator through code?

            Comment


              #7
              Hello NickyD,

              I would expect the call to the indicator to be the same in either State.DataLoaded or State.Historical as both are run after the data is loaded but before historical data is processed in OnBarUpdate.

              Do you have an example script that can demonstrate this is not the case?


              Yes, its fine to add any indicators to a chart manually even if a strategy is enabled on the chart. The two will not be able to communicate or interfere with each other.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Well... I am at a loss to explain anything then! Modifying the strategy code as I indicated and adding the indicator through code instead of by hand seem to have fixed the original issue, I haven't seen any old bars process a second time for almost 24hrs. Maybe I changed something else but I can't recall what it would have been. I think I'm fine now. The indicator is occasionally missing data now, but it happens in real time, I'll post a second thread if I can't figure out this new issue.

                Thanks for talking it through with me.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by funk10101, Today, 12:02 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by GLFX005, Today, 03:23 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by nandhumca, Yesterday, 03:41 PM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by The_Sec, Yesterday, 03:37 PM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by vecnopus, Today, 06:15 AM
                0 responses
                1 view
                0 likes
                Last Post vecnopus  
                Working...
                X