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

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 geotrades1, Today, 10:02 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by ender_wiggum, Today, 09:50 AM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by rajendrasubedi2023, Today, 09:50 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by bmartz, Today, 09:30 AM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by geddyisodin, Today, 05:20 AM
      3 responses
      26 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X