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

BUG, replicatable, in attached Indicator

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

    BUG, replicatable, in attached Indicator

    Hi Ninja guys,
    I have a bug for you. It was driving me absolutely nuts in developing an indicator, until I realised it was a bug and not my coding.
    I have written a simplified indicator which does nothing other than demonstrate the bug (attached).
    I have also pasted the code below for a quick look-see while you read this post.
    The bug is that when writing a value to a plot intra-bar, on the next tick of the same bar the data has been thrown away. Instead of the data, the Plot1[0] now contains the latest closing price of the instrument, and Plot1.ContainsValue(0) shows as FALSE.
    In the attached indicator, you will see I write to the indicator's plot with
    Plot1.Set(...value...)
    Then I Print() to the Output Window the value I just wrote (by reading it back from Plot1[0]) and also Print() Plot1.ContainsValue(0). Results are as they should be; I get the correct value back and a boolean value of TRUE.
    NEXT TICK, though, the value is corrupted and the boolean value is FALSE.

    Please tell me if you can replicate the bug at your end.
    I re-installed NinjaTrader this afternoon, deleting my user's data folder as well. I re-installed .Net only a fortnight ago. I am on Vista, fully up to date.
    saltminer.

    protected override void OnBarUpdate()
    {

    if (Close[0] != LastPrice)
    { // this is just a simple technique to occasionally write a value to a plot intra-bar
    LastPrice = Close[0];
    PriceChangeCount++;
    if (PriceChangeCount <10)
    return;

    PlotSomeValue(); // write to the plot in a Method
    PriceChangeCount = 0;

    }

    // each tick, display what is in the plot
    Print("At bar "+CurrentBar+", Tick by tick check: Value is "+Plot1[0]+" and ContainsValue is "+Plot1.ContainsValue(0));
    }

    private void PlotSomeValue()
    {
    Plot1.Set(CurrentBar); // just put some value in here
    // prove its in by reading the value back
    Print("At bar "+CurrentBar+", Value of "+CurrentBar+" written to Plot1... Reading back, value is "+Plot1[0]+" and ContainsValue is "+Plot1.ContainsValue(0));

    Plot2.Set(SMA(Plot1,20)[0]); // and generate a second plot that is a moving average of the first
    }
    Attached Files

    #2
    saltminer, thanks for this detailed posting, we'll look into it and get back to you.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      saltminer, please don't do the plotting in your own functions, use the OnBarUpdate() directly please and retry.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Hello,
        ok, I've changed the plotting function to be inside of the OnBarUpdate() method. I can't see what difference that should make - are we really not allowed to access plot data in a custom Method called from OnBarUpdate? Is that in the manual?
        Anyway, it made no difference. The bug still stands.
        I have attached the revised indicator for your testing. Code is pasted below, and also the print from my Output Window which shows intra-bar on bar 14299 that
        (1) the value written to the Plot disappears and is replaced by the latest price of the instrument.
        (2) Plot1.ContainsValue() changes from TRUE to FALSE

        saltminer.


        At bar 14299, Tick by tick check: Value is 944.75 and ContainsValue is False
        At bar 14299, Value of 14299 written to Plot1... Reading back, value is 14299 and ContainsValue is True
        At bar 14299, Tick by tick check: Value is 14299 and ContainsValue is True
        At bar 14299, Tick by tick check: Value is 944.75 and ContainsValue is False
        At bar 14299, Tick by tick check: Value is 944.75 and ContainsValue is False
        At bar 14299, Tick by tick check: Value is 944.5 and ContainsValue is False


        protected override void OnBarUpdate()
        {

        if (Close[0] != LastPrice)
        { // this is just a simple technique to occasionally write a value to a plot intra-bar
        LastPrice = Close[0];
        PriceChangeCount++;
        if (PriceChangeCount <10)
        return;

        Plot1.Set(CurrentBar); // just put some value in here
        // prove its in by reading the value back
        Print("At bar "+CurrentBar+", Value of "+CurrentBar+" written to Plot1... Reading back, value is "+Plot1[0]+" and ContainsValue is "+Plot1.ContainsValue(0));

        Plot2.Set(SMA(Plot1,20)[0]); // and generate a second plot that is a moving average of the first

        PriceChangeCount = 0; // reset count
        }

        // each tick, display what is in the plot
        Print("At bar "+CurrentBar+", Tick by tick check: Value is "+Plot1[0]+" and ContainsValue is "+Plot1.ContainsValue(0));
        }
        Attached Files

        Comment


          #5
          saltminer, thanks for the detailed post, could not reproduce this on my end, please check this simple sample, intrabar plotted values will stick even if conditions are not true anymore.
          Attached Files
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Hi Bertrand,
            unfortunately your indicator script is not valid to test this bug.
            Once a condition on a bar becomes true (High[0] > High[1]) it will remain true for the rest of the bar, so data will be written to the DataSeries every tick until the end of the bar.
            You are not testing what happens on subsequent ticks on the same bar when data is NOT re-written to the DataSeries.
            I have amended your indicator to use Close[0] > High[1], and Close[0] < Low[1]. This creates the opportunity for the bug to arise, which indeed it still does on my machine.
            Here is a copy/paste from my Output Window
            555 -1 True
            555 -1 True
            555 -1 True
            555 941.25 False

            Same bar, yet the value reverts to the closing price of the instrument and ContainsValue changes back to false.
            Please import my revision to your indicator (or change your own) and retry.
            Thanks,
            saltminer
            Attached Files

            Comment


              #7
              Thanks Saltminer, I'll give it a go and check on my end.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Saltminer, unfortunately I can't reproduce this here on a 49 tick chart of the September ES - Plot contains and stores the dataseries value until the new bar forms which is the expected outcome. If the condition is false you see the dummy value in the print out until the conditions hits again.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Hi Bertrand,
                  after your last post I began to wonder if it was something strange in my system. So I tried it on a different machine, this time running XP (my primary machine runs Vista).
                  Different Ninja install, obviously, and it has no fancy custom assemblies or anything on it. Everything is pretty much fresh-as-a-daisy.

                  I still see the bug occuring.

                  I have modified the indicator for you, to further help illustrate the bug.
                  First of all, please set your chart's timeframe to something longer than 49 tick. What you need to see using this indicator is a bar that achieves a higher high or lower low then retraces back inside the prior bar's range. Give it some time to do that, eg use a 610 tick.
                  Note that it must be in realtime, not Historical data.
                  The new version of the indicator keeps a record if it has written a value to the plot on this bar. If it has, and ContainsValue() returns false, it will write a very visible message to the OutputWindow and color the bar Pink on the chart. You can't miss it.

                  Please check it out one more time.
                  Thanks,
                  saltminer
                  Attached Files

                  Comment


                    #10
                    Originally posted by saltminer View Post
                    Hi Bertrand,
                    after your last post I began to wonder if it was something strange in my system. So I tried it on a different machine, this time running XP (my primary machine runs Vista).
                    Different Ninja install, obviously, and it has no fancy custom assemblies or anything on it. Everything is pretty much fresh-as-a-daisy.

                    I still see the bug occuring.

                    I have modified the indicator for you, to further help illustrate the bug.
                    First of all, please set your chart's timeframe to something longer than 49 tick. What you need to see using this indicator is a bar that achieves a higher high or lower low then retraces back inside the prior bar's range. Give it some time to do that, eg use a 610 tick.
                    Note that it must be in realtime, not Historical data.
                    The new version of the indicator keeps a record if it has written a value to the plot on this bar. If it has, and ContainsValue() returns false, it will write a very visible message to the OutputWindow and color the bar Pink on the chart. You can't miss it.

                    Please check it out one more time.
                    Thanks,
                    saltminer
                    Hello saltminer,


                    I am forwarding your reply to NinjaTrader_Bertrand and you will receive a response prior to the market open on Monday.

                    Thank you for your patience and have a great weekend!
                    Christopher J.NinjaTrader Customer Service

                    Comment


                      #11
                      saltminer thanks for the amended code, I'll recheck on a bigger timeframe chart on a different PC and let you know what I find, thanks for your efforts.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        saltminer, I could reproduce this as you state and checked with development: this behavior is unfortunately expected, as the default 'dummy' value needs to be overwritten on each tick. Thanks for your patience on this one.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Hi Bertrand,
                          thanks for that info.
                          I'd like to comment, politely, that the current design is poor.
                          saltminer

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by aussugardefender, Today, 01:07 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post aussugardefender  
                          Started by pvincent, 06-23-2022, 12:53 PM
                          14 responses
                          238 views
                          0 likes
                          Last Post Nyman
                          by Nyman
                           
                          Started by TraderG23, 12-08-2023, 07:56 AM
                          9 responses
                          383 views
                          1 like
                          Last Post Gavini
                          by Gavini
                           
                          Started by oviejo, Today, 12:28 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post oviejo
                          by oviejo
                           
                          Started by pechtri, 06-22-2023, 02:31 AM
                          10 responses
                          125 views
                          0 likes
                          Last Post Leeroy_Jenkins  
                          Working...
                          X