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

Drawing a line in strategy at the value of an indicator

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

    Drawing a line in strategy at the value of an indicator

    Hi,

    I would like to draw a line in my Strategy, but the value of the line should be the value of the indicator.

    Are there examples out there or this would be a good place for it?

    Thanks


    #2
    Hello AgriTrdr,

    This would be possible using Draw.Line() or Draw.HorizontalLine().



    For example to draw at the price of a 14 SMA:
    if (CurrentBar > 10) // we'll draw the line over the last 10 bars.
    Draw.Line(this, "tag1", false, 10, SMA(14)[0], 0, SMA(14)[0], Brushes.LimeGreen, DashStyleHelper.Dot, 2);
    Also, below is a link to a forum post with helpful resources on getting started with NinjaScript and C#.


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      So where you call "SMA(14)[0]", is the place where the indicator setting from what would be in a strategy State.Dataloaded would go?

      Comment


        #4
        Hello AgriTrdr,

        This is correct, calling the indicator would return the price for the plot as a double for that barsAgo index.

        This would be the startY and EndY parameters.

        Draw.Line(NinjaScriptBase owner, string tag, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          If this was on a secondary data series, would it be:

          Code:
          if (CurrentBars[1] > 10) // we'll draw the line over the last 10 bars.
          Draw.Line(this, "tag1", false, 10, [B]SMA(BarrsArray[1], 14)[0][/B], 0, [B]SMA(BarrsArray[1], 14)[0][/B], Brushes.LimeGreen, DashStyleHelper.Dot, 2);​

          Comment


            #6
            Hello AgriTrdr,

            Drawing objects can only be drawn on the primary series, but you can use data from other series.

            The code you've suggested should work.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              Once a line is drawn how can any point of the line be accessed? For example, if Close[0] >= the equivalent to Line[0], do something. So, how can Line[0] be called?

              Thanks,

              Bob Perez

              Comment


                #8
                Hello Bob,

                You can assign the drawing object to a variable and then access this from the variable. The help guide has sample code.


                Line myLine = Draw.Line(this, "tag1", false, 10, SMA(14)[0], 0, SMA(14)[0], Brushes.LimeGreen, DashStyleHelper.Dot, 2);

                Print(myLine.StartAnchor.Price);
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Chelsea,

                  Can the line be accessed from the script if drawn manually by the user?

                  Comment


                    #10
                    Hello bobperez,

                    Yes, you can loop through the DrawObjects collection. The help guide provides sample code.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you.

                      Comment


                        #12
                        Originally posted by NinjaTrader_ChelseaB View Post
                        Hello bobperez,

                        Yes, you can loop through the DrawObjects collection. The help guide provides sample code.
                        https://ninjatrader.com/support/help...rawobjects.htm
                        Chelsea,

                        How can I programmatically detect when a user-drawn line has been crossed over, either above or below it?

                        Bob

                        Comment


                          #13
                          Hello Bob,

                          From a script, you would need to calculate the y-intercept of the object and use this to determine if the price is greater or less than the y-intercept on this bar and is less than or greater on the previous bar.

                          There is an example of calculating the y-intercept.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Thank you

                            Bob

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by oneybuchi2, Today, 03:48 PM
                            0 responses
                            3 views
                            0 likes
                            Last Post oneybuchi2  
                            Started by Graci117, 06-19-2024, 01:39 PM
                            6 responses
                            52 views
                            0 likes
                            Last Post Graci117  
                            Started by farawayz, Today, 01:20 PM
                            0 responses
                            11 views
                            0 likes
                            Last Post farawayz  
                            Started by rjm1903, Today, 01:10 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post rjm1903
                            by rjm1903
                             
                            Started by AH369, 06-21-2024, 11:09 AM
                            3 responses
                            21 views
                            0 likes
                            Last Post AH369
                            by AH369
                             
                            Working...
                            X