![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Feb 2012
Posts: 18
Thanks: 0
Thanked 1 time in 1 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);
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 |
|
Senior Member
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,187
Thanks: 178
Thanked 301 times in 259 posts
|
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. |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Feb 2012
Posts: 18
Thanks: 0
Thanked 1 time in 1 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... |
|
|
|
|
|
#4 | |
|
Senior Member
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,187
Thanks: 178
Thanked 301 times in 259 posts
|
Quote:
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. |
|
|
|
|
|
|
#5 | |
|
Senior Member
|
Quote:
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. |
|
|
|
|
|
|
#6 | |
|
Senior Member
|
Quote:
![]() I have not tested it though. Let us know if it works.
|
|
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Oct 2007
Posts: 1,829
Thanks: 12
Thanked 83 times in 67 posts
|
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. |
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Feb 2012
Posts: 18
Thanks: 0
Thanked 1 time in 1 post
|
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
|
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Feb 2012
Posts: 18
Thanks: 0
Thanked 1 time in 1 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? |
|
|
|
|
|
#10 | |
|
Senior Member
Join Date: Oct 2007
Posts: 1,829
Thanks: 12
Thanked 83 times in 67 posts
|
Quote:
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
|
|
|
|
|
|
|
#11 |
|
Senior Member
|
|
|
|
|
|
The following user says thank you to koganam for this post: |
|
|
|
#12 |
|
Junior Member
Join Date: Feb 2012
Posts: 18
Thanks: 0
Thanked 1 time in 1 post
|
Thanks, that worked!
|
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Apr 2010
Posts: 125
Thanks: 18
Thanked 3 times in 3 posts
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |