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

public bool ZeroLine in Parameters

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

    public bool ZeroLine in Parameters

    Hello. What is wrong in this code in indicator
    [Description("displaying zeroline")]
    [GridCategory("Parameters")]
    public bool ZeroLine
    {
    get { return zeroLine; }
    }


    If it == true, indicator display zero line.

    #2
    Hi alexstox,

    There is no set { } for this public variable.

    Why have this variable if it doesn't set anything?

    If you are planning to use it just to return a value with the get { }, you will still need a set { } to prevent an error.

    Take a look at the Period public property of the SMA indicator for an example.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      #region Variables
      private bool zeroLine = true;
      ...............
      protected override void Initialize()
      {
      if (ZeroLine==true) {Add(new Line(Color.Gray, 0, "zeroline"));}
      .................
      #region Properties
      [Description("displaying zeroline")]
      [GridCategory("Parameters")]
      public bool ZeroLine
      {
      set { zeroLine; }
      }


      Still doesn't work.

      Comment


        #4
        Hello alexstox,

        You have now removed the get { } which will also cause an error.

        Do you see errors appearing at the bottom of the NinjaScript editor window when you try and compile this?

        What do these errors say?

        Please take a look at the Period public property in the SMA indicator. This has a get { } and set { }. You will need both.

        Also, you are not setting anything in set.

        Improper code:
        public bool ZeroLine
        {
        set { zeroLine; }
        }

        If you don't want to set zeroLine then do not add zeroLine; to the set function.

        Proper code (for not setting the zeroLine)
        public bool ZeroLine
        {
        set { }
        }

        Proper code (for setting the zeroLine)
        public bool ZeroLine
        {
        set { zeroLine = value; }
        }
        Last edited by NinjaTrader_ChelseaB; 03-19-2014, 09:54 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          #region Variables
          private bool zeroLine = true;
          ...............
          protected override void Initialize()
          {
          if (ZeroLine==true) {Add(new Line(Color.Gray, 0, "zeroline"));}
          .................
          #region Properties
          [Description("displaying zeroline")]
          [GridCategory("Parameters")]
          public bool ZeroLine
          {
          get { return zeroLine; }
          set { zeroLine; }
          }


          As you see this variable is only for on/off Zero line in indicator.

          This doesn't help.
          Error (translation from Russian in Google): As the operator can use an assignment expression, call increment, decrement, and create a new object - CS0201

          This error about zeroLine in set { zeroLine; }

          As you see this variable is only for on/off Zero line in indicator.
          Last edited by alexstox; 03-19-2014, 09:28 AM.

          Comment


            #6
            alexstox,

            Please see post #4.
            http://www.ninjatrader.com/support/f....php?t=64768#4

            You are not setting anything in set.

            Improper code:
            public bool ZeroLine
            {
            set { zeroLine; }
            }

            If you don't want to set zeroLine then do not add zeroLine; to the set function.

            Proper code (for not setting the zeroLine)
            public bool ZeroLine
            {
            set { }
            }

            Proper code (for setting the zeroLine)
            public bool ZeroLine
            {
            set { zeroLine = value; }
            }
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              1) What is right in my case: to set or not to set? If I need ZeroLine variable only to ON/OFF displaying zero line in indicator?

              2) "get" is not used with bool?

              Comment


                #8
                Hi alexstox,

                1) Yes, you need a set { } and a get { } no matter what.

                If you are wanting a parameter that you can set when starting the script you have to set the private variable to the current value of the public variable in set { }.

                2) No, public bools also need both a get { } and a set { }.

                The code you are looking for is this.

                public bool ZeroLine
                {
                get { return zeroLine; }
                set { zeroLine = value; }
                }
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by alexstox View Post
                  #region Variables
                  private bool zeroLine = true;
                  ...............
                  protected override void Initialize()
                  {
                  if (ZeroLine==true) {Add(new Line(Color.Gray, 0, "zeroline"));}
                  .................
                  #region Properties
                  [Description("displaying zeroline")]
                  [GridCategory("Parameters")]
                  public bool ZeroLine
                  {
                  get { return zeroLine; }
                  set { zeroLine; }
                  }


                  As you see this variable is only for on/off Zero line in indicator.

                  This doesn't help.
                  Error (translation from Russian in Google): As the operator can use an assignment expression, call increment, decrement, and create a new object - CS0201

                  This error about zeroLine in set { zeroLine; }

                  As you see this variable is only for on/off Zero line in indicator.
                  Code:
                  set { zeroLine = [SIZE=3][B][COLOR=Red]value[/COLOR][/B][/SIZE]; }

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by GussJ, 03-04-2020, 03:11 PM
                  16 responses
                  3,281 views
                  0 likes
                  Last Post Leafcutter  
                  Started by WHICKED, Today, 12:45 PM
                  2 responses
                  19 views
                  0 likes
                  Last Post WHICKED
                  by WHICKED
                   
                  Started by Tim-c, Today, 02:10 PM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by Taddypole, Today, 02:47 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post Taddypole  
                  Started by chbruno, 04-24-2024, 04:10 PM
                  4 responses
                  53 views
                  0 likes
                  Last Post chbruno
                  by chbruno
                   
                  Working...
                  X