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

Is it possible to buy upon crossing of a piece of geometry created w/a draw object?

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

    Is it possible to buy upon crossing of a piece of geometry created w/a draw object?

    Howdy.

    Just wondering, if it is possible to create an entry order based on say a diagonally drawn line created with something like the Draw.Line() method for example?

    Or would the only way to accomplish this be to store the price at each bar this line creates in a draw object?

    Thanks!

    #2
    Hello forrestang,

    Thanks for your post.

    Yes, you would need to loop through a collection of draw objects and determine which line(s) you wanted to check the price against, obtain the anchor prices of the line and compare the current price to the anchor price.

    Please see this section of the help guide for sorting through a draw objects collection: https://ninjatrader.com/support/helpGuides/nt8/?drawingtools_drawobjects.htm

    Also, see the example script, YAxisProjectionOfLine, created by my colleague Paul in post #6 of this forum thread: https://ninjatrader.com/support/forum/forum/ninjatrader-8/add-on-development/107312-price-crossing-a-line#post828663

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Ok thanks.

      That's essentially what I was asking... can you actually interact and place an order based on a drawn object... OR, would you manually have to calculate the slope of a line and check if price has crossed this line at each individual bar.

      Comment


        #4
        I have another question.

        So, I am able to draw lines, some of which happen beyond the right most developing bar on the chart. I have used the variant of Draw.Line using DateTime as the x-inputs, this allows me to draw to a clock time.

        The x2 input, I get using something like Time[0].AddHours(15), which allows me to get an endpoint in the future.

        Drawing the line works fine. I am attaching an image showing how I've drawn the lines in the script with Draw.Line(). And the Red dots are attempting to turn these lines into a plot.

        But what I am wanting to do, is create outputs, and store the value into a plot.

        For this, I simply use Bars.GetBars(), to find out what the index is. I then calculate a slope using (y2-y1)/(x2-x1)... and then multiply this by the X-position on the axis, and add a y-intercept... I.e., the y=mx+b formula to plot a line.

        So this works fine, as long as the x2 point(the furthest point I am drawing to) has already happened. The issue however, is how GetBars will not report FUTURE index position of bars given a DateTime.

        So my question is essentially, is there a way to get the slope of a line, given that I have two DateTimes, but not to bar index points(one of which is beyond the right most bar on the chart)?


        Click image for larger version

Name:	2021-10-20_132446.png
Views:	254
Size:	58.3 KB
ID:	1175643

        Comment


          #5
          Hello forrestang,

          Thanks for your note.

          You would not be able to get the future bar index positions if the index is beyond the current developing bar. You would only be able to get bar index positions that have already occurred.

          That said, are you using time-based bars or non-time-based bars?

          If you are using time-based bars, you may be able to calculate how many bars are between the time of the current developing bar and the time that the drawing is being drawn.

          Let us know if we may assist further.
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            I was hoping I could use both...

            But assuming the use of time-based bars, is there an obvious way of coming up with the index of a bar(beyond the current bar) based on the bar interval used(BarsPeriod)? More specifically, is there an obvious way to know how many bars there should be per session?

            I have done this in the past by using 2/3 periods to count the bars, before running the indicator, I.e., counting the bars at session's end, returning.

            I could also do something like dividing the number of minutes in a day, by the bar interval, but this is kinda messy, as it might not work properly if I ever use a different session template, and might require a user input for the # of minutes in a day.

            Is there an obvious or simple way to know how many bars are in a session based on a used template and barsperiod, so that I can get the index of future bars?

            Thanks!

            Comment


              #7
              Hello forrestang,

              Thanks for your note.

              This could likely be done by reading the TradingHours template in State.DataLoaded, and calculating how many bars could be in a session if the bar is time-based (Subtract times, divide by minutes).

              Please also keep in mind that if there is no data then there is no bar. If there is no bar then there would be no bar index, so this would not be 100% true for where an index "would be".

              TradingHours: https://ninjatrader.com/support/help...adinghours.htm

              Let us know if we may assist further.
              Brandon H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rdtdale, Today, 01:02 PM
              0 responses
              1 view
              0 likes
              Last Post rdtdale
              by rdtdale
               
              Started by alifarahani, Today, 09:40 AM
              3 responses
              15 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by RookieTrader, Today, 09:37 AM
              4 responses
              18 views
              0 likes
              Last Post RookieTrader  
              Started by PaulMohn, Today, 12:36 PM
              0 responses
              5 views
              0 likes
              Last Post PaulMohn  
              Started by love2code2trade, 04-17-2024, 01:45 PM
              4 responses
              40 views
              0 likes
              Last Post love2code2trade  
              Working...
              X