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

Problems learning to change line plot color & draw arrows once only

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

    #16
    Hint: If you are trying to use a variable over in the Variables part of the code it likely has not been initialized yet.
    Josh P.NinjaTrader Customer Service

    Comment


      #17
      Thanks Josh. Not sure what that means since am still overly 'clueless' about C+ etc. My only previous programming experience was in Tradestation which is a far more non-programmer designed interface so there are many very basic programming things I am unaware of. Mainly I just copy other things and try to make little alterations and am learning by trial and error.

      Ralph:

      I re-ran it this morning and the error msg is:

      From the C+ links:

      The error msg in the Ninja compiler reads:
      A field initializer cannot reference the nonstatic field method or property 'NinjaTrader.Indicator.IchiLines2.opacityValue' CS0236 - click for info


      Visual C# Language Concepts
      Compiler Error CS0236
      A field initializer cannot reference the nonstatic field, method, or property 'field'

      Instance fields cannot be used to initialize other instance fields outside of a method.
      The following sample generates CS0236:
      [IMG]file:///D:/DOCUME%7E1/Ash1/LOCALS%7E1/Temp/msoclip1/01/clip_image002.gif[/IMG]Copy Code
      // CS0236.cspublic class MyClass{public int i = 5;public int j = i; // CS0236public int k; // initialize in constructorMyClass(){k = i;}public static void Main(){}}

      I tried putting the opacityValue int into the Properties and it compiled but I cannot put either opacityValue or colorup into the first field, i.e. where I now have 50 which compiles fine.

      If I input 'colorup' I also get errors CS 1502 and 1503 as well as CS0236.

      Code in Variables section:

      private Color colorup = Color.DarkGoldenrod;
      private Color colordown = Color.SteelBlue;
      private int opacityValue = 25;
      private Color backcolorup = Color.FromArgb(50, Color.LightYellow);
      private Color backcolordown = Color.FromArgb(50, Color.Azure);

      Code in Properties Section:

      [Description("Opacity")]
      [Category("Parameters")]
      public int OpacityValue
      {
      get { return opacityValue; }
      set { opacityValue = value; }
      }

      I tried changing the Category to "Visual" but it makes no difference. Only inputting numbers works and then the same problem in the color menu.

      Of course as Josh pointed out earlier this is not all that important since I could just input normal colors without opacity and choose very light ones from the extensive palette available, but it would be nice to know how to do this as part of the learning process.

      Comment


        #18
        cclsys,

        If you move the definition to OnBarUpdate() it will work.
        Josh P.NinjaTrader Customer Service

        Comment


          #19
          Hi cclsys,

          the error ID is quite clear, you cant initialise a variable with another one. No problem, you have several possibilities:

          - Like Josh proposes, you could initialise in OnBarUpdate() but I think it is not the best choice because this issue is not a runtime problem.
          - You posted the error description together with an example which proposes the initialisation in the constructor.
          - You could initialise your variable in the property definition of the source-variable, assuming you would like to get that update whenever the source-variable is to be changed by the property-grid-menu.


          It's your choice.

          Regards
          Ralph

          Comment


            #20
            Originally posted by Ralph View Post
            Hi cclsys,

            the error ID is quite clear, you cant initialise a variable with another one. No problem, you have several possibilities:

            - Like Josh proposes, you could initialise in OnBarUpdate() but I think it is not the best choice because this issue is not a runtime problem.
            - You posted the error description together with an example which proposes the initialisation in the constructor.
            - You could initialise your variable in the property definition of the source-variable, assuming you would like to get that update whenever the source-variable is to be changed by the property-grid-menu.


            It's your choice.

            Regards
            Ralph
            Josh and Ralph. Thanks. In playing further it appears that for back coloring it really is helpful to have the ability to
            a) adjust opacity and b) be able to choose from all available colors. (in the ideal world of course)

            About suggestions: I am not understanding the vocabulary although I am sure it makes perfect sense to you! For example, I have no idea what it means to "initialise your variable in the property definition of the source-variable" and indeed I am not sure what 'initialise' means in the first place.

            I am assuming that 'constructor' means in the Variables section?
            I am assuming that the property definition is in the Properties section.
            But I do not know how to do anything down there apart from copy and paste the basic lines Description, Category etc with the requisite brackets.

            I am wondering if either of you could please supply some code from what I had earlier and show where it goes so I can understand this since the words alone are too opaque for me and I am looking for more transparency here! [Playful pun intended]

            Comment


              #21
              Originally posted by NinjaTrader_Josh View Post
              cclsys,

              If you move the definition to OnBarUpdate() it will work.
              Josh: which 'definition' do you mean please?

              Comment


                #22
                Right, seems we have a real transparency issue here . Could you describe exactly how you would like to initialise your colors and opacities? What is to be defined/modified by properties, and what is to be initialised by other variables (every time the variables change or only once the class instance is constructed)?

                Regards
                Ralph

                Comment


                  #23
                  Your declaration cclsys. Unfortunately I cannot assist you any further. As stated in the beginning this is beyond the level of what I can offer you support for. Feel free to continue to work with Ralph. Thanks for the insights on this matter Ralph.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #24
                    Originally posted by Ralph View Post
                    Right, seems we have a real transparency issue here . Could you describe exactly how you would like to initialise your colors and opacities? What is to be defined/modified by properties, and what is to be initialised by other variables (every time the variables change or only once the class instance is constructed)?

                    Regards
                    Ralph
                    Thanks Josh, understood.

                    Ralph,

                    appreciate your interest and input.

                    I have another (protected) indicator which has similar BackColor options that color the background depending on up or down trend. Fine. The menu inputs there are simple.

                    BackColor True/False. (whether or not you want to have this feature)
                    UpColor - any color you like from the usual palette.
                    DownColor - "
                    BackColor Opacity (enter number from 1 - 255 to adjust opacity)

                    Now I have no idea how he coded it. But you use normal colors from the palette and then just add in the opacity quotient which only effects the Backcolor colors. I was hoping to be able to do the same thing and now that I/we have tustled with this a little, even though of course what I have already works OK, it would be good to figure out how to do it 'right'. I am sorry my C+ / programming skills are so sub-par, but that's the way it is!

                    Thxs.

                    Comment


                      #25
                      I have another basic question can't find answer for in Help area:

                      Is it possible (like with Tradestation which I know) to say something like:

                      If BackColor is LimeGreen (or whatever I set after certain conditions), then put text "SideTrend" in the Lower Right.

                      I already have Uptrend and Downtrend in the Lower Right working fine. The Side conditions are a little more complex and I can copy and paste them into the text section but I seem to remember seeing an excerpt of Ninja code somewhere that used the color as part of an if... statement.

                      I have written out:

                      if (trendtext)
                      {
                      if (wasshort)
                      {DrawTextFixed("TrendDown", " Ichi Down", tPosition, Color.Black, new Font("Arial Rounded MT Bold", 10), Color.Goldenrod, Color.SteelBlue, 7);}
                      else
                      {RemoveDrawObject("TrendDown");}

                      if (waslong)
                      {DrawTextFixed("TrendUp", " Ichi Up", tPosition, Color.Black, new Font("Arial Rounded MT Bold", 10), Color.SteelBlue, Color.Goldenrod, 7);}
                      else
                      {RemoveDrawObject("TrendUp");}

                      if (BackColor = Color.Honeydew)
                      {DrawTextFixed("Side", " Ichi Side", tPosition, Color.Black, new Font("Arial Rounded MT Bold", 10), Color.Azure, Color.Lime, 7);}
                      else
                      {RemoveDrawObject("Side");}

                      }

                      The basic trend text is fine, but the last one using the BackColor (or BackColorAll word) is rejected. CS0029.

                      Again, none of this is vital rather part of learning process. So any input appreciated.

                      Comment


                        #26
                        I suggest you create yourself a DataSeries that stores the back color with numeric values corresponding to different colors. Then you can just do numeric comparisons to know which color the background is.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #27
                          Originally posted by cclsys View Post
                          BackColor True/False. (whether or not you want to have this feature)
                          UpColor - any color you like from the usual palette.
                          DownColor - "
                          BackColor Opacity (enter number from 1 - 255 to adjust opacity)
                          Sounds simple. Could you provide me with the related sections of your code, which describes usage and declaration of colors and opacities? This way it should be even simpler to make a proposal.
                          ( I mean your trial code with the compilation error).

                          Regards
                          Ralph

                          Comment


                            #28
                            Originally posted by Ralph View Post
                            Sounds simple. Could you provide me with the related sections of your code, which describes usage and declaration of colors and opacities? This way it should be even simpler to make a proposal.
                            ( I mean your trial code with the compilation error).

                            Regards
                            Ralph
                            OK, what I'll do is send the file compiled and the 'bad' inputs //'d out so you can see what I mean. The only cs's in the export are Max and Min so I believe it is 'safe'. But what do I know?

                            If this is the wrong protocol or something let me know and I'll send pasted-in snippets directly. But this way you have it all and I might not send everything you need properly otherwise.
                            Attached Files
                            Last edited by cclsys; 03-20-2009, 02:07 PM.

                            Comment


                              #29
                              Originally posted by Ralph View Post
                              Sounds simple. Could you provide me with the related sections of your code, which describes usage and declaration of colors and opacities? This way it should be even simpler to make a proposal.
                              ( I mean your trial code with the compilation error).

                              Regards
                              Ralph
                              Ralph,

                              I apologise. On reading your message and going into the code, I put in the dysfunctional parts only where the opacity issue was involved in the Variables menu.

                              I did not do anything about the BackColor condition for determing the text message (about trend direction in this case sideways) business having solved the problem with a variable which you can see lower down in the code.

                              (Variable "side' boolean). It works fine, but then I was curious if it was possible to use the backcolor value in the coding somehow since I believe I saw another snippet of code somewhere that did that.

                              (Looks like Josh has a good idea how to do it, although as usual I have no idea how to implement it!)
                              Last edited by cclsys; 03-20-2009, 06:18 PM.

                              Comment


                                #30
                                Please see this article: http://www.ninjatrader-support.com/H...taSeriesObject

                                Store in 1 or 2 or 3 whenever you change the background color. Then check the DataSeries for whichever value you want.
                                Josh P.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by ZenCortexCLICK, Today, 04:58 AM
                                0 responses
                                2 views
                                0 likes
                                Last Post ZenCortexCLICK  
                                Started by sidlercom80, 10-28-2023, 08:49 AM
                                172 responses
                                2,280 views
                                0 likes
                                Last Post sidlercom80  
                                Started by Irukandji, Yesterday, 02:53 AM
                                2 responses
                                17 views
                                0 likes
                                Last Post Irukandji  
                                Started by adeelshahzad, Today, 03:54 AM
                                0 responses
                                5 views
                                0 likes
                                Last Post adeelshahzad  
                                Started by Barry Milan, Yesterday, 10:35 PM
                                3 responses
                                13 views
                                0 likes
                                Last Post NinjaTrader_Manfred  
                                Working...
                                X