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

Custom drawing tool, advice please

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

    Custom drawing tool, advice please

    Hi,

    I would like to create a custom drawing tool, a variant of "Line". My line is supposed to anchor to a specific bar and price and then go horizontally all the way to the right only (not the left, as "horizontal line" does). So the line has only a single anchor. I will then make the line display some additonal information attached to it.

    After looking through the Line.cs file, I am unsure of how to go about creating a new "MyLine" tool. It seems that all chart line types derive from the Line class, but the actual mechanics of each line is not coded into the derived classes, but into the Line class itself. The selection of available line types is a hardcoded enum within Line.

    Other than copying the whole file and pruning it down to what I need, is there a better method? Could I derive from Line and override the ChartLineType enum to add my own?

    Any advice or a short code outline is much appreciated!

    Thank you,
    Stefan.

    #2
    Hello Stefan,

    In needing to test various drawing tool script methods I actually pulled out the line from the @Lines.cs file.

    This should save you considerable time.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      now that is cool. Thank you very much, I think I get it. Let me look at the code for a while and I should be able to get along. Great!

      Kind regards,
      Stefan.

      Comment


        #4
        maybe something like this.
        Attached Files

        Comment


          #5
          Hi,

          I'm trying to create a new modified "custom" line.
          I'm not an expert with NT, but I try to learn.

          I would like to draw a second line after drawing the first line with the above drawing tool "customline".
          For example: I select two points with the mouse, drawing a line, and as I click the second point and finish drawing the line, NT will draw this line, and another second line starting from the last point I selected and going 5 bars to the right.

          Do you have an idea, where could I continue?
          I studied the CustomLine_NT8 but I don't know where to continue...

          Thanks!

          Comment


            #6
            Hello artson,

            I would recommend viewing the TrendChannel drawing tool script included with NinjaTrader.

            Your script is going to need custom logic to add anchors and control which anchor IsEditing.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks a lot Chelsea

              I'll try to check it.

              Comment


                #8
                Hi,

                I've been looking through your documentation and the example of TrendChannel (and RegressionChannel also..) but I don't reach my target.

                I cannot find the way to create a line (horizontal) starting from a High (for example) of a bar located 10 bars back from the bar I selected.
                I don't understand the way of switching from bar coordinates (price and time) to screen coordinates (x,y)....
                I use "SharpDX.Vector2" and "RenderTarget.DrawLine" and more but I cannot find it....

                Maybe you can help me or give me some advices....

                Thanks in advance!!

                Comment


                  #9
                  Hello arston,

                  Thanks for your question.

                  ChartControl.GetXByBarIndex and ChartScale.GetYByValue can be used to convert chart values into chart coordinates. Keep in mind when using these methods, we are using BarIndexes as opposed to Bars Ago indexes, so a "BarsAgo" reference would be an index of CurrentBar - 10.

                  Also to note, when you are referencing values from a Series or PriceSeries object outside of OnBarUpdate, you should use the GetValueAt() method. So referencing the Close of the current bar would look like:

                  Close.GetValueAt(CurrentBar)

                  Publicly available documentation on the items discussed can be referenced below.

                  ChartControl.GetXByBarIndex - https://ninjatrader.com/support/help...bybarindex.htm

                  ChartScale.GetYByValue - https://ninjatrader.com/support/help...etybyvalue.htm

                  GetValueAt - https://ninjatrader.com/support/help...getvalueat.htm

                  Please let us know if we can be of further assistance.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks for the help Jim,

                    I'm still trying it......

                    I', at "public override void OnRender(ChartControl chartControl, ChartScale chartScale)" (creating a DrawingTool)
                    and using "double highPrice = Bars.GetClose(10);"
                    I get the error CS0120 -> a reference is required for the field, method or property not static 'NinjaTrader.Data.Bars.GetClose(int)....

                    why?.....????

                    Thanks,

                    Comment


                      #11
                      Ok, I finally managed to solve it!

                      I have to define previously the bars:
                      Bars baseBars = GetAttachedToChartBars().Bars;

                      Thanks a lot!!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by gemify, 11-11-2022, 11:52 AM
                      6 responses
                      803 views
                      2 likes
                      Last Post ultls
                      by ultls
                       
                      Started by ScottWalsh, Today, 04:52 PM
                      0 responses
                      3 views
                      0 likes
                      Last Post ScottWalsh  
                      Started by ScottWalsh, Today, 04:29 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post ScottWalsh  
                      Started by rtwave, 04-12-2024, 09:30 AM
                      2 responses
                      22 views
                      0 likes
                      Last Post rtwave
                      by rtwave
                       
                      Started by tsantospinto, 04-12-2024, 07:04 PM
                      5 responses
                      70 views
                      0 likes
                      Last Post tsantospinto  
                      Working...
                      X