Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
how to plot existing indicator in another indicator
Collapse
X
-
Hello junkone,
Thanks for your post.
This is not possible in NinjaTrader 8. A feature request has been created based on this thread: http://ninjatrader.com/support/forum...ad.php?t=61584
We have added your vote for this feature request (SFT-899).Paul H.NinjaTrader Customer Service
-
Hello junkone,
For the sake of clarity, member Kogaman is providing a solution for adding a plot with a few lines of code and I was responding to the use of AddChartIndicator() which works (to plot the indicators) in strategies but not in another indicator. (At least we have another vote for the feature!)
I apologize if I misunderstood or confused the original question.Paul H.NinjaTrader Customer Service
Comment
-
To elaborate, there is an AddPlot() method you can call from an indicator, which will add an array called Value[] to your indicator:
Code:protected override void OnStateChange() { if (State == State.SetDefaults) { AddPlot(Brushes.Orange, "IndicatorPlot"); } }
Code:protected override void OnBarUpdate() { // set the AddPlot value to an EMA indicator Value[0] = EMA(9)[0]; }
MatthewNinjaTrader Product Management
Comment
-
interesting logic. i tried it but it does not plot anything.
Code:public class S_Trading_System : Indicator { protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "S_Trading_System"; Calculate = Calculate.OnEachTick; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = false; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; AddPlot(Brushes.Orange, "Mean"); } else if (State == State.Configure) { AddPlot(Brushes.Aqua, "EMA 9"); AddPlot(Brushes.DarkGray, "EMA 22"); } } protected override void OnBarUpdate() { //Add your custom indicator logic here. // Only process entry signals on a bar by bar basis (not tick by tick) switch (BarsInProgress) { case 0: BarsinProgress0(); break; case 1: Value[0] = EMA(9)[0]; break; case 2: Value[0] = EMA(22)[0]; break; default: Alert(" undefind bars in progress" + BarsInProgress, Priority.High, " undefind bars in progress" + BarsInProgress, NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert1.wav", 10, Brushes.Black, Brushes.Yellow); break; } } private void BarsinProgress0() { if (IsFirstTickOfBar) { Value.Reset(); if (CrossAbove(EMA(9), EMA(22), 1)) { Draw.Text(this, "crossabove" + CurrentBar, "look for long", 1, Low[1]); //Draw.ArrowLine(this, "crossabove_" + CurrentBar, 1, bounds.Y, 1, bounds.height, Brushes.LimeGreen, DashStyleHelper.Dot, 2); Share("Twitter", Instrument.FullName + "Look for Long"); } else { if (CrossBelow(EMA(9), EMA(22), 1)) { Share("Twitter", Instrument.FullName + "Look for Short"); Draw.Text(this, "crossbelow" + CurrentBar, "look for short", 1, High[1]); Values[0][1] = 2; } } } // if it had crossed above recently, draw line from the start of the crossover to the end of crossover if (EMA(9)[0] > EMA(22)[0]) { } if (EMA(9)[0] < EMA(22)[0]) { } //Print(" start=" + start + " end " + end); // Process } } }
Comment
-
Originally posted by junkone View Postinteresting logic. i tried it but it does not plot anything.
Code:public class S_Trading_System : Indicator { protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "S_Trading_System"; Calculate = Calculate.OnEachTick; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = false; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; AddPlot(Brushes.Orange, "Mean"); } else if (State == State.Configure) { AddPlot(Brushes.Aqua, "EMA 9"); AddPlot(Brushes.DarkGray, "EMA 22"); } } protected override void OnBarUpdate() { //Add your custom indicator logic here. // Only process entry signals on a bar by bar basis (not tick by tick) switch (BarsInProgress) { case 0: BarsinProgress0(); break; case 1: Value[0] = EMA(9)[0]; break; case 2: Value[0] = EMA(22)[0]; break; default: Alert(" undefind bars in progress" + BarsInProgress, Priority.High, " undefind bars in progress" + BarsInProgress, NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert1.wav", 10, Brushes.Black, Brushes.Yellow); break; } } private void BarsinProgress0() { if (IsFirstTickOfBar) { Value.Reset(); if (CrossAbove(EMA(9), EMA(22), 1)) { Draw.Text(this, "crossabove" + CurrentBar, "look for long", 1, Low[1]); //Draw.ArrowLine(this, "crossabove_" + CurrentBar, 1, bounds.Y, 1, bounds.height, Brushes.LimeGreen, DashStyleHelper.Dot, 2); Share("Twitter", Instrument.FullName + "Look for Long"); } else { if (CrossBelow(EMA(9), EMA(22), 1)) { Share("Twitter", Instrument.FullName + "Look for Short"); Draw.Text(this, "crossbelow" + CurrentBar, "look for short", 1, High[1]); Values[0][1] = 2; } } } // if it had crossed above recently, draw line from the start of the crossover to the end of crossover if (EMA(9)[0] > EMA(22)[0]) { } if (EMA(9)[0] < EMA(22)[0]) { } //Print(" start=" + start + " end " + end); // Process } } }
In which case, BarsInProgress will always be zero, as you have not defined any other barSeries. In other words, your code is doing exactly what you wrote, and never accessing that which does not exist anyway. In your code, I see multiple artifices that depend on ideas that seem not to be clearly understood.
You came in here asking for help with something that you did not yet quite understand. Matthew gave you some annotated code to demonstrate what could be achieved. It might pay you better dividends if you took only that code, with no other ideas, and verified what that it does what you wish. Once, you are confident that the code does what you expect, further exploration of ideas is then much more viable.
Just my $0.02.
Comment
-
Originally posted by koganam View PostI am assuming that that is your entire code.
In which case, BarsInProgress will always be zero, as you have not defined any other barSeries. In other words, your code is doing exactly what you wrote, and never accessing that which does not exist anyway. In your code, I see multiple artifices that depend on ideas that seem not to be clearly understood.
You came in here asking for help with something that you did not yet quite understand. Matthew gave you some annotated code to demonstrate what could be achieved. It might pay you better dividends if you took only that code, with no other ideas, and verified what that it does what you wish. Once, you are confident that the code does what you expect, further exploration of ideas is then much more viable.
Just my $0.02.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by algospoke, Yesterday, 06:40 PM
|
2 responses
23 views
0 likes
|
Last Post
by algospoke
Today, 07:04 PM
|
||
Started by ghoul, Today, 06:02 PM
|
3 responses
14 views
0 likes
|
Last Post Today, 06:43 PM | ||
Started by jeronymite, 04-12-2024, 04:26 PM
|
3 responses
45 views
0 likes
|
Last Post
by jeronymite
Yesterday, 10:10 PM
|
||
Started by Barry Milan, Yesterday, 10:35 PM
|
7 responses
22 views
0 likes
|
Last Post Today, 06:16 PM | ||
Started by AttiM, 02-14-2024, 05:20 PM
|
10 responses
181 views
0 likes
|
Last Post
by jeronymite
Today, 06:11 PM
|
Comment