Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Retrieve Data from Screen (or Drawing Objects box)

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

    Retrieve Data from Screen (or Drawing Objects box)

    Hi,

    I am creating a strategy that needs to access drawing objects I have manual drawn on a chart. We can assume those drawing objects are rectangles for this example. I would like to only to only print the name of the rectangle that starts before the current bar and ends after the current bar. I can't seem to figure out how to do this. So far I can loop through all of the objects something like below but I would like to ignore all the rectangles that came before.


    if (DrawObjects.Count > 0) {
    foreach (DrawingTool draw in DrawObjects.ToList())
    {
    if (draw is DrawingTools.Rectangle)
    {
    Print ("Tag name: "+draw.Tag);​

    Any help to get me going in the right direction would be appreciated.

    Thanks!

    #2
    Hello jamestrades,

    Thanks for writing in.

    Detecting information from manually drawn objects on a chart could be accomplished by looping through the DrawObjects collection and checking if draw.IsUserDrawn in the script.

    Please see the third section of sample code on this help guide page demonstrating detecting manually drawn objects on a chart.

    DrawObjects: https://ninjatrader.com/support/help...ub=drawobjects

    And, see this help guide page about what values could be accessed from a draw object: https://ninjatrader.com/support/help...rawingtool.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      I suppose you mean how to access its coordinates to compare them to the current bar time, you might try this to read a rectangle coordinates:
      Code:
      foreach ( DrawingTool draw in DrawObjects.ToList() )
      {
          if ( draw is DrawingTools.Rectangle )
          {
              if ( draw.IsUserDrawn )
              {
                  // create a variable to hold a ref to the rectangle object beeing processed
                  DrawingTools.Rectangle myRect = draw as DrawingTools.Rectangle;
                  // apply a filter
                  if ( myRect.Tag.Trim('@').StartsWith("abc") == true) {
                      //---------------
                      string aLine = "";
      
                      aLine += myRect.StartAnchor.Time.ToString("yyyy-MM-dd HH:mm:ss") + "\t";
                      aLine += myRect.StartAnchor.Price.ToString("G", CultureInfo.InvariantCulture) + "\t";
                      aLine += myRect.EndAnchor.Time.ToString("yyyy-MM-dd HH:mm:ss") + "\t";
                      aLine += myRect.EndAnchor.Price.ToString("G", CultureInfo.InvariantCulture);
                      Print( aLine );
                  }
              }
          } //end if ( draw is ...            
      } //end foreach​

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      62 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      134 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 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
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X