Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What causes anchor.SlotIndex to evaluate to -1?

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

    What causes anchor.SlotIndex to evaluate to -1?

    Hello.

    I am working within OnRender(), and attempting to find the location of various user drawn objects on the chart, and report the time, price, and specifically the bar location.

    I am using Anchor.SlotIndex, rounding it, and then converting it to an int.

    The odd thing is that it work some times. There are other times, where it seems to evaluate to -1. It does not seem to come from objects that are off the time scale, so I'm not sure WHERE this error is coming from?

    I saw in the docs, somewhere speaking of -1, but I do not remember where it was?

    Are there any known reasons why this would evaluate to -1?

    Context of the foreach loop I am doing is attached.



    #2
    Hello forrestang,

    Definitely do not do this in OnRender(). Do this in OnBarUpdate or any other method than OnRender().

    A negative -1 index would imply to me that the anchor is not associated with a chart bar. Are you able to print the anchor.Time? Does this correspond with a bar on the chart?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      My script was simply one where it would record times/prices from manually drawn arrows I placed on a chart. I place two same direction arrows on each bar, representing an entry/stop price. I added logic to EXPECT two arrows per bar, and for some reason my script would find an arrow where I hadn't drawn one. Due to this expected logic, if there was not two arrows on the same bar, it would break.

      I am using this on historical charts, usually w/no data connection, so I used onRender(), as onBarUpdate() requires an incoming tick to run once. So that's why I used onRender(), and created virtual bar series with Lists.

      There was an option to create some type of button, and create logic to force it to run once, but I didn't want to go that route just yet.

      I was getting intermittent behavior and it was difficult to isolate.

      I.e., it would work fine, but upon a restart of the platform, or if I duplicated the chart to a new window... it would break.

      The issue was indeed the bar index.

      I managed to find where it was producing odd values, and due to the weird logic I had it would break occasionally. I added a check to ensure this value is never -1.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      56 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      133 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X