#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.Indicator; using NinjaTrader.Gui.Chart; #endregion // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// Bar makes a higher high but closes lower than the prior bar. /// </summary> [Description("Bar makes a higher high but closes lower than the prior bar.")] public class HigherHighLowerClose : Indicator { #region Variables // Wizard generated variables private int myInput0 = 1; // Default setting for MyInput0 // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Condition set 1 if (High[0] > High[1] && Close[0] < Open[1]) { DrawDot("My dot" + CurrentBar, false, 0, 0, Color.Red); Alert("MyAlert0", Priority.High, "HH Lower Close", @"C:\Program Files\NinjaTrader 7\sounds\Alert2.wav", 0, Color.White, Color.Black); } } #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 Plot0 { get { return Values[0]; } } [Description("")] [GridCategory("Parameters")] public int MyInput0 { get { return myInput0; } set { myInput0 = Math.Max(1, value); } } #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 HigherHighLowerClose[] cacheHigherHighLowerClose = null; private static HigherHighLowerClose checkHigherHighLowerClose = new HigherHighLowerClose(); /// <summary> /// Bar makes a higher high but closes lower than the prior bar. /// </summary> /// <returns></returns> public HigherHighLowerClose HigherHighLowerClose(int myInput0) { return HigherHighLowerClose(Input, myInput0); } /// <summary> /// Bar makes a higher high but closes lower than the prior bar. /// </summary> /// <returns></returns> public HigherHighLowerClose HigherHighLowerClose(Data.IDataSeries input, int myInput0) { if (cacheHigherHighLowerClose != null) for (int idx = 0; idx < cacheHigherHighLowerClose.Length; idx++) if (cacheHigherHighLowerClose[idx].MyInput0 == myInput0 && cacheHigherHighLowerClose[idx].EqualsInput(input)) return cacheHigherHighLowerClose[idx]; lock (checkHigherHighLowerClose) { checkHigherHighLowerClose.MyInput0 = myInput0; myInput0 = checkHigherHighLowerClose.MyInput0; if (cacheHigherHighLowerClose != null) for (int idx = 0; idx < cacheHigherHighLowerClose.Length; idx++) if (cacheHigherHighLowerClose[idx].MyInput0 == myInput0 && cacheHigherHighLowerClose[idx].EqualsInput(input)) return cacheHigherHighLowerClose[idx]; HigherHighLowerClose indicator = new HigherHighLowerClose(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.MyInput0 = myInput0; Indicators.Add(indicator); indicator.SetUp(); HigherHighLowerClose[] tmp = new HigherHighLowerClose[cacheHigherHighLowerClose == null ? 1 : cacheHigherHighLowerClose.Length + 1]; if (cacheHigherHighLowerClose != null) cacheHigherHighLowerClose.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheHigherHighLowerClose = 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> /// Bar makes a higher high but closes lower than the prior bar. /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.HigherHighLowerClose HigherHighLowerClose(int myInput0) { return _indicator.HigherHighLowerClose(Input, myInput0); } /// <summary> /// Bar makes a higher high but closes lower than the prior bar. /// </summary> /// <returns></returns> public Indicator.HigherHighLowerClose HigherHighLowerClose(Data.IDataSeries input, int myInput0) { return _indicator.HigherHighLowerClose(input, myInput0); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// <summary> /// Bar makes a higher high but closes lower than the prior bar. /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.HigherHighLowerClose HigherHighLowerClose(int myInput0) { return _indicator.HigherHighLowerClose(Input, myInput0); } /// <summary> /// Bar makes a higher high but closes lower than the prior bar. /// </summary> /// <returns></returns> public Indicator.HigherHighLowerClose HigherHighLowerClose(Data.IDataSeries input, int myInput0) { 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.HigherHighLowerClose(input, myInput0); } } } #endregion
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
HH Lower Close
Collapse
X
-
HH Lower Close
I wanted a dot above if the bar made a higher high but closed below the prior bar's open. This script compiles but doesnt work.
HTML Code:Tags: None
-
Hello simpletrades,
Thank you for your post.
Looking at your condition set 1 logic, you access data from the previous bar without first checking you have more than one bar. If this is the case, you will get an exception in the output window.
You can check that CurrentBar is greater than or equal to the number of bars you require so you don't try to access a bar that does not yet exist. CurrentBar starts from zero. If you want to make sure you have at least two bars for example:
Code:if(CurrentBar < 1) return;
Give this a try and let me know if I can assist with anything else.DexterNinjaTrader Customer Service
-
didnt work, and i do only need to check the prior bar as the comparison.
do i need to set up a color plot for the dot like i would if it were drawing anindicator?
Comment
-
Originally posted by simpletrades View Postdidnt work, and i do only need to check the prior bar as the comparison.
DrawDot("My dot" + CurrentBar, false, 0,High[0], Color.Red);
mine was reading
DrawDot("My dot" + CurrentBar, false, 0,0, Color.Red);
Comment
-
simpletrades,
Thank you for your reply.
I noticed on your DrawDot, you have 0 for a y value. This would draw the dot on the very bottom of the chart which is probably not desirable when using overlay on price. If you want to draw the Dot right at the close price, try:
DrawDot("My dot" + CurrentBar, false, 0, Close[0], Color.Red);
Let me know if it is still not visible.DexterNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by drewski1980, Today, 08:24 AM
|
0 responses
3 views
0 likes
|
Last Post
by drewski1980
Today, 08:24 AM
|
||
Started by rdtdale, Yesterday, 01:02 PM
|
2 responses
17 views
0 likes
|
Last Post
by rdtdale
Today, 07:54 AM
|
||
Started by TradeSaber, Today, 07:18 AM
|
0 responses
7 views
0 likes
|
Last Post
by TradeSaber
Today, 07:18 AM
|
||
Started by PaulMohn, Today, 05:00 AM
|
0 responses
10 views
0 likes
|
Last Post
by PaulMohn
Today, 05:00 AM
|
||
Started by ZenCortexAuCost, Today, 04:24 AM
|
0 responses
6 views
0 likes
|
Last Post Today, 04:24 AM |
Comment