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

field initializer

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

    field initializer

    I have the following:

    #region Variables
    public int dotsize = 10;

    private
    Font pfont = new Font("Arial", dotsize, FontStyle.Bold, GraphicsUnit.Point);

    when I place "dotsize" in the code i get an error:

    A field initializer cannot reference the nonstatic field, method, or property

    When I type
    private Font pfont = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point);

    everything is fine. How do I swap the word dotsize for the number 10 ?
    Last edited by velocity; 03-18-2009, 11:04 AM.

    #2
    Is that "publicint" a typo? If not, I believe it should be:

    private int dotsize = 10;
    Last edited by eDanny; 03-18-2009, 07:05 AM.
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      You likely can't do that because dotsize has not been initialized yet.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        So how do I initialize it?

        (publicint was a typo.)

        Comment


          #5
          You can't. Do it after your dotsize has been initialized in OnBarUpdate() somewhere.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            I'm confused, you say I can't, Then you say I can and to put it after bar update. Still a little puzzled here as to what the code is for initializing dotsize would look like.

            Comment


              #7
              I say you can't meaning not from the Variables section up there.

              Leave your dotsize as is. Move your Font down to OnBarUpdate(). Or just hard set the dotsize in your Font. The point is you can't do it that early. It doesn't know what dotsize is and will only know at runtime. That is why you can't compile.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                ok, I will give it a try. thanks

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ghoul, Today, 06:02 PM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                44 views
                0 likes
                Last Post jeronymite  
                Started by Barry Milan, Yesterday, 10:35 PM
                7 responses
                20 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by AttiM, 02-14-2024, 05:20 PM
                10 responses
                180 views
                0 likes
                Last Post jeronymite  
                Started by DanielSanMartin, Yesterday, 02:37 PM
                2 responses
                13 views
                0 likes
                Last Post DanielSanMartin  
                Working...
                X