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

draw verrtical line across all panels

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

    draw verrtical line across all panels

    Hi,

    In a strategy i add an indicator through code using the addChartiIndicator method. How do I draw a vertical line across all panels? I tried

    var tag = Guid.NewGuid().ToString();
    Draw.VerticalLine(_rSquared,tag,0,Brushes.DarkOran ge);

    but only draws on the data series panel

    #2
    Hello.

    I like to use vertical lines on all panels too.

    I see 3 variants:

    1) Use Custom plot (Just draw line across all window, no Draw.Line() needed).

    2) Make separate indicator, with will analyse DrawObjects collection on each bar, select vertical lines (by some attribute) and replicate them in panel, this indicator placed at.
    This indicator can be placed in any number of panels together with other indicators.


    For cases when indicator generate lines in additional panel, and strategy have to replicate them on price panel:

    3) Host strategy have access to public objects of hosted indicators.
    So, hosted indicator can generate, for example public List<DateTime>, witch holds times of vertical lines.
    Host strategy can analyse this list and draw lines in specified time.
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    Comment


      #3
      Hello tolisss,

      Thanks for your post.

      You can use the Draw.VerticalLine() method overload with the IsGlobal variable set true.
      Draw.VerticalLine(NinjaScriptBase owner, string tag, int barsAgo, bool isGlobal, string templateName)

      For example:

      Draw.VerticalLine(this, "test", 0, true,"Default"); // Draw a global vertical line with the default template.

      For further options, please see the helpguide here: http://ninjatrader.com/support/helpG...rticalline.htm
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Hi Paul,

        I thought that the overload is what I needed so I have tried already before posting but i failed to make it work.

        here my code and I added the indicator from the UI but as you can see it only plots on chart and not global

        Code:
        		protected override void OnBarUpdate()
        		{
        			if (CurrentBar%10==0){
        			    Draw.VerticalLine(this, Guid.NewGuid().ToString(), 0, true, "Default");
                        Print(CurrentBar);
        			}
                }
        @fx.practic thanks for the suggestion however as I new to NT I would appreciate more references I could look into, maybe some sample if I not ask too much?
        Attached Files
        Last edited by tolisss; 08-09-2017, 01:50 AM.

        Comment


          #5
          Under global draw objects Paul mean draw objects that visible on multiply charts, not in multiply panels.

          --

          In attachment - my indicator for NT7, that work with draw objects.
          It repeat vertical line in host panel and can be placed over other indicators.

          here is video how it work in NT7: https://monosnap.com/file/75hgGvJ0pp...X6yb1is67ZBTtx

          In NT8 DrawObjects collection provide access to all draw objects, including draw objects, created by other scripts (I didn't try, but manual say so).

          --
          But, I have to say, draw objects work very slow.
          Another way - custom plotting.

          You will need to create some list or array, witch holds bar numbers or times, when vertical line shod be plotted.

          Than You need to put some code in, OnRended method.

          Each time, OnRender called - You have to determine witch bars from Your list (array) are visible at the moment, and draw on them line from the very top of ChartControl to the very bottom of ChartControl.

          Sorry, I have no code like this to share now.
          Attached Files
          Last edited by fx.practic; 08-09-2017, 08:32 AM.
          fx.practic
          NinjaTrader Ecosystem Vendor - fx.practic

          Comment


            #6
            I have to say, that indicator from previous post work only at close of bar.
            So, You need to wait for new bar to see changes.
            fx.practic
            NinjaTrader Ecosystem Vendor - fx.practic

            Comment


              #7
              thnks a lot for the snippet it takes me really helps NT adoption ,

              excellent answer and very helpful snippet!

              one last answer can you please elab on the meaning of

              >Use Custom plot (Just draw line across all window, no Draw.Line() needed).

              do you refer again in the same case mentioned by Paul? if not could you post a snippet as well?

              Comment


                #8
                I referred to another method.

                When You set plot's values or creating draw objects inside OnBarUpdate() method - You need to set it once, and NT "remember" it and will show each time in definite place on chart.

                But, there is another way for You to draw something on chart.
                Each time when something changed on chart (scrolling, resizing, mouse clicking, incoming ticks happens, etc.) OnRender() method executed.



                From within OnRender() method You can draw everything in terms of pixel coordinates.


                ChartBars.FromIndex gives You index of first bar, actually visible now on chart;
                ChartBars.ToIndex gives You index of last bar, actually visible now on chart

                ChartControl.GetXByBarIndex(ChartBars chartBars, int barIndex ) gives You X-coordinate of centre of bar,
                ChartScale.GetYByValue(double price) gives You Y-coordinate of given price.


                If You have X and Y - You can plot everything - like noob, or like profi, but everything ))


                I'd say, Your pseudo-code should be like this:
                PHP Code:
                List<intBars_To_Draw_VLine = new List<int>();

                OnBarUpdate()
                {
                   if( 
                some_condition == true )  Bars_To_Draw_VLine.AddCurrentBar );
                }

                OnRender()
                {
                   foreach( 
                int bar_to_plot_vline in Bars_To_Draw_VLine.Wherex=> >= ChartBars.FromIndex && <= ChartBars.ToIndex )
                   {
                       
                SharpDX.Direct2D1.RenderTarget.DrawLineFromVeryTopToVeryBottom)

                   }

                This approach work much and much faster, than draw objects.
                But, need excess amount of code (imho).

                You should consider all this as prelude only.
                And I am not a profi in coding, my point of view very simplified.
                And, (can't resist) futures, foreign currency and options trading contains substantial risk ........
                Last edited by fx.practic; 08-09-2017, 08:36 AM.
                fx.practic
                NinjaTrader Ecosystem Vendor - fx.practic

                Comment


                  #9
                  great info now I feel stop less!

                  many thanks!

                  Comment


                    #10
                    Hope, it will helps You to make first steps!

                    And I miss to advice You to look at code of SampleCustomRender system indicator.
                    Last edited by fx.practic; 08-09-2017, 09:07 AM.
                    fx.practic
                    NinjaTrader Ecosystem Vendor - fx.practic

                    Comment


                      #11
                      VERY HELPFUL!

                      Thanks, fxpractic

                      Comment


                        #12
                        Originally posted by fx.practic View Post
                        Under global draw objects Paul mean draw objects that visible on multiply charts, not in multiply panels.

                        --

                        In attachment - my indicator for NT7, that work with draw objects.
                        It repeat vertical line in host panel and can be placed over other indicators.

                        here is video how it work in NT7: https://monosnap.com/file/75hgGvJ0pp...X6yb1is67ZBTtx

                        In NT8 DrawObjects collection provide access to all draw objects, including draw objects, created by other scripts (I didn't try, but manual say so).

                        --
                        But, I have to say, draw objects work very slow.
                        Another way - custom plotting.

                        You will need to create some list or array, witch holds bar numbers or times, when vertical line shod be plotted.

                        Than You need to put some code in, OnRended method.

                        Each time, OnRender called - You have to determine witch bars from Your list (array) are visible at the moment, and draw on them line from the very top of ChartControl to the very bottom of ChartControl.

                        Sorry, I have no code like this to share now.
                        Is there a way to draw these vertical lines for trade entries and exits in NT 7? Even better would be an option for 4 colors of lines; 1) Short Entry 2) Short Exit 3) Long Entry 4) Long Exit. I know about the standard plot execution drawings, but I find them to be too busy and too hard to distinguish entries from exits (especially when scalping/short term trading).

                        Comment


                          #13
                          Hello NTTrader33,

                          Thanks for your post.

                          You may want to take a look at this indicator in the User apps section: https://ninjatraderecosystem.com/use...visualization/
                          The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
                          Paul H.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by CortexZenUSA, Today, 12:53 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post CortexZenUSA  
                          Started by CortexZenUSA, Today, 12:46 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post CortexZenUSA  
                          Started by usazencortex, Today, 12:43 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post usazencortex  
                          Started by sidlercom80, 10-28-2023, 08:49 AM
                          168 responses
                          2,265 views
                          0 likes
                          Last Post sidlercom80  
                          Started by Barry Milan, Yesterday, 10:35 PM
                          3 responses
                          12 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Working...
                          X