Ok, actually I have tried what you say but no value was appearing so this is why I asked if you suceeded, I will post a sample code later for you to review......... thank you
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!
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
NinjaTrader
Strategy driven indicator plot
Collapse
X
-
I've modified the SampleStrategyPlot examples a bit to further explain the idea.
The strategy below will plot variable1 in the indicator on panel1, also the indicator is able to access the value of variable2 (defined in the strategy) and perform some logic like change the color of a line if variable2 exceeds a certain threshold-value.
Indeed this doesn't work on backtesting, but it does work on replay or live. Since I use this technique to plot a red/green filled realized profit/loss graph, I doesn't matter if it only works in live trading.
Marco
indicator:
Code:namespace NinjaTrader.Indicator { ///<summary> /// Empty placeholder indicator for creating plots in NinjaScript Strategies ///</summary> [Description("Empty placeholder indicator for creating plots in NinjaScript Strategies")] publicclass StrategyPlot : Indicator { #region Variables privatedouble variable1 = 0; // Default setting for variable1 privatedouble variable2 = 0; // Default setting for variable2 privateint id = 0; // Default setting for Id #endregion ///<summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. ///</summary> protectedoverridevoid Initialize() { Add(new Plot(Color.Orange, PlotStyle.Line, "Strategy_Plot")); Add(new Line(Color.White,0, "dd")); // Stored in Lines[0] CalculateOnBarClose = false; DrawOnPricePanel = false; } ///<summary> /// Called on each bar update event (incoming tick) ///</summary> protectedoverridevoid OnBarUpdate() { variable2 = Lines[0].Value; // readout variable2 as defined in the strategy. //Print(variable2); } #region Properties [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Strategy_Plot { get { return Values[0]; } } [Description("")] [Category("Parameters")] publicint Id { get { return id; } set { id = Math.Max(0, value); } } #endregion } }
Code:namespace NinjaTrader.Strategy { /// <summary> /// Reference sample demonstrating how to plot from within a strategy /// </summary> [Description("Reference sample demonstrating how to plot from within a strategy")] public class SampleStrategyPlot : Strategy { #region Variables private double variable1 = 0; // Default setting for variable1 private double variable2 = 0; // Default setting for variable2 #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { CalculateOnBarClose = false; Add(StrategyPlot(0) ); StrategyPlot(0).Panel = 1; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { variable1++; // increment with 1 variable2++; StrategyPlot(0).Value.Set(variable1); // pass variable1 to the indicator Plot ( plot values are not accessible to indicator code ) StrategyPlot(0).Lines[0].Value = variable2; // pass variable2 to the indicator Lines[0] Y-coordinates (this value IS accessible to indicator code for indicator logic // like change color of line if variable exceeds 50) } #region Properties #endregion } }
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ezrollin, 02-26-2022, 11:14 PM
|
7 responses
206 views
0 likes
|
Last Post
by kenz987
Today, 08:36 PM
|
||
Started by rocketman7, Today, 08:34 PM
|
0 responses
1 view
0 likes
|
Last Post
by rocketman7
Today, 08:34 PM
|
||
Started by rt61968, 02-17-2018, 05:24 PM
|
3 responses
2,733 views
0 likes
|
Last Post
by MasterEtrad3
Today, 08:12 PM
|
||
Started by nuobo, Today, 07:43 PM
|
0 responses
4 views
0 likes
|
Last Post
by nuobo
Today, 07:43 PM
|
||
Started by ETFVoyageur, Today, 02:04 PM
|
3 responses
22 views
0 likes
|
Last Post
by ETFVoyageur
Today, 07:04 PM
|
Comment