#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class HighLow : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Plots Highs and Lows";
Name = "HighLow";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = false;
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(new Stroke(Brushes.Green, 2), PlotStyle.TriangleUp, "High");
AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.TriangleDown, "Low");
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (CurrentBar<1)
return;
// Condition set 1
if (High[0] > High[1]
&& High[0] > High[-1]
&& High[0] > High[2]
&& High[0] > High[-2])
{
AddPlot(new Stroke(Brushes.Green, 2), PlotStyle.TriangleUp, "High");
}
// Condition set 2
if (Low[0] < Low[1]
&& Low[0] < Low[-1]
&& Low[0] < Low[2]
&& Low[0] < Low[-2])
{
AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.TriangleDown, "Low");
}
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> High
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> Low
{
get { return Values[1]; }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private HighLow[] cacheHighLow;
public HighLow HighLow()
{
return HighLow(Input);
}
public HighLow HighLow(ISeries<double> input)
{
if (cacheHighLow != null)
for (int idx = 0; idx < cacheHighLow.Length; idx++)
if (cacheHighLow[idx] != null && cacheHighLow[idx].EqualsInput(input))
return cacheHighLow[idx];
return CacheIndicator<HighLow>(new HighLow(), input, ref cacheHighLow);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.HighLow HighLow()
{
return indicator.HighLow(Input);
}
public Indicators.HighLow HighLow(ISeries<double> input )
{
return indicator.HighLow(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.HighLow HighLow()
{
return indicator.HighLow(Input);
}
public Indicators.HighLow HighLow(ISeries<double> input )
{
return indicator.HighLow(input);
}
}
}
#endregion
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Need Help with custom NT8 Indicator script
Collapse
X
-
Need Help with custom NT8 Indicator script
Hello, i am not a scripter by any means i originally made this as an NT7 strategy and converted to indicator. I see in NT8 i never had to do that, but its not actually plotting... there are no errors on the scripter... please help, the indicator is supposed to plot at triangle just above a high that is higher than two bars to the left or right, and just below a low that is lower than two bars to the right or left. thanks ahead of time!
PHP Code:Tags: None
-
Hello Columbcille,
Thanks for your post.
In Ninjatrader8 to output to the plot you must use the plot name followed by the bar index value (typically [0]), however the complication is that you have named your plots High and Low which will conflict with the normal High and Low bar references. So step 1 is to rename your plots to something like High1 and Low1 just to make them different. Make sure to change them not only in the state.Defaults but also in the region properties, for example:
IsSuspendedWhileInactive = true;
AddPlot(new Stroke(Brushes.Green, 2), PlotStyle.TriangleUp, "High1");
AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.TriangleDown, "Low1");
... and
[Browsable(false)]
[XmlIgnore]
public Series<double> High1
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> Low1
{
get { return Values[1]; }
}
Next, to output the plots you would assign a value to them when the condition you have are true. For example:
High1[0] = High[0] + 2 * TickSize; // Place triangle 2 ticks above the high
Low1[0] = Low[0] - 2 * TickSize; // place triangle 2 ticks below the low
Finally, the conditions, they are not correct as you cannot use a negative barsago number which would be a bar in the future that does not exist. You will generate a bars ago reference error.
Once you have your logic in place you will also need to add a line like:
if (CurrentBar < 2) return; // do not process the first 3 bars
If you are looking at a bar index of [2] then you need to make sure 3 bars are loaded first and the above statement will have you covered.Paul H.NinjaTrader Customer Service
-
so i THINK ive understood you, renamed the high and low to Highs and Lows (wasnt sure if 1 was actually necessary, and changed the parameter script... now it just crashes NT LOL
PHP Code://This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class HighLow : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Plots Highs and Lows";
Name = "HighLow";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = false;
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(new Stroke(Brushes.Green, 2), PlotStyle.TriangleUp, "Highs");
AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.TriangleDown, "Lows");
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (CurrentBar<2)
return; // do not process the first 3 bars
// Condition set 1
Highs[0] = High[0] + 2 * TickSize; // Place triangle 2 ticks above the high
{
AddPlot(new Stroke(Brushes.Green, 2), PlotStyle.TriangleUp, "Highs");
}
// Condition set 2
Lows[0] = Low[0] - 2 * TickSize; // place triangle 2 ticks below the low
{
AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.TriangleDown, "Lows");
}
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> Highs
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> Lows
{
get { return Values[1]; }
}
#endregion
}
}
Comment
-
Originally posted by Columbcille View Postso i THINK ive understood you, renamed the high and low to Highs and Lows (wasnt sure if 1 was actually necessary, and changed the parameter script... now it just crashes NT LOL
PHP Code://This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class HighLow : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Plots Highs and Lows";
Name = "HighLow";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = false;
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(new Stroke(Brushes.Green, 2), PlotStyle.TriangleUp, "Highs");
AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.TriangleDown, "Lows");
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (CurrentBar<2)
return; // do not process the first 3 bars
// Condition set 1
Highs[0] = High[0] + 2 * TickSize; // Place triangle 2 ticks above the high
{
AddPlot(new Stroke(Brushes.Green, 2), PlotStyle.TriangleUp, "Highs");
}
// Condition set 2
Lows[0] = Low[0] - 2 * TickSize; // place triangle 2 ticks below the low
{
AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.TriangleDown, "Lows");
}
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> Highs
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> Lows
{
get { return Values[1]; }
}
#endregion
}
}
Use the given suggestion, High1 etc.,
Comment
-
Originally posted by koganam View PostIncorrect use of the reserved word Highs, Lows, which have a very specific meaning in NT: a specific meaning which would likely cause NT to crash if used in the manner that you have.
Use the given suggestion, High1 etc.,
Comment
-
Hello Columbcille,
Thanks for your replies.
In your code:
Highs[0] = High[0] + 2 * TickSize; // Place triangle 2 ticks above the high
{
AddPlot(new Stroke(Brushes.Green, 2), PlotStyle.TriangleUp, "Highs");
}
// Condition set 2
Lows[0] = Low[0] - 2 * TickSize; // place triangle 2 ticks below the low
{
AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.TriangleDown, "Lows");
}
You would need to delete both of the AddPlot(...) lines.Paul H.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Paul View PostHello Columbcille,
Thanks for your replies.
In your code:
Highs[0] = High[0] + 2 * TickSize; // Place triangle 2 ticks above the high
{
AddPlot(new Stroke(Brushes.Green, 2), PlotStyle.TriangleUp, "Highs");
}
// Condition set 2
Lows[0] = Low[0] - 2 * TickSize; // place triangle 2 ticks below the low
{
AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.TriangleDown, "Lows");
}
You would need to delete both of the AddPlot(...) lines.
PHP Code:#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class HighLow : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Plots Highs and Lows";
Name = "HighLow";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = false;
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(new Stroke(Brushes.Green, 2), PlotStyle.TriangleUp, "High1");
AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.TriangleDown, "Low1");
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (CurrentBar<2)
return; // do not process the first 3 bars
// Condition set 1
High1[0] = High[0] + 2 * TickSize; // Place triangle 2 ticks above the high
// Condition set 2
Low1[0] = Low[0] - 2 * TickSize; // place triangle 2 ticks below the low
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> High1
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> Low1
{
get { return Values[1]; }
}
#endregion
}
}
Comment
-
Originally posted by NinjaTrader_Paul View PostHello Columbcille,
Thanks for your reply.
Yes, the code shown should compile and run. The output will be a red and green triangle on every bar.
Comment
-
Comment
-
Hello Columbcille,
Thanks for your reply.
That is the issue you will need to resolve. You cannot know what future bars will do so you would need to test for the high being higher than the next two bars which means you would not be able to identify the high until two more bars have passed.
In that regard then you could only test when the current bar is the 2nd bar past the high.
Here is an example:
if (High[0] < High[2] && High[1] < High[2] && High[3] < High[2] && High[4] < High[2])
{
High1[2] = High[2] + 2 * TickSize; //plot triangle 2 bars ago
}
I've attached a picture that will illustrate the bar references related above.Paul H.NinjaTrader Customer Service
Comment
-
ok i get what youre saying, the script you posted looked like what i had in NT& so i copied and pasted, but now it crashes again...
This works
PHP Code:if (CurrentBar < 2) return; // do not process the first 3 bars
// Condition set 1
if (High[0] > High[1]
&& High[0] > High[2])
High1[0] = High[0] + 5 * TickSize; //plot triangle
PHP Code:if (CurrentBar < 2) return; // do not process the first 3 bars
// Condition set 1
if (High[2] > High[0]
&& High[2] > High[1]
&& High[2] > High[3]
&& High[2] > High[4])
High1[2] = High[2] + 5 * TickSize; //plot triangle
Do i need to change something withing the properties field values?
PHP Code:#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> Low1
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> High1
{
get { return Values[1]; }
}
#endregion
Comment
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Haiasi, Today, 06:53 PM
|
1 response
3 views
0 likes
|
Last Post Today, 07:05 PM | ||
Started by ScottWalsh, Today, 06:52 PM
|
1 response
6 views
0 likes
|
Last Post Today, 07:02 PM | ||
Started by ScottW, Today, 06:09 PM
|
1 response
4 views
0 likes
|
Last Post Today, 06:53 PM | ||
Started by ftsc2022, 10-25-2022, 12:03 PM
|
5 responses
256 views
0 likes
|
Last Post Today, 06:48 PM | ||
Started by Board game geek, 10-29-2023, 12:00 PM
|
14 responses
244 views
0 likes
|
Last Post
by DJ888
Today, 05:38 PM
|
Comment