Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Retrieving Horizontal Lines from .xml file

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

    Retrieving Horizontal Lines from .xml file

    If I have Horizontal Lines stored in the NinjaTrader 8-> templates-> GlobalDrawingObject folder in the .xml files. How can I retrieve them for a strategy? I don't need to draw the lines, I just need their values. I have both ES and NQ .xml files.

    #2
    Hello RJBen,

    There is no built in way to retrieve those files from NinjaScript, your strategy would need to draw the line to know its values or the line would have to be drawn on the chart where the strategy is running so you can access it from the charts object collection. https://developer.ninjatrader.com/do...op/drawobjects

    Comment


      #3
      That will work perfectly Jesse! And thank you so much for the DrawObjects link. Problem solved.
      Last edited by RJBen; 01-26-2025, 08:46 AM.

      Comment


        #4
        I'm trying to create an Indicator that just prints all of the Global Horizontal Lines for an Instrument to the Output Window. It doesn't have any parameters or Inputs. It just gets their values, I have several, and prints them. I'm trying to set it up in the NinjaScript Editor.
        I'm looking at the DrawObjects and want their values regardless of their tag.
        As I have several I understand it needs a foreach loop as it prints each.
        I'm stuck because in the DrawObjects examples for "Looping through the collection to find specific draw objects" I'm not sure which are system and which are User names.
        Can you help clarify?
        Thanks​

        Comment


          #5
          Hello RJBen,

          It is not clear what you are asking here, what do you mean by " I'm not sure which are system and which are User names."

          Are you asking which are global lines or user drawn vs script drawn lines?

          Comment


            #6
            Hi Jesse, in the example: foreach (DrawingTool draw in DrawObjects.ToList())
            is DrawingTool a Variable?
            is draw a NinjaTrader system tool?
            I'm trying to figure out what I have to add and what are system recognized inputs.
            Last edited by RJBen; 01-27-2025, 03:11 PM.

            Comment


              #7
              Hello RJBen,

              The page I had linked has a sample of using the loop. In that sample the variable for each iteration of the loop is named draw, that would be how to access the properties of the object being looped at that time.

              A drawing object is not a bool, its an object that has many properties.

              I am not sure what you are asking to add, what specifically are you trying to do?

              Comment


                #8
                I needed to do as much of my own homework first before putting too much resource dependence on NinjaTrader Customer Service- as awesome as you and your team members are. That said, What to code is one thing, How to code it is another. I'm trying to create an Indicator that just prints all of the Global Horizontal Lines (GHLs) for an Instrument to the Output Window. The GHLs are on the chart. I want to add the Indicator to the chart and have the values print. Here is all of the info, I think.

                All of the Horizontal Lines are Global, ie. bool IsGlobalDrawingTool HLgdt = true

                Jesse I'm not sure of the difference between DrawBy; IsAttachedToNinjaScript; <ChartAnchor>.IsNinjaScriptDrawn; and <ChartAnchor>.DrawingTool.
                It seems they are all asking the same thing.
                All of the Horizontal Lines are NinjaScript generated (from an Indicator) and each has its own tag.

                For ChartAnchor Properties, I think the one I need is:
                <ChartAnchor>.Price
                The GHLs were added on different days and times. As such, I'd be unable to specify Anchor Time for something like StartAnchor and EndAnchor.

                So I would need to create a variable: double ghlPrice = DrawObjects[]; (Not sure if the syntax is correct.)
                I would also need a foreach Loop to cycle through and print each instance in the Output Window
                This should go, I think, under several OnStateChange Methods
                The first would be State.SetDefaults (I will admit as I think this through, with nothing for the user to input, are SetDefaults necessary?)
                The second would be State.DataLoaded as it only needs to be called once after the chart series is loaded.
                The third would be State.Configure as GHLs will, at the end of the trading day, have a few new GHLs added (by the NinjaScript Indicator) and some will be deleted off the chart, by me.
                The DrawingState, if necessary to include, would be DrawingState.Normal
                The GHLs are not going to be edited so DrawingState.Editing wouldn't be necessary.

                For now, the OnBarUpdate Method probably wouldn't be needed, yet, because the GHLs I'm after are static.

                Jesse, I've done as much of my own homework and legwork to include as much input and explanation I can think of as necessary. I hope it's enough. I did my best.
                Last edited by RJBen; 01-27-2025, 03:11 PM.

                Comment


                  #9
                  Hello RJBen,

                  The items you mentioned are properties of the drawing object, each object has some properties that can be accessed.

                  The sample I linked shows how to filter by global objects and get their info.

                  foreach (DrawingTool draw in DrawObjects.ToList())
                  {
                  // Finds line objects that are attached globally to all charts of the same instrument
                  if (draw.IsGlobalDrawingTool && draw is DrawingTools.Line)
                  {
                  DrawingTools.Line globalLine = draw as DrawingTools.Line;

                  // Changes the line color and prints its starting and end points
                  globalLine.Stroke.Brush = Brushes.Black;

                  Print("Start: " + globalLine.StartAnchor.SlotIndex + " End: " + globalLine.EndAnchor.SlotIndex);
                  }

                  This code loops the collection and each object is set to the variable draw. That variable is used in a condition to check if its global and is a Line type tool. You can change the Line to any other object that you are looking for or just remove that part of the condition to check for all global objects.
                  In the condition the globalLine variable is used to get the values from the global line, that part also needs changed to the correct object type if you are targeting a specific object. The Print shows how to get the anchors, you could change that to globalLine.StartAnchor.Price if you wanted the price.

                  This code has to go in your scripts OnBarUpdate, the drawing object list is only available in realtime while the script is processing. It cannot go in OnStateChange.​

                  Comment


                    #10
                    User deleted this post
                    Last edited by RJBen; 01-27-2025, 05:36 PM.

                    Comment


                      #11
                      Hi Jesse
                      So I've made definite progress.
                      It still has a few issues.
                      First, each Horizontal Line is set to the Instruments (All charts). Doesn't that make it global?
                      Second, there are 63 Horizontal Lines on the ES chart. All are set to ES (All charts)
                      The Output Window says there are 2,071.
                      The ES was moving very slowly and I noticed it started at 2,068, then I ran it again and without adding any Horizontal Lines it went up to 2,069, then 2,070 then 2,071.
                      I noticed it increased each time a new bar started. I ran the Ruler from the beginning of the chart and there were, indeed, 2,071 bars.
                      It seems like its treating the number of bars as Draw Objects. It prints to the Output Window one "set" of the Horizontal Lines to each Draw Object. 2,071 sets- one for every bar. On top of that, it's not even counting the 63 Horizontal Lines.
                      Here is what I wrote:
                      protected override void OnBarUpdate()
                      {
                      if (DrawObjects.Count > 0)
                      {
                      Print("Total number of Draw Objects " + Count);

                      Print("******************************************* ");
                      }

                      // Loops through the DrawObjects collection via a threadsafe list copy
                      foreach (DrawingTool draw in DrawObjects.ToList())
                      {
                      // Finds line objects that are attached globally to all charts of the same instrument
                      if (draw.IsGlobalDrawingTool && draw is DrawingTools.HorizontalLine)
                      {
                      DrawingTools.HorizontalLine globalLine = draw as DrawingTools.HorizontalLine;

                      Print(draw.Tag + globalLine.StartAnchor.Price);
                      }

                      // Finds non-global line objects
                      else if (draw is DrawingTools.HorizontalLine)
                      {
                      // Indicates if this is a manually drawn or script generated line
                      Print("Line Object: " + draw.Tag + " Manually Drawn: " + draw.IsUserDrawn);
                      }
                      }
                      }​

                      Comment


                        #12
                        Hello RJBen,

                        AllCharts means a global line.

                        Regarding the count, do you see that many objects in the charts drawing objects property menu where it lists the objects on the chart?

                        Comment


                          #13
                          No, it just lists the tags but not the values

                          Comment


                            #14
                            Hello RJBen,

                            In the list where you see the tags do you see 2070 objects?

                            Comment


                              #15
                              That's where I got the 63 from. I double clicked a line and added all of the tags from the Drawing Objects->Configured panel

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              79 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              147 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              79 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              52 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              58 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X