Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
how to plot existing indicator in another indicator
Collapse
X
-
Originally posted by koganam View Post
-
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.
Leave a 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 } } }
Leave a 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]; }
Leave a comment:
-
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.
Leave a comment:
-
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).
Leave a comment:
-
how to plot existing indicator in another indicator
1. i started coding a indicator and realized, i want to plot the EMA(9) on the chart when my indicator gets displayed. how do i add it to it?Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by SnailHorn, 03-27-2024, 09:54 AM
|
4 responses
17 views
0 likes
|
Last Post
by SnailHorn
Today, 09:19 AM
|
||
Started by ninza33, Today, 07:16 AM
|
3 responses
18 views
0 likes
|
Last Post
by ninza33
Today, 09:01 AM
|
||
Started by foxtrott21, Today, 08:27 AM
|
0 responses
4 views
0 likes
|
Last Post
by foxtrott21
Today, 08:27 AM
|
||
Started by jaypelle3, Today, 08:26 AM
|
0 responses
3 views
0 likes
|
Last Post
by jaypelle3
Today, 08:26 AM
|
||
Started by linkcou, Today, 07:01 AM
|
2 responses
26 views
0 likes
|
Last Post
by bltdavid
Today, 08:25 AM
|
Leave a comment: