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

C# question

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

    C# question

    New to indicator development and C#. Can someone please explain this to me:

    In looking at an indicator someone else wrote, there's this code:

    In region variables: private bool showArrows;

    In the logic to show arrows on the chart: if(ShowArrows) ...

    In the area where the user can set the variable:

    public bool ShowArrows
    {
    get { return showArrows; }
    set { showArrows = value; }
    }

    I don't understand this: if the user is inputting to showArrows, how does ShowArrows ever get set? The input is to the lower case "showArrows", yet the logic uses the upper case "ShowArrows". Nowhere in the code is ShowArrows set to showArrows.

    I see this sort of thing all the time and find it extremely puzzling. Why are there, nearly always, 2 variables used when all you want is one variable to use within the program?

    #2
    You do have two variables one private bool showArrows;
    and one public bool ShowArrows. Thats how C# works!
    The public is set by
    set { showArrows = value; }
    What not to understand?

    Comment


      #3
      Originally posted by Baruch View Post
      You do have two variables one private bool showArrows;
      and one public bool ShowArrows. Thats how C# works!
      The public is set by
      set { showArrows = value; }
      What not to understand?
      What I don't understand is just what I posted originally: one first defines "showArrows"; the user is allowed to set "showArrows". The variable used within the logic is not "showArrows" ... what is used is "ShowArrows". One starts with a lower-case "s", the other starts with an upper-case "S". This language is, unlike some other languages, case-sensitive. Since "ShowArrows" is never assigned a value, either in the definition area or by the user ("showArrows" is the variable referenced in those two sections), how can "ShowArrows" ever be used in the code?

      Comment


        #4
        ShowArrows can be used in the code instead of showArrows. They work the same.
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment


          #5
          The set line is what set the capital S's value.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Josh View Post
            The set line is what set the capital S's value.
            So, let me get this straight: even though the set line references "showArrows" - with a lower-case "s", it is ACTUALLY setting "ShowArrows" - with an upper-case "S"?

            Comment


              #7
              Originally posted by eDanny View Post
              ShowArrows can be used in the code instead of showArrows. They work the same.
              i see this mistake being made a lot

              to clarify: these are two independent variables, one contains the default, the other one contains the users selection from the parameters dialog

              so showArrows is the default and will always be the same
              and ShowArrows is the value which is being passed back from the indicators parameters dialog and only defaults to the value from showArrows

              correctly you should evaluate ShowArrows in your code

              hope that helps

              Comment


                #8
                Originally posted by toulouse-lautrec View Post
                i see this mistake being made a lot

                to clarify: these are two independent variables, one contains the default, the other one contains the users selection from the parameters dialog

                so showArrows is the default and will always be the same
                and ShowArrows is the value which is being passed back from the indicators parameters dialog and only defaults to the value from showArrows

                correctly you should evaluate ShowArrows in your code

                hope that helps
                Thank you for the response.

                What is it that assigns the user-specified value - the value that, to me, looks like it's being place into "showArrows" - into "ShowArrows"? Is it simply the fact that the input is in the "#region Properties" portion of the indicator and the "get" and "set" are part of the definition of "public bool ShowArrows"? I assume the variable referenced in "get" and "set" could be named "fred", as long as "fred" was defined in the variable section.

                Comment


                  #9
                  Weston,

                  Correct. It could be named fred if you desired.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Josh View Post
                    Weston,

                    Correct. It could be named fred if you desired.
                    Thanks. For someone coming from a background of - I'm dating myself here - fortran, basic, PL/1, snobol - this object-oriented stuff is just a bit different. The light bulb is starting to come on ... uh, I think.

                    Comment


                      #11
                      Another question:

                      How in the world do I use Print()?

                      I have a strategy that, when certain conditions are met, displays things on the chart using DrawText and DrawTextFixed. I just put, right below the "DrawText" line, a line that simply reads 'Print("stuff");'. When I apply the strategy to a chart, the text in "DrawText" shows up just fine. The word "stuff" does not. Why not? It's in the same "then" clause, before the closing brace ("}"). The documentation says Print() sends output to the "output window". Where's that? Is it the chart? Is "stuff" being output somewhere besides the chart?

                      Comment


                        #12
                        The output for Print() is in the Output Window accessible from Control Center>Tools>Output Window.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Josh View Post
                          The output for Print() is in the Output Window accessible from Control Center>Tools>Output Window.
                          Opened the Output Window as you described above. It's empty. That's not really what I want, anyhow.

                          How do I just "print" something to the screen, the current chart? Are DrawText and DrawTextFixed the only ways to do that?

                          Very specifically, I am trying to see what's in "BarsSinceExit()". When I add, to my entry logic: if BarsSinceExit() = -1 || BarsSinceExit() > BarsAfterExit, I get no entries at all (BarsAfterExit is the user-defined var).

                          I stripped it totally down and said "if BarsSinceExit() = -1" then enter the trade. I got no entries.

                          I changed it to "if BarsSinceExit() != -1" then enter the trade. I got no entries.

                          How can it be equal to -1 and not equal to -1 at the same time?

                          Anyhow: I just want to see what's in BarsSinceExit(). When I use DrawText to attempt to see it, doing so blows away all the other output to the chart that's been generated by the strategy. AND it doesn't show me the contents of BarsSinceExit().

                          Comment


                            #14
                            Output Window only outputs things as you run the script. You need to have it open before you run the script to see outputs.

                            To draw on the chart you need to use DrawText/Fixed.

                            = is not a comparison. = is an assignment. If you want to check comparisons you need to use ==.

                            You likely ran into errors with your DrawText line. Please see Control Center logs for runtime errors.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by Weston View Post
                              Thanks. For someone coming from a background of - I'm dating myself here - fortran, basic, PL/1, snobol - this object-oriented stuff is just a bit different. The light bulb is starting to come on ... uh, I think.
                              i know how this feels... learned programming 20 years ago myself and now i find myself in this beatiful world of objects ....

                              often wondering if all these techniques are really making things so much more efficient or are we only kidding ourselves... never mind, i´m digressing

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by SantoshXX, Today, 03:09 AM
                              0 responses
                              12 views
                              0 likes
                              Last Post SantoshXX  
                              Started by DanielTynera, Today, 01:14 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post DanielTynera  
                              Started by yertle, 04-18-2024, 08:38 AM
                              9 responses
                              42 views
                              0 likes
                              Last Post yertle
                              by yertle
                               
                              Started by techgetgame, Yesterday, 11:42 PM
                              0 responses
                              14 views
                              0 likes
                              Last Post techgetgame  
                              Started by sephichapdson, Yesterday, 11:36 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post sephichapdson  
                              Working...
                              X