Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnRender prevented from running

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

    OnRender prevented from running

    I am using an indicator called ATR8 to provide values for a trailing stop.

    I modified Chelsea_B's Example code for attaching to an indicator and have run into an issue I don't understand.
    Surprisingly this runs in ONRender which is unusual but works for the purpose I need _ if I try to run it in ONBarUpdate I get
    different values as the indicator calculates.OnBarClose but this code runs onEachTick.


    Code:
     double Displace = TickSize * Offset;
                        if ( Direction > 0)
                            {
                                
                                //if(indicator.Values[0].IsValidDataPoint(index))// prevents values updating
                                    IndieValue = Instrument.MasterInstrument.RoundDownToTickSize(indicator.Values[0].GetValueAt(index));
                                    UsedValue = IndieValue - Displace;
                            }
                        ​


    If I include the check for data validity the code no longer works but doesn't fail or give any errors.

    It seems good practice to check if in fact there is a valid data point but I can't work out why it would fail?

    Any help or advice appreciated.

    #2
    Hello Mindset,

    Thank you for your post.

    Can you please provide more details, what exactly is failing and in what way is it failing?

    To confirm, this code is located in OnBarUpdate and not OnRender, correct?

    Comment


      #3
      Did you see the warning:
      Warning: Calling IsValidDataPoint() will only work a MaximumBarsLookBackInfinite series. Attempting to check IsValidDataPoint() MaximumBarsLookBack256 series throw an error. Please check the Log tab of the Control Center. In addition since this method references BarsAgo data, and therefore cannot be used during OnRender (see note 5).- instead please use the IsValidDataPointAt during OnRender.​

      Comment


        #4
        Hi Gaby



        The code runs in OnRender() and calls from an Indicator called "A".


        It has to run in ONRender as the value from the indicator "A" is Calculate.OnBarClose whereas the hosting indicator
        runs Calculate.OnEachTick - and I could not get an instance of the "A" indicator to play pretty even when I explicitly set the Calculate state.


        The red condition silently fails - without it it still works so I am good but I can't see why it causes the code to fail.

        if (indicator.Values[0].Count <= index || indicator.Values[1].Count <= index] &&(indicator.Values[0.IsValidDataPoint(index) || indicator.Values[1].IsValidDatPoint(index)) //this fails​
        Code:
                        #region TrailStop
                        if (!trailUpdateEnabled)
                            return;
                    
                        int index = ChartBars.ToIndex - 1;
                        double displace = TickSize * TrailOffset;
                        
                        lock (chartControl.Indicators)
                        {
                            foreach (var indicator in chartControl.Indicators)
                            {
                                if (indicator.Name == "\"A\"" && indicator.State == State.Realtime)
                                {
                                     if (indicator.Values[0].Count <= index || indicator.Values[1].Count <= index]  [COLOR=#e74c3c]&&(indicator.Values[0.IsValidDataPoint(index) || indicator.Values[1].IsValidDatPoint(index))[/COLOR] //this fails
                                     {            
                                        Draw.TextFixed(this,"DLDK","Index error",TextPosition.BottomRight);
                                          return;       // ❗ Prevents out-of-range crash
                                     }          
                  
                                if (Direction > 0)
                                {
                                    IndieValue = Instrument.MasterInstrument.RoundDownToTickSize(indicator.Values[0].GetValueAt(index));
                                    UsedValue = IndieValue - displace;
                                }
                                else if (Direction < 0 )
                                {
                                    IndieValue = Instrument.MasterInstrument.RoundDownToTickSize(indicator.Values[1].GetValueAt(index));
                                    UsedValue = IndieValue + displace;
                                }
                                    if(ShowPrints)
                                    {
                                        Draw.TextFixed(this, ":DP:DP",
                                    $"Indie Value = {IndieValue:N2}\nPrior Value = {priorValue:N2}\nUsed Value = {UsedValue:N2}",
                                    TextPosition.TopRight);
                                    }
                    
                                if ((IndieValue != priorValue || priorValue != UsedValue) && IndieValue > 1000)
                                {
                                    priorValue = IndieValue;
                                    trailUpdateEnabled = true;
                                    Find_Trail_Order_Type();  // will internally call UpdateTrailOrder()
                                }
                            }
                        }
            }
            #endregion
        ​

        Comment


          #5
          Hello Mindset,

          The hosted indicator will adopt the Calculate setting of the hosting script.

          Could you please be more specific, what do you mean it "silently fails? How exactly is it failing? Are you just not seeing the condition trigger, are you seeing an error, or something else?

          Comment


            #6
            Originally posted by MiCe1999 View Post
            Did you see the warning:
            Warning: Calling IsValidDataPoint() will only work a MaximumBarsLookBackInfinite series. Attempting to check IsValidDataPoint() MaximumBarsLookBack256 series throw an error. Please check the Log tab of the Control Center. In addition since this method references BarsAgo data, and therefore cannot be used during OnRender (see note 5).- instead please use the IsValidDataPointAt during OnRender.​
            HI

            Yes I found that but IsValidDataPointAt didn't work either.
            My check is indicator.Values[0].Count <= index so at least there is something there to validate the data point.

            It's annoying that if you try to access a series value that is set to Calculate.OnBarClose when the hosting indicator is Calculate.OnEachTick doesn't seem to work.

            Comment


              #7
              Originally posted by NinjaTrader_Gaby View Post
              Hello Mindset,

              The hosted indicator will adopt the Calculate setting of the hosting script.

              Could you please be more specific, what do you mean it "silently fails? How exactly is it failing? Are you just not seeing the condition trigger, are you seeing an error, or something else?
              I wasn't clear. Whilst I would expect the hosting indicator to calculate as it's set I was under the impression that i could change the calculation if for example i was calling an indicator value that I only wanted on every bar close. This appears not to be the case.

              Silently fails means it compiles,runs, doesn't produce any errors, but does NOT compute the value as the IsValidData check screws up the logic somehow. And as Mice1999 pointed out IsValidDataAt which should be used in OnRender doesn't work either.



              So in simple terms I am trying to get a value (IndieValue) which fails because of this check - without the check ,it works,

              Comment


                #8
                Hello Mindset,

                Thank you for clarifying.

                So in simple terms I am trying to get a value (IndieValue) which fails because of this check - without the check ,it works,
                IsValidDataPoint() does not obtain an indicator value, it returns a bool (true or false). When true, it indicates that specified data point is set, otherwise it is false.

                Please see the documentation below.



                If you're trying to get a value, use GetValueAt().

                Comment


                  #9
                  Gaby

                  Have you read the code? Your response makes no sense.

                  I am checking if the indicator value is a validdatapoint which is a boolean condiiton.

                  It is not working here - that's my query.

                  Comment


                    #10
                    Yes, I did read your code. I am responding to your statement below.

                    So in simple terms I am trying to get a value (IndieValue) which fails because of this check - without the check ,it works,

                    If the check isn't working, I recommend debugging. From a basic sample script with no longer logic, IsValidDataPointAt() and .GetValueAt() works from OnRender to obtain an indicator value.
                    Attached Files

                    Comment

                    Latest Posts

                    Collapse

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