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

Problem with .Reset()? or with me?

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

    Problem with .Reset()? or with me?

    The following code prints out weird stuff (see printed output). The printed output shows the correct volume for bars not .Reset(); however, .Reset() values print out as the Close of that bar. I am not currently connected to a data source so all values are historic. The same thing happens if I add the Print Statement Loop to System Indicator VolumeUpDown.

    #region Variables
    private int mAPeriods = 9;
    private DataSeries upVolumeSeries;
    private DataSeries downVolumeSeries;
    #endregion

    protected override void Initialize()
    {
    upVolumeSeries = new DataSeries(this);
    downVolumeSeries = new DataSeries(this);
    }

    if (Close[0] >= Open[0])
    {
    upVolumeSeries.Set(Volume[0]);
    downVolumeSeries.Reset();
    }
    else
    {
    downVolumeSeries.Set(Volume[0]);
    upVolumeSeries.Reset();
    }

    for (int index = 0; index <= mAPeriods; index++)
    {
    Print("Bar: " + (Bars.BarsSinceSession - index+1) + " Up " + UpVolume[index] + " Down " + DownVolume[index]);
    }

    #region properties
    [Description("Numbers of bars used for EMA calculations")]
    [Category("Parameters")]
    [Gui.Design.DisplayName("Periods, EMA")]
    public int MAPeriods
    {
    get { return mAPeriods; }
    set { mAPeriods = value; }
    }

    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries UpVolume
    {
    get { Update();
    return upVolumeSeries; }
    }

    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries DownVolume
    {
    get { Update();
    return downVolumeSeries; }
    }
    #endregion


    Printed Output

    Bar: 529 Up 82.97 Down 290
    Bar: 528 Up 83.02 Down 309
    Bar: 527 Up 83.08 Down 183
    Bar: 526 Up 436 Down 83.1
    Bar: 525 Up 83.01 Down 182
    Bar: 524 Up 83.09 Down 987
    Bar: 523 Up 83.19 Down 570
    Bar: 522 Up 1081 Down 83.29
    Bar: 521 Up 839 Down 83.28
    Bar: 520 Up 335 Down 83.21
    Bar: 519 Up 348 Down 83.1

    #2
    just make a IsValidPlot check.

    Comment


      #3
      .Reset() is more a vusual artifice to remove the visual plot from the chart than anything else. Apparently if the Plot() is invalidated, NT just uses the Close for the value. You may want to make a check if the value is really valid, using the ContainsValue property. Earlier documentation of .Reset() said that the value is put to zero. Either that has changed, or the original documentation is still in error.

      Comment


        #4
        Not a plot

        I am storing the values in a DataSeries to use with a Moving Average calculation. If it is storing Close values, it will screw up the MA calcs.

        Comment


          #5
          ContainsValue is a property of the DataSeries class, of which Plot() is a special variety.Just make the check, and omit that value if ContainsValue returns false.

          Comment


            #6
            I eliminated the .Reset(), since I am not plotting the value, and replaced it with a simple .Set(0).

            Thanks for walking me through this, but I think there is still a problem with the Reset() function, NT staff should look into.

            Snap

            Comment


              #7
              Same error here blocking correct results when using indicator dialog window for input

              Originally posted by snaphook View Post
              Thanks for walking me through this, but I think there is still a problem with the Reset() function, NT staff should look into.

              Snap
              I'm experiences the same flaw. I use .Reset() in what I call indicator #1. However the effective value in indicator #2 (using input from indicator #1) defaults to Close[0], a value I have absolutely no use for even though it MAY be identical to the correct value now and then.

              In my case, I am using the indicator dialog window to get the value of an indicator #1 as input to another indicator #2. There's absolutely no way to validate wether Input is valid or not in indicator #2. No method that I can find at least. I certainly cannot use ContainsValue() as my input is Inputs[0] which do not have that method, and ValidPlot() is useless as well since it checks for wether Close[0] is valid and doesn't give the correct results.

              If I do:
              DataSeries DS = new ...
              DS.Set(10.0);
              DS.Reset();

              It makes no difference. Indicator #2 somehow uses Close[0] anyways, leaving me with no sane method to detect invalid values in inputs[0] in indicator #2.

              Comment


                #8
                Hi steeltoe,

                Thanks for the post. Can you please clarify if you are having issues with Input[0] or Inputs[0]. Inputs, with the s is not a supported property.

                Using Inputs won't provide any convenience for changing the input series of a secondary series. It will compile and produce a value, but the best practice is using Closes[1][0] instead.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Input[0] not Inputs

                  Originally posted by NinjaTrader_RyanM View Post
                  Hi steeltoe,

                  Thanks for the post. Can you please clarify if you are having issues with Input[0] or Inputs[0]. Inputs, with the s is not a supported property.

                  Using Inputs won't provide any convenience for changing the input series of a secondary series. It will compile and produce a value, but the best practice is using Closes[1][0] instead.
                  It is Input[0]. I meant to say Input[0] to state I do not have access to the real DataSeries object.

                  Not an Inputs-issue.

                  Comment


                    #10
                    Originally posted by steeltoe View Post
                    I'm experiences the same flaw. I use .Reset() in what I call indicator #1. However the effective value in indicator #2 (using input from indicator #1) defaults to Close[0], a value I have absolutely no use for even though it MAY be identical to the correct value now and then.

                    In my case, I am using the indicator dialog window to get the value of an indicator #1 as input to another indicator #2. There's absolutely no way to validate wether Input is valid or not in indicator #2. No method that I can find at least. I certainly cannot use ContainsValue() as my input is Inputs[0] which do not have that method, and ValidPlot() is useless as well since it checks for wether Close[0] is valid and doesn't give the correct results.

                    If I do:
                    DataSeries DS = new ...
                    DS.Set(10.0);
                    DS.Reset();

                    It makes no difference. Indicator #2 somehow uses Close[0] anyways, leaving me with no sane method to detect invalid values in inputs[0] in indicator #2.
                    I believe that Inputs does not work as one would think, which is maybe why it is unsupported. You will have to use a workaround to set an input, based on the Price'Type.

                    Here is an example. See if it helps.

                    ref: http://www.ninjatrader.com/support/f...ight=PriceType

                    Comment


                      #11
                      Originally posted by koganam View Post
                      I believe that Inputs does not work as one would think, which is maybe why it is unsupported. You will have to use a workaround to set an input, based on the Price'Type.

                      Here is an example. See if it helps.

                      ref: http://www.ninjatrader.com/support/f...ight=PriceType
                      Unfortunately, this does not help me. I am not assigning the data series through code. I am assigning the data series through the indicator dialog window, in the way stated in the first post. Unless I'm missing something, plain vanilla NT7 should be able to give me the Input from any other indicator or dataseries as is user-selectable in the indicator dialog window.

                      However, when choosing data from another indicator (indicator #1), my only input parameter is Input[0] in indicator #2. How to check wether Input[0] contains valid data or not?
                      Last edited by steeltoe; 11-17-2011, 02:46 PM.

                      Comment


                        #12
                        You should be able to use .IsValidPlot with Input. One difference here is that this method needs the bar index to check. CurrentBar can be used like in this example:

                        if (Input.IsValidPlot(CurrentBar))
                        Plot0.Set(Input[0]);

                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_RyanM View Post
                          You should be able to use .IsValidPlot with Input. One difference here is that this method needs the bar index to check. CurrentBar can be used like in this example:

                          if (Input.IsValidPlot(CurrentBar))
                          Plot0.Set(Input[0]);

                          http://www.ninjatrader.com/support/h...dataseries.htm
                          Hi. Thanks for the reply.

                          This is exactly how I'm doing the check and it "works" as long as any value is set in indicator #1. However, if the source indicator (#1) object has .Reset() its Plot-value for that bar, then Input.IsValidPlot(CurrentBar)) still returns true.

                          It seems instead of detecting missing Input, Input[0] is allocated the value of Close[0], and that's what being plotted and checked against. So there's no way for me to get the original value being plotted, when it's been Reset(). It kinda works when there is a value though, but how can you trust it when suddenly it might be Close[0]?

                          Even when trying to override the "default value" in indicator #1 I get the exact same results:
                          DS.Set(10.0);
                          DS.Reset();

                          Which means I've overridden the "default value" according to another posting here, I'm still getting Close[0] as Input[0] in my indicator #2 and no methodology of checking for missing value or not.

                          Of course, this destroys any credibility of Input[0], since it may at any time be set arbitrarily to Close[0]. I'm very sure I'm not doing anything wrong here, but will be happy to try suggestions. However, if you can reproduce this behaviour, I'm sure it should be a fixable bug as my setup is pretty simple. I've noticed this odd behaviour before, and I've never noticed this ever been working correctly.

                          It's just that now I need to Reset() a plot-value in an indicator, and also need to detect that in another. I also like to add that indicator #2 is a general-purpose indicator, which is why I need to select its Input from the indicator dialog window. Indicator #2 does not know anything about indicator #1, and should not need to.

                          I also like to add that you can workaround this with the workaround the original poster explained, however then your plots will be messed up as you'll have to set some bogus value for detection. I fully agree with the original poster this is a bug, and the workaround is quite unsettling as it would have to be supported by all your indicators.
                          Last edited by steeltoe; 11-17-2011, 03:19 PM.

                          Comment


                            #14
                            Thanks for following up steeltoe. Do you have example scripts where I'm able to see what you are running into? I'm not yet sure how this needs to be setup. Can you please also include the sequence of applying indicators and selecting input series.
                            Ryan M.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by gentlebenthebear, Today, 01:30 AM
                            2 responses
                            13 views
                            0 likes
                            Last Post gentlebenthebear  
                            Started by Kaledus, Today, 01:29 PM
                            2 responses
                            7 views
                            0 likes
                            Last Post Kaledus
                            by Kaledus
                             
                            Started by frankthearm, Yesterday, 09:08 AM
                            13 responses
                            45 views
                            0 likes
                            Last Post frankthearm  
                            Started by PaulMohn, Today, 12:36 PM
                            2 responses
                            16 views
                            0 likes
                            Last Post PaulMohn  
                            Started by Conceptzx, 10-11-2022, 06:38 AM
                            2 responses
                            56 views
                            0 likes
                            Last Post PhillT
                            by PhillT
                             
                            Working...
                            X