Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy -Indicator Dataserie

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

    Strategy -Indicator Dataserie

    I'm having problems with this code breaking

    " When working with indicators in a strategy, if you run into exceptions or returns of unexpected
    values, make sure you have followed the new .Set() requirements discussed above in General.
    Also ensure that Update() is called in any method within your indicator that returns values."

    Do you have any example, or you can point me to more info

    #2
    "When working with custom DataSeries objects, do NOT access a DataSeries value on a bar
    where you have not called DataSeries.Set() since you can run into exceptions
    o It is advisable to always call .Set() and use a default value you can filter for in your
    code even on the bars you do not wish to set a value for"

    This is not very clear for me some kind of example or snippet will be great

    Comment


      #3
      No values in a DataSeries will be set unless you set them. Not just custom DataSeries but also an indicator's output DataSeries. You can only refer to values which you have set, otherwise it will cause an error. You can run into this issue if you are doing lookbacks into any Data Series where the values aren't always set.

      Suppose you have an indicator which doesn't start creating output until after some number of bars, so lookbacks aren't guaranteed to contain a value. If there is an error, you want to repeat the last bar's output if there was one. You need to check to make sure the last bar's output contains a value. If you refer to it and it was never set, you will get an error.


      Code:
      if (denominator != 0)  // check for divide by zero
      	Value.Set(numerator / denominator);
      else	// avoid divide by zero exception
      	if ((CurrentBar > 0) && (Value.ContainsValue(1)))		
      		Value.Set(Value[1]); // Repeat last output value

      Comment


        #4
        Hello,

        Thanks for the assist kdoren.

        Let me know if I can be of further assistance.
        BrettNinjaTrader Product Management

        Comment


          #5
          Originally posted by NinjaTrader_Brett View Post
          Hello,

          Thanks for the assist kdoren.

          Let me know if I can be of further assistance.
          Thanks kdoren for the tips, My strategy is strip down to the minimum, my indicator work standalone without problems, is only when i call my indicator from my strategy that I have problems, i will continue looking for them.

          Regards

          Comment


            #6
            When an indicator's output is passed to a strategy or to another indicator, if any values were not set, instead of throwing an exception NT7 will insert the closing price for that bar in place of the missing value. In my opinion this is a very bad choice, it can result in bizarre behavior. I don't remember for sure, but I think the ContainsValue() method might not work in the context of your strategy, i.e. if the indicator didn't set an output value, NT7 will substitute the closing price, and I think if your strategy calls ContainsValue to check it will return true instead of false like it should.

            Comment


              #7
              Originally posted by kdoren View Post
              I think if your strategy calls ContainsValue to check it will return true instead of false like it should.
              I think that's the problem I have right now :-(

              Comment


                #8
                Originally posted by PrTester View Post
                I think that's the problem I have right now :-(
                PrTester, would you have a simple snippet to check into?

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                600 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                347 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                103 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                558 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                558 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X