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

Looping through DrawObjects odd behaviour

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

    Looping through DrawObjects odd behaviour

    I am looping through all the DrawObjects on my chart and I am noticing that testing whether a DrawObject is a particular type doesn't always work. These are all user drawn Rays and they were all drawn at the same time using the defaults.
    Code:
    if (draw is DrawingTools.Ray || draw is DrawingTools.Line) {
    					ChartAnchor c = ((NinjaTrader.NinjaScript.DrawingTools.ChartAnchor[])(draw.Anchors))[0];
    					ChartAnchor c2 = ((NinjaTrader.NinjaScript.DrawingTools.ChartAnchor[])(draw.Anchors))[1];
    					
    					//runCalc2(c.Time, c.Price);
    					Stats s = new Stats(c.Price,c2.Time);
    					s.runCalc2(TickSize,BarsArray[0],false);
    					
    				}


    The object type looks like it is a Ray, but that Ray never enters the if statement block

    #2
    Hello habibalex,

    I would recommend comparing the IDrawObject to IRay.

    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      would this be the same for NT8?

      Comment


        #4
        Hello habibalex,

        The classnames are different for NinjaTrader 8.



        This thread is posted in the NinjaTrader 7 Indicator Development section, was your original question for NinjaTrader 8?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          yes sorry it was supposed to be in the NT8 forum

          Comment


            #6
            Hello habibalex,

            I've remade this for NinjaTrader 8.

            Using this test script are you able to reproduce this behavior?
            (The test script will print the tagname and start time of all rays already on the chart)
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Yes I can reproduce. I made the following change to your code

              I made the rays in 1 chart using the CME US INDEX FUTURES ETH template. Rays are drawn on all charts globally.

              Then I opened a different chart and added your indicator.



              Code:
              foreach (DrawingTool draw in DrawObjects)
              			{
              				// Finds line objects that are attached globally to all charts of the same instrument
              				if (draw is DrawingTools.Ray)
              				{
              					Ray ray = (Ray)draw;
              
              					Print(string.Format("{0} | {1}", ray.Tag, ray.StartAnchor.Time));
              				}else if(draw.GetType().Name == "Ray"){
              					Print(draw.Tag + " draw is NOT a DrawingTools.Ray");
              				}
              			}
              HTML Code:
              @Ray 19 draw is NOT a DrawingTools.Ray
              @Ray 23 draw is NOT a DrawingTools.Ray
              @Ray 27 draw is NOT a DrawingTools.Ray
              @Ray 18 draw is NOT a DrawingTools.Ray
              @Ray 22 draw is NOT a DrawingTools.Ray
              @Ray 26 draw is NOT a DrawingTools.Ray

              Comment


                #8
                Hello habibalex,

                Each time I add the indicator the first time (without modifying the script) I am unable to reproduce this behavior.

                But I am able to reproduce if I make a change to the script and compile and then remove and re-add the script.

                Also, I am seeing some different behavior when reloading ninjascript (F5).

                I've made a video and reported the behavior to our development.
                Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


                Once I have a tracking ID for the behavior I will post in this thread.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello habibalex,

                  I've received a tracking ID for this behavior.

                  This issue is being tracked with ID #NTEIGHT-11857.

                  There are two issues. Here's the skinny.

                  First, when the chart is reloaded the DrawObjects collection does no longer hold the old instances of objects, but neither does it hold the new instances yet.

                  The work around is to detect the objects after they are added to the collect in real-time.

                  Below is a link to an example.



                  Second, as the script is compiled a temporary assembly is created (so as to not interrupt the scripts currently running) including the objects that are on the charts. Because of this, the cast does not work until nt is restarted.

                  The workaround is to use the dynamic type and compare the ToString() to the full namespace.
                  Code:
                  foreach (dynamic ray in DrawObjects)
                  {
                  	// Use ToString().Equals() to detect the object's Type 
                  	if (ray.ToString().Equals("NinjaTrader.NinjaScript.DrawingTools.Ray"))
                  	{
                  		// Access the object by assuming that it is the Type we expect
                  		Print(String.Format("Ray {0} detected!", ray.Tag));
                  	}
                  }
                  This is shown in our help guide.
                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by RookieTrader, Today, 07:41 AM
                  2 responses
                  7 views
                  0 likes
                  Last Post RookieTrader  
                  Started by kujista, Today, 05:44 AM
                  2 responses
                  12 views
                  0 likes
                  Last Post kujista
                  by kujista
                   
                  Started by trilliantrader, Today, 08:16 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post trilliantrader  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  9 responses
                  175 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by funk10101, Today, 08:14 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post funk10101  
                  Working...
                  X