NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 07-21-2012, 05:35 AM   #1
fernlicht
Junior Member
 
Join Date: Feb 2012
Posts: 18
Thanks: 0
Thanked 1 time in 1 post
Default 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
fernlicht is offline  
Reply With Quote
Old 07-21-2012, 06:49 AM   #2
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,277
Thanks: 193
Thanked 333 times in 288 posts
Default

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.
sledge is offline  
Reply With Quote
Old 07-21-2012, 07:24 AM   #3
fernlicht
Junior Member
 
Join Date: Feb 2012
Posts: 18
Thanks: 0
Thanked 1 time in 1 post
Default

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...
fernlicht is offline  
Reply With Quote
Old 07-21-2012, 07:30 AM   #4
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,277
Thanks: 193
Thanked 333 times in 288 posts
Default

Quote:
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.
sledge is offline  
Reply With Quote
Old 07-21-2012, 07:32 AM   #5
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,356
Thanks: 24
Thanked 1,304 times in 1,067 posts
Send a message via Skype™ to koganam
Default

Quote:
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.
koganam is offline  
Reply With Quote
Old 07-21-2012, 05:10 PM   #6
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,356
Thanks: 24
Thanked 1,304 times in 1,067 posts
Send a message via Skype™ to koganam
Default

Quote:
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.
koganam is offline  
Reply With Quote
Old 07-22-2012, 09:51 AM   #7
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 1,863
Thanks: 17
Thanked 100 times in 82 posts
Default

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:

http://www.bigmiketrading.com/downlo...load.html?view

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 Images
File Type: jpg 6E 09-12 (10 Min) 13_07_2012.jpg (143.8 KB, 24 views)
Harry is offline  
Reply With Quote
Old 07-22-2012, 12:37 PM   #8
fernlicht
Junior Member
 
Join Date: Feb 2012
Posts: 18
Thanks: 0
Thanked 1 time in 1 post
Default 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:
#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
Last edited by fernlicht; 07-22-2012 at 01:30 PM. Reason: Problem solved
fernlicht is offline  
Reply With Quote
Old 07-22-2012, 02:33 PM   #9
fernlicht
Junior Member
 
Join Date: Feb 2012
Posts: 18
Thanks: 0
Thanked 1 time in 1 post
Default

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?
fernlicht is offline  
Reply With Quote
Old 07-22-2012, 03:28 PM   #10
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 1,863
Thanks: 17
Thanked 100 times in 82 posts
Default

Quote:
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
Harry is offline  
Reply With Quote
Old 07-22-2012, 09:27 PM   #11
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,356
Thanks: 24
Thanked 1,304 times in 1,067 posts
Send a message via Skype™ to koganam
Default

Quote:
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);
koganam is offline  
Reply With Quote
The following user says thank you to koganam for this post:
Old 07-23-2012, 02:50 PM   #12
fernlicht
Junior Member
 
Join Date: Feb 2012
Posts: 18
Thanks: 0
Thanked 1 time in 1 post
Default

Thanks, that worked!
fernlicht is offline  
Reply With Quote
Old 11-14-2012, 03:19 PM   #13
ij001
Senior Member
 
Join Date: Apr 2010
Posts: 125
Thanks: 18
Thanked 3 times in 3 posts
Default

Quote:
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
ij001 is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Optimizer: "Time Remaining" should display Days in addition to HH:MM:SS kdoren Version 7 Beta General Questions & Bug Reports 1 11-18-2009 04:03 AM
Bug: Can't Back Up NT7 w/ Lots Of Data - "Too many entries for Zip file". ChiTrader2000 Version 7 Beta General Questions & Bug Reports 2 11-13-2009 10:41 AM
Can I define the "Time to flatten" for the "Exit on Close" in the NinjaScript? dleekk General Programming 5 11-09-2009 12:46 AM
summary of "strategy realized" is not equal "account performance, total net profit"" Fragolino Miscellaneous Support 1 02-19-2009 04:12 AM
Difference between"Bars ago" & "look Back" ju1234 Strategy Development 3 11-21-2008 10:56 AM


All times are GMT -6. The time now is 11:12 PM.