• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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.

    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.

          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.

            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.
                https://ninjatrader.com/support/help...s/onrender.htm


                From within OnRender() method You can draw everything in terms of pixel coordinates.
                https://ninjatrader.com/support/help...oordinates.htm

                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.
                https://ninjatrader.com/support/help...n-us/chart.htm

                If You have X and Y - You can plot everything - like noob, or like profi, but everything ))
                https://ninjatrader.com/support/help...ndertarget.htm

                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.

                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.

                    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 dadarara, Yesterday, 06:38 AM
                          1 response
                          7 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by jvanelli, Today, 01:19 PM
                          1 response
                          2 views
                          0 likes
                          Last Post jvanelli  
                          Started by TrendFollowingCapital, Today, 05:45 AM
                          1 response
                          3 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by Atilla, Today, 04:26 AM
                          1 response
                          13 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by FelixMMM, Today, 04:11 AM
                          1 response
                          17 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Working...
                          X