Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Semi-automated strategy using manually drawn horizontal lines on chart

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

    Semi-automated strategy using manually drawn horizontal lines on chart

    Hello,

    Is it possible to have a semi-automated strategy whereby the logic in the strategy code can react based on the position of manually drawn horizontal lines on a chart which are placed prior to the strategy being enabled and potentially moved whilst the strategy is enabled?

    Thanks,

    Neil

    #2
    Hello burtoninlondon,

    Yes that is possible in a manually coded strategy. You can use the DrawObjects collection to find drawing objects. This only works in realtime so the strategy won't be able to be backtested. You can find a sample of working with the drawing objects collection in the following page.

    Comment


      #3
      Thanks NinjaTrader_Jesse thats really helpful.

      I understand that to find a DrawObject the syntax is DrawObjects["someTag"] however each DrawObject on my chart is differentiated by a unique number. For example, if I was to consider horizontal lines then the tag would be "Horizontal Line 1", the next "Horizontal Line 2", and so on.

      How does the syntax deal with this or should I simply hard code the unique tags into the strategy code and ensure the hard coded tags match the horizontal lines I manually add?

      Thanks again.

      Comment


        #4
        Hello burtoninlondon,

        You can see the other sample on the linked page that loops over the drawing objects, that would be how you can find objects by their type instead of a tag. Hard coding the tag would be the suggested way to capture specific objects so that you know exactly which object you are targeting.

        Comment


          #5
          Thanks NinjaTrader_Jesse.

          Would you be able to help me understand how I can access the Start Y value of a Line I've manually drawn on my chart with the tag "Line 1"?

          I'm struggling to understand the syntax of the ChartAnchor properties guidance (https://ninjatrader.com/support/help...rawobjects.htm).

          Thanks again.

          Comment


            #6
            Hello burtoninlondon,

            You would need to use the StartAnchor or EndAnchor property to get their value, anchors have a Price property. You can see the available properties of anchors here: https://ninjatrader.com/support/help...ub=chartanchor

            There is also a sample of accessing the anchors properties from an object here https://ninjatrader.com/support/help...rawingtool.htm

            Comment


              #7
              NinjaTrader_Jesse, thanks for the links.

              Unfortunately I'm unable to decipher the documentation to determine what I need to do as my understanding of the documentation is that it is written to aid the insertion of drawing objects from code rather than accessing manually generated drawing objects. I'm not an expert coder and I could be wrong so please bear with me.

              I typically learn best from examples, I don't suppose you would have any examples to hand of accessing anchor properties from a manually drawn line you can share with me? I'll hopefully be able to expand from there.

              Comment


                #8
                Hello burtoninlondon,

                To find drawn objects you can use the samples in the first link from post 2, the properties of the object you found can be seen in the other links I had provided. The link in post 2 shows how to use the anchors:

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

                instead of SlotIndex you would use Price if you wanted the price of that anchor.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                41 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                124 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                64 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                41 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                46 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X