Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Does current bar touch or cross my trendline?

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

    #16
    Seems like for me to calculate runrate, I'd have to know the bar number of the anchors. However, the DrawOnBar of the trend anchors always returns -2147483648

    Comment


      #17
      Hello shildebrand324,

      Is the TrendChannel drawn in blank area where there are no bars?

      I made a quick test script to see if there is an issue, but this prints the bar number correctly.
      Attached Files
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Click image for larger version

Name:	Screenshot 2020-12-10 121903.png
Views:	321
Size:	50.9 KB
ID:	1131715Sometimes the trend channel anchors are in an area where no bars exists. Is there a way around this?
        Last edited by shildebrand324; 12-10-2020, 11:19 AM. Reason: Add image

        Comment


          #19
          Seems like even on channels where it is on bars, it still doesn't return the bar. However, I'll need to be able to do the projection without it having to touch bars, since not all channels will be touching bars, like in the pic above.

          Comment


            #20
            Hello shildebrand324,

            There would be no way around this. NinjaTrader cannot provide bar number or times of bars that do not exist.

            I recommend that you move the anchors to all be within the bars on the chart.

            As a heads up, you will also see approximations when restoring manually drawn objects from workspace. The price and time of the anchor may change when restored.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              That would be impossible on some channels, especially on ranges, like above. Is there not another way I can tell if I have a bar touching a line, except through projection?

              Comment


                #22
                Hello shildebrand324,

                I am not aware of any other way other than by looking at the bar information, price and time, of the drawing object anchors (which move with the bars as you adjust the chart).

                Drawing objects in the blank space to the right of the chart is basically unsupported through ninjascript.
                Below is a link to a forum thread where this is discussed.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #23
                  Yeah, I'm not really concerned about the blank space to the right of the chart. I just need to know if a drawing object is touching the current bar. I know this is possible, because I've seen indicators do it before.

                  So, you're telling me there's no way for me to know if the current bar is touching a line that NT has on the chart?

                  Comment


                    #24
                    Hello shildebrand324,

                    Only if the drawing object has the anchors within the chart bars.

                    They can project out into the blank space with the Extend lines right option, but the anchors must be within the chart bars we can get numbers for.

                    If the drawing object is within the chart bars the formula is:

                    slope between anchors = (anchor2price - anchor1price) / (anchor2bar - anchor1bar)
                    (slope = (y2 - y1)/(x2 - x1))

                    yintercept = slope * (CurrentBar - anchor1bar)
                    (yintercept = slope * (x2 - x1))

                    Then you can check if the yintercept is equal to the current bar close, or within a tick or within the high and low, or whatever you would like.

                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #25
                      Even when I have a channel start/end, my drawonbar still comes up with -2147483648. What could be the issue?

                      Comment


                        #26
                        Hello shildebrand324,

                        May I have a reduced copy of the script? Remove everything except the DrawObjects loop, the condition for draw type, the cast, and the print for the anchor .DrawnOnBar.

                        To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
                        1. Click Tools -> Export -> NinjaScript...
                        2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
                        3. Click the 'Export' button
                        4. Enter a unique name for the file in the value for 'File name:'
                        5. Choose a save location -> click Save
                        6. Click OK to clear the export location message
                        By default your exported file will be in the following location:
                        • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
                        Below is a link to the help guide on Exporting NinjaScripts.
                        http://ninjatrader.com/support/helpG...-us/export.htm

                        Once exported, please attach the file as an attachment to your reply.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #27
                          This is the loop in OnBarUpdate(). Is that all you need?

                          foreach (DrawingTool draw in DrawObjects)
                          {
                          if (draw is DrawingTools.TrendChannel)
                          {
                          TrendChannel channel = draw as DrawingTools.TrendChannel;
                          double parallelEndAnchorPrice = channel.ParallelStartAnchor.Price + (channel.TrendEndAnchor.Price - channel.TrendStartAnchor.Price);
                          Print("Tag: " + draw.Tag + " Start Price: " + channel.TrendStartAnchor.Price + " End Price " + channel.TrendEndAnchor.Price + " Start Bars Ago: " + channel.TrendStartAnchor.DrawnOnBar + " End Bars Ago: " + channel.TrendEndAnchor.DrawnOnBar);
                          Print("Tag: " + draw.Tag + " Parallel Start Price: " + channel.ParallelStartAnchor.Price + " End Price " + parallelEndAnchorPrice + " Start Bars Ago: " + channel.ParallelStartAnchor.DrawnOnBar);
                          }
                          }

                          Comment


                            #28
                            TrendDraw script
                            Attached Files

                            Comment


                              #29
                              Hello shildebrand324,

                              So DrawnOnBar 'Gets the absolute bar index value that a NinjaScript object drew the chart anchor.

                              Meaning, this only applies to NinjaScript drawn anchors.

                              (As a heads up, DrawnOnBar is not a bars ago value and is a bar number.)


                              But the TrendStartAnchor.SlotIndex will work instead.

                              (or Bars.GetBar(channel.TrendStartAnchor.Time))
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #30
                                Very good. How would I get Bars.GetBar(channel.TrendStartAnchor.Time) for ParallelEndAnchor.Time, since ParallelEndAnchor doesn't exist?

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                603 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                349 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                104 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                560 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                560 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X