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

DonchianWidth

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

    DonchianWidth

    Hello to everybody,
    my first post
    never programmed in my life, I’m trying to build the Donchian channel Width using the wizard
    following the instruction I replaced 'Close[0]'with my formula,
    Plot0.Set(DonchianChannel(Period).Upper[0] - DonchianChannel(Period).Lower[0]);
    I’m getting errors CS1518, CS101, CS1022, CS1518, clicked for info but the answer is Unfortunately we do not have NinjaScript context based Help information on this specific error code. You can check the Microsoft MSDN site section on error codes for futher information, there Iget the message:
    This section is a reference to the errors generated by the C# compiler. To get help on a particular error message, either click the mouse on an error number in the Output window and press F1, or type the error number in the Look for box in the Index.
    This is too far for me, what I can do to fix the errors?
    I’ll appreciate any help

    brunox
    Attached Files

    #2
    Plain code

    Here the code, in this way you do not have to import the .cs file to see it, please forgive my broken English
    brunox
    ///*********************************


    #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.Gui.Chart;
    #endregion

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// The name is self explaining
    /// </summary>
    [Description("The name is self explaining")]
    public class DonchianWidth1 : 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()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Aqua), PlotStyle.Line, "Plot0"));
    Overlay = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    Plot0.Set(DonchianChannel(Period).Upper[0] - DonchianChannel(Period).Lower[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 Plot0
    {
    get { return Values[0]; }
    }

    [Description("DonchianWidth")]
    [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 DonchianWidth1[] cacheDonchianWidth1 = null;

    private static DonchianWidth1 checkDonchianWidth1 = new DonchianWidth1();

    /// <summary>
    /// The name is self explaining
    /// </summary>
    /// <returns></returns>
    public DonchianWidth1 DonchianWidth1(int myInput0)
    {
    return DonchianWidth1(Input, myInput0);
    }

    /// <summary>
    /// The name is self explaining
    /// </summary>
    /// <returns></returns>
    public DonchianWidth1 DonchianWidth1(Data.IDataSeries input, int myInput0)
    {
    if (cacheDonchianWidth1 != null)
    for (int idx = 0; idx < cacheDonchianWidth1.Length; idx++)
    if (cacheDonchianWidth1[idx].MyInput0 == myInput0 && cacheDonchianWidth1[idx].EqualsInput(input))
    return cacheDonchianWidth1[idx];

    lock (checkDonchianWidth1)
    {
    checkDonchianWidth1.MyInput0 = myInput0;
    myInput0 = checkDonchianWidth1.MyInput0;

    if (cacheDonchianWidth1 != null)
    for (int idx = 0; idx < cacheDonchianWidth1.Length; idx++)
    if (cacheDonchianWidth1[idx].MyInput0 == myInput0 && cacheDonchianWidth1[idx].EqualsInput(input))
    return cacheDonchianWidth1[idx];

    DonchianWidth1 indicator = new DonchianWidth1();
    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();

    DonchianWidth1[] tmp = new DonchianWidth1[cacheDonchianWidth1 == null ? 1 : cacheDonchianWidth1.Length + 1];
    if (cacheDonchianWidth1 != null)
    cacheDonchianWidth1.CopyTo(tmp, 0);
    tmp[tmp.Length - 1] = indicator;
    cacheDonchianWidth1 = 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 name is self explaining
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.DonchianWidth1 DonchianWidth1(int myInput0)
    {
    return _indicator.DonchianWidth1(Input, myInput0);
    }

    /// <summary>
    /// The name is self explaining
    /// </summary>
    /// <returns></returns>
    public Indicator.DonchianWidth1 DonchianWidth1(Data.IDataSeries input, int myInput0)
    {
    return _indicator.DonchianWidth1(input, myInput0);
    }
    }
    }

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    public partial class Strategy : StrategyBase
    {
    /// <summary>
    /// The name is self explaining
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.DonchianWidth1 DonchianWidth1(int myInput0)
    {
    return _indicator.DonchianWidth1(Input, myInput0);
    }

    /// <summary>
    /// The name is self explaining
    /// </summary>
    /// <returns></returns>
    public Indicator.DonchianWidth1 DonchianWidth1(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.DonchianWidth1(input, myInput0);
    }
    }
    }
    #endregion

    Comment


      #3
      Hi brunox, because the errors listed are highlighted in red, that means the error is coming from another script. In this case, the error is coming from the DonchianWidth.cs file. The code in your DonchianWidth1.cs file looks fine. My recommendation would be to delete the original (width.cs) and then try compiling the new one (width1.cs). To delete the original, you can go to Tools -> Edit NinjaScript -> Indicator -> select DonchianWidth and then hit the delete button.

      Let me know if you have any other questions.
      AustinNinjaTrader Customer Service

      Comment


        #4
        Thank you, now is working

        Hi Austin,
        thank you, now is working.
        The value is in point (0,11), it will be better in ticks (11), then I used:
        Plot0.Set(DonchianChannel(dCPeriod).Upper[0] - DonchianChannel(dCPeriod).Lower[0])*100;
        But it is not working, I tried many different symbol combination ; ()[] without any succes
        I’ll appreciate any help
        Attached Files

        Comment


          #5
          brunox,

          I am responding on behalf of Austin.

          Plot0.Set(DonchianChannel(dCPeriod).Upper[0] - DonchianChannel(dCPeriod).Lower[0])*100;

          Is incorrect, you want to put the 100 inside the Plot0.Set() parenthesis like this :

          Plot0.Set( (DonchianChannel(dCPeriod).Upper[0] - DonchianChannel(dCPeriod).Lower[0])*100 ) ;

          Please let me know if I may assist further.
          Adam P.NinjaTrader Customer Service

          Comment


            #6
            Thank you very much, is working

            Hi AdamP,
            Thank you very much, is working
            brunox
            Attached Files

            Comment


              #7
              brunox,

              No problem.

              Don't hesitate to contact us should you require additional assistance.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                R/R Ratio

                Hello,
                I’m trying to calculate an hypothetic risk reward ratio, my string seems to be fine but I’m getting error on line 45 column 13 (Plot0.set) that is written by the wizard; I checked the errors code info but I’m incapable to understand the meaning.
                I’ll appreciate if someone can help me to correct the error and understand why the code is wrong.

                Thank you very much
                brunox

                *-*-*-*-*


                #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.Gui.Chart;
                #endregion

                // This namespace holds all indicators and is required. Do not change it.
                namespace NinjaTrader.Indicator
                {
                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                [Description("Enter the description of your new custom indicator here")]
                public class RRLONG : Indicator
                {
                #region Variables
                // Wizard generated variables
                private int stop = 8; // Default setting for Stop
                private int target = 89; // Default setting for Target
                // 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()
                {
                Add(new Plot(Color.FromKnownColor(KnownColor.Aqua), PlotStyle.Line, "Plot0"));
                Overlay = false;
                }

                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
                Plot0.Set(DonchianChannel(Target).Upper[0] - DonchianChannel(Stop).Upper[0])*100 /(DonchianChannel(Stop).Upper[0] - DonchianChannel(Stop).Lower[0])*100 ;
                }

                #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 Stop
                {
                get { return stop; }
                set { stop = Math.Max(1, value); }
                }

                [Description("")]
                [GridCategory("Parameters")]
                public int Target
                {
                get { return target; }
                set { target = 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 RRLONG[] cacheRRLONG = null;

                private static RRLONG checkRRLONG = new RRLONG();

                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                public RRLONG RRLONG(int stop, int target)
                {
                return RRLONG(Input, stop, target);
                }

                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                public RRLONG RRLONG(Data.IDataSeries input, int stop, int target)
                {
                if (cacheRRLONG != null)
                for (int idx = 0; idx < cacheRRLONG.Length; idx++)
                if (cacheRRLONG[idx].Stop == stop && cacheRRLONG[idx].Target == target && cacheRRLONG[idx].EqualsInput(input))
                return cacheRRLONG[idx];

                lock (checkRRLONG)
                {
                checkRRLONG.Stop = stop;
                stop = checkRRLONG.Stop;
                checkRRLONG.Target = target;
                target = checkRRLONG.Target;

                if (cacheRRLONG != null)
                for (int idx = 0; idx < cacheRRLONG.Length; idx++)
                if (cacheRRLONG[idx].Stop == stop && cacheRRLONG[idx].Target == target && cacheRRLONG[idx].EqualsInput(input))
                return cacheRRLONG[idx];

                RRLONG indicator = new RRLONG();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
                #if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
                #endif
                indicator.Input = input;
                indicator.Stop = stop;
                indicator.Target = target;
                Indicators.Add(indicator);
                indicator.SetUp();

                RRLONG[] tmp = new RRLONG[cacheRRLONG == null ? 1 : cacheRRLONG.Length + 1];
                if (cacheRRLONG != null)
                cacheRRLONG.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheRRLONG = 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>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                [Gui.Design.WizardCondition("Indicator")]
                public Indicator.RRLONG RRLONG(int stop, int target)
                {
                return _indicator.RRLONG(Input, stop, target);
                }

                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                public Indicator.RRLONG RRLONG(Data.IDataSeries input, int stop, int target)
                {
                return _indicator.RRLONG(input, stop, target);
                }
                }
                }

                // This namespace holds all strategies and is required. Do not change it.
                namespace NinjaTrader.Strategy
                {
                public partial class Strategy : StrategyBase
                {
                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                [Gui.Design.WizardCondition("Indicator")]
                public Indicator.RRLONG RRLONG(int stop, int target)
                {
                return _indicator.RRLONG(Input, stop, target);
                }

                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                public Indicator.RRLONG RRLONG(Data.IDataSeries input, int stop, int target)
                {
                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.RRLONG(input, stop, target);
                }
                }
                }
                #endregion
                Attached Files

                Comment


                  #9
                  Sorry

                  My string is:
                  Plot0.Set(DonchianChannel(Target).Upper[0] - DonchianChannel(Stop).Upper[0])*100 /(DonchianChannel(Stop).Upper[0] - DonchianChannel(Stop).Lower[0])*100 ;

                  The errors code are CS0201 (Error Code Explanation This error can occur when you make a statement solely from an indicator or variable call. You will need to do something with the value you called for the statement to be complete.)

                  and CS0019 (The following CS0019 error code information is provided within the context of NinjaScript. The examples provided are only a subset of potential problems that this error code may reflect. In any case, the examples below provide a reference of coding flaw possibilities. Error Code Explanation Strings cannot be compared with relational operators (<, >, <=, >=, ==, !=) to other object types. Strings can only be compared to other strings and only through the use of equality operators (==, !=).)

                  Brunox

                  Comment


                    #10
                    brunox,

                    Are stop and target supposed to be periods?

                    Also, try this :

                    Plot0.Set( ( DonchianChannel(Target).Upper[0] - DonchianChannel(Stop).Upper[0] ) / ( DonchianChannel(Stop).Upper[0] - DonchianChannel(Stop).Lower[0] ) ) ;

                    Essentially, I believe you are trying to divide A-B by C-D , and the proper way to do this is (A-B) / (C-D), then you need to assign it to your plot with Plot0.Set( (A-B)/(C-D) ) so the parenthesis in the Plot0.Set() needs to totally enclose your calculation.

                    Please let me know if I may assist further.
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi AdamP,
                      Thank you for your answer

                      This is a working string
                      Plot0.Set((((DonchianChannel(DCperiod1).Upper[0] - DonchianChannel(DCperiod0).Upper[0])*100))/((DonchianChannel(DCperiod0).Upper[0] - DonchianChannel(DCperiod0).Lower[0])*100));


                      Thank you for you assistence
                      brunox

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by GLFX005, Today, 03:23 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post GLFX005
                      by GLFX005
                       
                      Started by XXtrader, Yesterday, 11:30 PM
                      2 responses
                      11 views
                      0 likes
                      Last Post XXtrader  
                      Started by Waxavi, Today, 02:10 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post Waxavi
                      by Waxavi
                       
                      Started by TradeForge, Today, 02:09 AM
                      0 responses
                      11 views
                      0 likes
                      Last Post TradeForge  
                      Started by Waxavi, Today, 02:00 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post Waxavi
                      by Waxavi
                       
                      Working...
                      X