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

DrawObjects are always null

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

    DrawObjects are always null

    Hi,
    I got some manually drawn objects on my chart and I need to get time and price of them. I do it like this:

    Code:
    foreach (IDrawingTool draw in DrawObjects.ToList()) //safe copy
    {
    if (!draw.IsUserDrawn || draw.IsSelected) continue;
    
    if (draw.ToString().Equals("NinjaTrader.NinjaScript.DrawingTools.ArrowUp"))
    {
    ArrowUp up = draw as DrawingTools.ArrowUp;
    if (up != null)
    {
    DateTime time = up.Anchor.Time;
    double price = up.Anchor.Price;
    //do something
    }
    }
    }
    The problem is that they always stay null.
    If I draw another arrow this code works and I can get time and price but it doesn't for previous drawn arrows. If I refresh indicator all arrows become null again.

    #2
    the way I would do it is use a double as the place to store the X another to store the Y placement and use that in the obj line. Then use a secondary double that instantiates when the obj gets drawn, & then you need to have that secondary double nullified at some point after when it is not in use, but that way you can use the secondary store as a conditional store of value when you do something & can call that double.
    That way you can state that if (draw.line() != null && secondaryStore > 0) { //do something } adding a layer to check that both the obj is placed and that the value is stored.
    Last edited by LoganJKTrader; 09-09-2022, 09:09 AM.

    Comment


      #3
      Hello Leeroy_Jenkins,

      From the given code I don't see that you are using an prints to address what specifically is happening. You would need to use prints at each of your conditions to better understand what the problem is. Keep in mind that the draw object collection only works going forward in realtime and may take a few bars before its available to your indicator. It is not directly tied to the indicators loading process because that is a collection from the chart and not from the indicator directly.

      JesseNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by TraderBCL, Today, 02:37 AM
      0 responses
      1 view
      0 likes
      Last Post TraderBCL  
      Started by mangel2000, Today, 02:23 AM
      0 responses
      3 views
      0 likes
      Last Post mangel2000  
      Started by mangel2000, Today, 01:30 AM
      0 responses
      8 views
      0 likes
      Last Post mangel2000  
      Started by Doxxxx, Today, 01:24 AM
      0 responses
      5 views
      0 likes
      Last Post Doxxxx
      by Doxxxx
       
      Started by ezekilany, Today, 01:10 AM
      0 responses
      4 views
      0 likes
      Last Post ezekilany  
      Working...
      X