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

DrawTextFixed "Current" display if scolling back in Time

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

    DrawTextFixed "Current" display if scolling back in Time

    Hello Forum,
    I would like to display some variables to a fixed textfield. This example
    should display the CurrentBar instead of any variable.
    Code:
    DrawTextFixed("name", CurrentBar,TextPosition.BottomRight);
    It displays the CurrentBar well, but if i scroll back in time it doesn't change.
    Only if I scroll forward, then the CurrentBar is updating again. It behaviours like if
    if only displays the most current bar in the displayed dataseries.
    I'm really wondering, if it is really not possible to display a viariable on
    any current bar, even if it is "in the past"?
    Means the last(right) bar in the chart window one can see at the moment.

    i hope i could explain my problem my problem good enough...
    Best regards

    #2
    I don't think you can do what you are trying to do, if I am understanding it.

    You can assign your text to each bars with unique "tags"''

    Koganam will probably have some ideas.


    Syntax
    DrawTextFixed(string tag, string text, TextPosition textPosition)


    tag
    A user defined unique id used to reference the draw object. For example, if you pass in a value of "myTag", each time this tag is used, the same draw object is modified. If unique tags are used each time, a new draw object will be created each time.

    Comment


      #3
      In the end, it should look like a panel which monitors values from the most
      right bar you can see in the chart.

      If I use unique names like "Tag"+CurrenBar, then it gets overdrawn...

      Comment


        #4
        Originally posted by fernlicht View Post
        In the end, it should look like a panel which monitors values from the most
        right bar you can see in the chart.

        If I use unique names like "Tag"+CurrenBar, then it gets overdrawn...

        Check out the Pivots indicator and code. When you scroll back, you get the previous day's pivot drawn.

        I think this is what you are looking for, where the text floats over the chart, but is updated for that place (in this case daily)

        Maybe you can get it to work on a smaller time frame.

        Comment


          #5
          Originally posted by fernlicht View Post
          Hello Forum,
          I would like to display some variables to a fixed textfield. This example
          should display the CurrentBar instead of any variable.
          Code:
          DrawTextFixed("name", CurrentBar,TextPosition.BottomRight);
          It displays the CurrentBar well, but if i scroll back in time it doesn't change.
          Only if I scroll forward, then the CurrentBar is updating again. It behaviours like if
          if only displays the most current bar in the displayed dataseries.
          I'm really wondering, if it is really not possible to display a viariable on
          any current bar, even if it is "in the past"?
          Means the last(right) bar in the chart window one can see at the moment.

          i hope i could explain my problem my problem good enough...
          Best regards
          Your DrawTextfixed() code is being triggered by the barUpdate event. That event does not occur if you are scrolling backwards. (It does occur scrolling forward, as it is called on Historical bars).

          To do what you want, you are going to have to dive into undocumented ChartControl territory to determine where you are in the clientRectangle, and use that for updates.

          Comment


            #6
            Originally posted by sledge View Post
            Check out the Pivots indicator and code. When you scroll back, you get the previous day's pivot drawn.

            I think this is what you are looking for, where the text floats over the chart, but is updated for that place (in this case daily)

            Maybe you can get it to work on a smaller time frame.
            That might work. Use a transparent Plot, and feed its value to DrawTextFixed(). No need then for hairy ChartControl thingies.

            I have not tested it though. Let us know if it works.

            Comment


              #7
              The problem here is that the information on the chart needs to be linked to the last bar painted on the chart and not to the last bar called by OnBarUpdate(). If you move your chart forward or plot in real-time, the last bar painted is identical with the last bar called by OnBarUpdate(), and you will observe no problem. However, if you scroll you chart back horizontally, the information in the box will not change accordingly, if DrawText() is called in OnBarUpdate().

              What you need to do is to code a custom plot. An example can be found here:

              The best futures trading community on the planet: futures trading, market news, trading charts, trading platforms, trading strategies


              The upper left box of the indicator catches the DataSeries values according to the last bar painted on the chart. This can only be coded within the custom plot.
              Attached Files

              Comment


                #8
                Problem Solved

                Ok, I solved it. The magic words are -> ChartControl.LastbarPainted

                I've written a really simple example to show"current" Close prices in a panel.
                Thanks for the hints!

                Code:
                [FONT=Tahoma][SIZE=2][COLOR=black]#region Using declarations
                 using System;
                 using System.ComponentModel;
                 using System.Diagnostics;
                 using System.Drawing;
                 using System.Drawing.Drawing2D;
                 using System.Xml.Serialization;
                 using NinjaTrader.Cbi;
                 using NinjaTrader.Data;
                 using NinjaTrader.Gui.Chart;
                 #endregion
                 
                 // This namespace holds all indicators and is required. Do not change it.
                 namespace NinjaTrader.Indicator
                 {
                     
                     [Description("Enter the description of your new custom indicator here")]
                     public class PanelOnChart : Indicator
                     {
                         #region Variables
                         Font textfont = new System.Drawing.Font(FontFamily.GenericSansSerif, 15);
                         System.Drawing.Brush textbrush = new SolidBrush(Color.Black);
                         #endregion
                 
                         protected override void Initialize()
                         {
                             Overlay                = false;
                         }
                 
                         
                         protected override void OnBarUpdate()
                         {
                            
                 
                         }
                         
                         public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
                         {
                             int recleft,rectop,recw,rech;
                             recleft = bounds.Left + bounds.Width/4;
                             rectop = bounds.Top + bounds.Height/3;
                             recw = Math.Min(100,bounds.Width/3);
                             rech = Math.Min(30,bounds.Height/2);
                             
                             int currentbarOnChart = ChartControl.LastBarPainted;
                             
                             graphics.DrawRectangle(new Pen(Color.Black,3),recleft,rectop,recw,rech);
                             graphics.DrawString(""+Close[currentbarOnChart] ,textfont,textbrush,new Point(recleft + 10,rectop + 5));
                             
                         }
                 
                         #region Properties
                 
                         #endregion
                     }
                 }
                 
                 
                 
                 
                 #region NinjaScript generated code. Neither change nor remove.
                 // This namespace holds all indicators and is required. Do not change it.
                 namespace NinjaTrader.Indicator
                 {
                     public partial class Indicator : IndicatorBase
                     {
                         private PanelOnChart[] cachePanelOnChart = null;
                 
                         private static PanelOnChart checkPanelOnChart = new PanelOnChart();
                 
                         /// <summary>
                         /// Enter the description of your new custom indicator here
                         /// </summary>
                         /// <returns></returns>
                         public PanelOnChart PanelOnChart()
                         {
                             return PanelOnChart(Input);
                         }
                 
                         /// <summary>
                         /// Enter the description of your new custom indicator here
                         /// </summary>
                         /// <returns></returns>
                         public PanelOnChart PanelOnChart(Data.IDataSeries input)
                         {
                             if (cachePanelOnChart != null)
                                 for (int idx = 0; idx < cachePanelOnChart.Length; idx++)
                                     if (cachePanelOnChart[idx].EqualsInput(input))
                                         return cachePanelOnChart[idx];
                 
                             lock (checkPanelOnChart)
                             {
                                 if (cachePanelOnChart != null)
                                     for (int idx = 0; idx < cachePanelOnChart.Length; idx++)
                                         if (cachePanelOnChart[idx].EqualsInput(input))
                                             return cachePanelOnChart[idx];
                 
                                 PanelOnChart indicator = new PanelOnChart();
                                 indicator.BarsRequired = BarsRequired;
                                 indicator.CalculateOnBarClose = CalculateOnBarClose;
                 #if NT7
                                 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                                 indicator.MaximumBarsLookBack = MaximumBarsLookBack;
                 #endif
                                 indicator.Input = input;
                                 Indicators.Add(indicator);
                                 indicator.SetUp();
                 
                                 PanelOnChart[] tmp = new PanelOnChart[cachePanelOnChart == null ? 1 : cachePanelOnChart.Length + 1];
                                 if (cachePanelOnChart != null)
                                     cachePanelOnChart.CopyTo(tmp, 0);
                                 tmp[tmp.Length - 1] = indicator;
                                 cachePanelOnChart = tmp;
                                 return indicator;
                             }
                         }
                     }
                 }
                 
                 // This namespace holds all market analyzer column definitions and is required. Do not change it.
                 namespace NinjaTrader.MarketAnalyzer
                 {
                     public partial class Column : ColumnBase
                     {
                         /// <summary>
                         /// Enter the description of your new custom indicator here
                         /// </summary>
                         /// <returns></returns>
                         [Gui.Design.WizardCondition("Indicator")]
                         public Indicator.PanelOnChart PanelOnChart()
                         {
                             return _indicator.PanelOnChart(Input);
                         }
                 
                         /// <summary>
                         /// Enter the description of your new custom indicator here
                         /// </summary>
                         /// <returns></returns>
                         public Indicator.PanelOnChart PanelOnChart(Data.IDataSeries input)
                         {
                             return _indicator.PanelOnChart(input);
                         }
                     }
                 }
                 
                 // This namespace holds all strategies and is required. Do not change it.
                 namespace NinjaTrader.Strategy
                 {
                     public partial class Strategy : StrategyBase
                     {
                         /// <summary>
                         /// Enter the description of your new custom indicator here
                         /// </summary>
                         /// <returns></returns>
                         [Gui.Design.WizardCondition("Indicator")]
                         public Indicator.PanelOnChart PanelOnChart()
                         {
                             return _indicator.PanelOnChart(Input);
                         }
                 
                         /// <summary>
                         /// Enter the description of your new custom indicator here
                         /// </summary>
                         /// <returns></returns>
                         public Indicator.PanelOnChart PanelOnChart(Data.IDataSeries input)
                         {
                             if (InInitialize && input == null)
                                 throw new ArgumentException("You only can access an  indicator with the default input/bar series from within the  'Initialize()' method");
                 
                             return _indicator.PanelOnChart(input);
                         }
                     }
                 }
                 #endregion[/COLOR][/SIZE][/FONT]
                Last edited by fernlicht; 07-22-2012, 01:30 PM. Reason: Problem solved

                Comment


                  #9
                  After implementig it into an indicator i'm missing my Plots.
                  So what lines should i add, that the overwritteb Plot() function
                  is able to draw my plotlines again?

                  Comment


                    #10
                    Originally posted by fernlicht View Post
                    After implementig it into an indicator i'm missing my Plots.
                    So what lines should i add, that the overwritteb Plot() function
                    is able to draw my plotlines again?
                    The custom plot overrides your default plot. Your plot now draws what you have coded, and that is just the box.

                    If you wish to plot both the indicator plots and the text book, then you have two options:

                    (a) either you use a second indicator to plot just the text box,

                    (b) or if you prefer the comfort to add only one indicator, you would need to add the code for the indicator plots to the code of your text box

                    Comment


                      #11
                      Originally posted by fernlicht View Post
                      After implementig it into an indicator i'm missing my Plots.
                      So what lines should i add, that the overwritteb Plot() function
                      is able to draw my plotlines again?
                      In your custom Plot, first call

                      Code:
                      base.Plot(graphics, bounds, min, max);

                      Comment


                        #12
                        Thanks, that worked!

                        Comment


                          #13
                          Originally posted by fernlicht View Post
                          Thanks, that worked!

                          I'm looking to do the same thing. Did your code work that you can share?

                          Thx

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by GussJ, 03-04-2020, 03:11 PM
                          16 responses
                          3,279 views
                          0 likes
                          Last Post Leafcutter  
                          Started by WHICKED, Today, 12:45 PM
                          2 responses
                          19 views
                          0 likes
                          Last Post WHICKED
                          by WHICKED
                           
                          Started by Tim-c, Today, 02:10 PM
                          1 response
                          9 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by Taddypole, Today, 02:47 PM
                          0 responses
                          5 views
                          0 likes
                          Last Post Taddypole  
                          Started by chbruno, 04-24-2024, 04:10 PM
                          4 responses
                          52 views
                          0 likes
                          Last Post chbruno
                          by chbruno
                           
                          Working...
                          X