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

Printing DrawingTools Anchor

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

    Printing DrawingTools Anchor

    In NT8, I am having trouble with the following code:

    Code:
    Print(Message); //Hello World!
    				
    				foreach (DrawingTool draw in DrawObjects)
    				{
    					if (draw.GetType().Name == "Dot")
    						{
    						Print("Dot");
    						Print(draw.GetType());					
    						Print("Dot2");
    						DrawingTools.Dot myDot = draw as DrawingTools.Dot;
    						[B]Print(myDot.Anchor.Price); [/B]
    				}
    Hello World!
    Hello World!
    Dot
    NinjaTrader.NinjaScript.DrawingTools.Dot
    Dot2
    Strategy 'Test2': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.
    After Dot2 I can't get what I really need, to print (myDot.Anchor.Price)

    #2
    Hello,

    Thank you for the post.

    I do see this syntax working in OnBarUpdate, can you tell me which state in the script you are currently using this? Based on the error you will likely need to move the logic to a later state, for example if this was in Configure you may need to move it to Historical or DataLoaded potentially.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Tried again in OnBarUpdate

      As usual, a speedy reply from NinjaTrader!

      Tried again in OnBarUpdate, still get the error unfortunately:

      Hello World!
      Dot
      NinjaTrader.NinjaScript.DrawingTools.Dot
      Dot2
      Strategy 'Test2': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.
      for example if this was in Configure you may need to move it to Historical or DataLoaded potentially.
      The code was previously in Configure, how can I create a section for Historical or DataLoaded please?

      Comment


        #4
        Hello,

        Had you completely removed the indicator from the chart and re added it? If not you may be seeing the previous instance still. Like NT7's Initialize, changes to OnStateChange may require removing/adding the script.

        Does this resolve the error? If not can you provide the sample you are working with as an export? Also could you tell me is this a dot you are drawing manually on the chart or is this generated from code?

        To create additional states you can either add an if statement to OnStateChange():

        Code:
        protected override void OnStateChange()
        {
        	if (State == State.SetDefaults)
        	{
        	} 
        	else if (State == State.Historical)
        	{
        		
        	}
        }
        Or in OnBarUpdate, you can check for each bar what the State object equals:

        Code:
        if(State == State.Historical)
        {
        
        }
        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          How do I get the chart anchor for a dot. I tried the following below but the intellisense doesnt recognize the ".Anchor" only ".Anchors" which prints "NinjaTrader.NinjaScript.DrawingTools.ChartAnc hor[]" in the output window.

          I would like to get the bar it is drawn on.

          foreach(DrawingTool drawn in DrawObjects)
          {
          if(drawn.Tag.Contains("Dot"))
          {
          drawn.????????
          }
          }
          EDIT

          I figured it out, I'll leave this here just incase someone else needs it

          PHP Code:
                  public void DeleteDots()
                  {
                      List<
          stringdotsToDelete = new List<string>();
                      
                       foreach(
          DrawingTool drawn in DrawObjects)
                      {
                          if(
          drawn.Tag.Contains("Dot"))
                          {
                              foreach(
          ChartAnchor anchor in drawn.Anchors)
                                  if(
          anchor.Time DateTime.Now.AddHours(-12))  dotsToDelete.Add(drawn.Tag);
                          }
                      }
                      
                      
                      foreach(
          string dot in dotsToDelete)
                      {

                          
          base.RemoveDrawObject(dot);    
                      }
                  } 
          Last edited by cutzpr; 07-18-2018, 07:39 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Lumbeezl, 01-11-2022, 06:50 PM
          31 responses
          817 views
          1 like
          Last Post NinjaTrader_Adrian  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          5 responses
          14 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by swestendorf, Today, 11:14 AM
          2 responses
          6 views
          0 likes
          Last Post NinjaTrader_Kimberly  
          Started by Mupulen, Today, 11:26 AM
          0 responses
          6 views
          0 likes
          Last Post Mupulen
          by Mupulen
           
          Started by Sparkyboy, Today, 10:57 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X