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!
See more
See less

Partner 728x90

Collapse

HH Lower Close

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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:
    #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

    #2
    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;
    You can find a full example of checking CurrentBar here:


    Give this a try and let me know if I can assist with anything else.
    DexterNinjaTrader Customer Service

    Comment


      #3
      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


        #4
        Originally posted by simpletrades View Post
        didnt work, and i do only need to check the prior bar as the comparison.
        I fixed it. i went back into my 6.5 indicators that used dots and noticed this:
        DrawDot("My dot" + CurrentBar, false, 0,High[0], Color.Red);

        mine was reading
        DrawDot("My dot" + CurrentBar, false, 0,0, Color.Red);

        Comment


          #5
          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


            #6
            Great, glad you got it working. If you need any additional assistance just let us know.
            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 drewski1980  
            Started by rdtdale, Yesterday, 01:02 PM
            2 responses
            17 views
            0 likes
            Last Post rdtdale
            by rdtdale
             
            Started by TradeSaber, Today, 07:18 AM
            0 responses
            7 views
            0 likes
            Last Post TradeSaber  
            Started by PaulMohn, Today, 05:00 AM
            0 responses
            10 views
            0 likes
            Last Post PaulMohn  
            Started by ZenCortexAuCost, Today, 04:24 AM
            0 responses
            6 views
            0 likes
            Last Post ZenCortexAuCost  
            Working...
            X