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

Please Assist: CCI Rising Falling Colors

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

    Please Assist: CCI Rising Falling Colors

    Hi,

    I have zero programming skills. However, I have attempted to alter the standard NT7 CCI indicator such that it plots Lime when rising and green when falling. This is my first attempt at programming and I simply tried to copy the sequence of code from another indicator that changes plot style based on rising and falling values.

    I post the code below in full and also attach the indicator file

    The compiler is telling me I have issues in the #region properties lines of code

    I'd really appreciate some assistance.

    Bondi9999

    ------------------------------------------------------------------------------------------------------
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
    /// </summary>
    [Description("The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.")]
    public class CCIColor : Indicator
    {
    #region Variables
    private int period = 14;
    #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()
    {
    Add(new Plot(Color.Lime, "CCIRising"));
    Add(new Plot(Color.DarkRed, "CCIFalling"));
    Add(new Line(Color.DarkGray, 200, "Level 2"));
    Add(new Line(Color.DarkGray, 100, "Level 1"));
    Add(new Line(Color.DarkGray, 0, "Zero line"));
    Add(new Line(Color.DarkGray, -100, "Level -1"));
    Add(new Line(Color.DarkGray, -200, "Level -2"));
    }

    /// <summary>
    /// Calculates the indicator value(s) at the current index.
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (CurrentBar == 0)
    Value.Set(0);
    else
    {
    double mean = 0;
    for (int idx = Math.Min(CurrentBar, Period - 1); idx >= 0; idx--)
    mean += Math.Abs(Typical[idx] - SMA(Typical, Period)[0]);
    Value.Set((Typical[0] - SMA(Typical, Period)[0]) / (mean == 0 ? 1 : (0.015 * (mean / Math.Min(Period, CurrentBar + 1)))));
    }
    if(CCIColor[1] < CCIColor[0])
    {
    CCIRising[1] = CCIColor[1];
    CCIRising.Set(CCIColor[0]);
    }
    else
    CCIFalling[1] = CCIColor[1];
    CCIFalling.Set(CCIColor[0]);
    }
    }

    #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 CCIFalling
    {
    get { return Value [1]; }
    }

    [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 CCIRising
    {
    get { return Values[0]; }
    }

    [Description("Numbers of bars used for calculations")]
    [GridCategory("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = 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 CCIColor[] cacheCCIColor = null;

    private static CCIColor checkCCIColor = new CCIColor();

    /// <summary>
    /// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
    /// </summary>
    /// <returns></returns>
    public CCIColor CCIColor(int period)
    {
    return CCIColor(Input, period);
    }

    /// <summary>
    /// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
    /// </summary>
    /// <returns></returns>
    public CCIColor CCIColor(Data.IDataSeries input, int period)
    {
    if (cacheCCIColor != null)
    for (int idx = 0; idx < cacheCCIColor.Length; idx++)
    if (cacheCCIColor[idx].Period == period && cacheCCIColor[idx].EqualsInput(input))
    return cacheCCIColor[idx];

    lock (checkCCIColor)
    {
    checkCCIColor.Period = period;
    period = checkCCIColor.Period;

    if (cacheCCIColor != null)
    for (int idx = 0; idx < cacheCCIColor.Length; idx++)
    if (cacheCCIColor[idx].Period == period && cacheCCIColor[idx].EqualsInput(input))
    return cacheCCIColor[idx];

    CCIColor indicator = new CCIColor();
    indicator.BarsRequired = BarsRequired;
    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
    indicator.Input = input;
    indicator.Period = period;
    Indicators.Add(indicator);
    indicator.SetUp();

    CCIColor[] tmp = new CCIColor[cacheCCIColor == null ? 1 : cacheCCIColor.Length + 1];
    if (cacheCCIColor != null)
    cacheCCIColor.CopyTo(tmp, 0);
    tmp[tmp.Length - 1] = indicator;
    cacheCCIColor = 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>
    /// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.CCIColor CCIColor(int period)
    {
    return _indicator.CCIColor(Input, period);
    }

    /// <summary>
    /// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
    /// </summary>
    /// <returns></returns>
    public Indicator.CCIColor CCIColor(Data.IDataSeries input, int period)
    {
    return _indicator.CCIColor(input, period);
    }
    }
    }

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    public partial class Strategy : StrategyBase
    {
    /// <summary>
    /// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.CCIColor CCIColor(int period)
    {
    return _indicator.CCIColor(Input, period);
    }

    /// <summary>
    /// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
    /// </summary>
    /// <returns></returns>
    public Indicator.CCIColor CCIColor(Data.IDataSeries input, int period)
    {
    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.CCIColor(input, period);
    }
    }
    }
    #endregion
    Attached Files

    #2
    Hello Bondi999,

    Most likely you need to correct the line below: Change from Value to Values.

    public DataSeries CCIFalling
    {
    get { return Values [1]; }
    }

    If this isn't it, please let us know the exact line that's causing issues and what the specific error message is.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Did not do the trick

      Hi Ryan,

      I still received error messages. I have attached an image of the area of code in question and the compiler output.

      Cheers
      Attached Files

      Comment


        #4
        Bondi9999, you are missing a bracket before the code of your last else statement in OnBarUpdate(). After I fixed that, there are a number of other errors that appear that have to do with trying to set a plot without initializing any plots.
        Attached Files
        AustinNinjaTrader Customer Service

        Comment


          #5
          Here you go

          I did some canges to the script.

          Please look at lines 28, 29, 72 to 79 and of course the changes in the Properties section.

          Hopefully this is what you are looking for

          Regards
          Finn Jurbol
          Attached Files

          Comment


            #6
            Finn, I will have Ryan get back to you tomorrow.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Hi Finn Jurbol,

              I can't thank you enough for your assistance with this.

              All the best and good trading,

              Bondi9999

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Mindset, 05-06-2023, 09:03 PM
              10 responses
              262 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by michi08, 10-05-2018, 09:31 AM
              5 responses
              741 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by The_Sec, Today, 02:29 PM
              0 responses
              2 views
              0 likes
              Last Post The_Sec
              by The_Sec
               
              Started by tsantospinto, 04-12-2024, 07:04 PM
              4 responses
              62 views
              0 likes
              Last Post aligator  
              Started by sightcareclickhere, Today, 01:55 PM
              0 responses
              1 view
              0 likes
              Last Post sightcareclickhere  
              Working...
              X