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

#define

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

    #define

    Hello!
    I am wondering if there is a way in C#/Ninjatrader to have predefine values.

    In my case, I want to fix predefine values corresponding to the strength of my conditions. For example:
    #define weak 1
    #define strong 3
    The idea here is that if the price touch the EMA once, I would have
    HTML Code:
    Close[i] = weak;
    , and if prices touch the EMA three times, I would have
    HTML Code:
    Close[i] = strong;
    Is there a way in Ninjatrader to predefine such values?

    Thanks


    #2
    Hello Stanfillirenfro,

    That would just be a private variable:

    Code:
    private double weak = 1; 
    
    protected override void OnBarUpdate()
    {
    if(Close[0] >= weak)
    Checking exact equality on a double number generally wont work so using an == condition may not become true when the values are the same. You can see some examples of comparing equality on double numbers here: https://ninjatrader.com/support/help...htsub=floating


    JesseNinjaTrader Customer Service

    Comment


      #3
      Many thanks Jesse for your reply.

      It is not exactly what I want.
      I think I will use Class as container.
      I have the following:
      HTML Code:
      static class Constants
      {
        public const int weak = 1;
        public const int strong = 3;
      }
      I would be gretaful to you if you could advise me where to place this code:
      1) Outside of
      HTML Code:
      public class myIndicator : Indicator {}
      or
      2) inside?

      Thanks!

      Comment


        #4
        Hello Stanfillirenfro,

        You can use any C# structure that you like as long as its C# code. That is essentially the same as using private variables but with more code and more to debug depending on how you plan to use that.

        You would need to place a class outside your indicators class. If you plan to export the file that can cause issues depending on how its used so we generally suggest to avoid making complex structures unless you are able to debug that use case when exporting/importing the script.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks Jesse for your reply.
          It is a bit tricky to use it outside of my indicator class, but I need the values of this class inside of my indicator class. Hummmmm!!!
          Could you please advise how?

          Thanks!

          Comment


            #6
            Hello Stanfillirenfro,

            You used a static class so you would have to use that in the static way by calling the type then the property name. if you are unsure how to use static classes you can research that in external C# guides, we generally suggest avoiding static all together because that is a more complex topic with a lot of specifics on how you would need to use it in NinjaScript. If you know that is what you need for your use case you could use that, I would otherwise suggest sticking the properties inside the indicators class and to avoid using extra classes.

            JesseNinjaTrader Customer Service

            Comment


              #7
              Many thanks Jesse for your help.

              If using eunumeration, would that yield the same result as private variables?
              When we plot an indicator containing an enumeration on the chart, there are possibilities to choose the variables of the enumeration.
              Is there a way to use enumeration without having to select the variables on the variable panel of the indicator while ploting on the chart?

              Thanks

              Comment


                #8
                Hello Stanfillirenfro,

                You can make a private variable for an enum if that is just used in your code, only public properties show up as user inputs. An enum makes a dropdown list of selectable items in the UI.
                You can also hide public properties using the browsable attribute: https://ninjatrader.com/support/help...tsub=browsable

                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Many thanks Jesse.
                  I will now explore all these ways you have suggested me.

                  I will revert to you again if I face other problems.

                  Many thanks again.

                  Comment


                    #10
                    Another question Jesse.

                    Please could you advise if two different variables of an enum CAN have the same value?
                    For example
                    HTML Code:
                    enum myValues
                    {
                      value1 = 3,
                      value2 = 1,
                      value3 = 3
                    }
                    Many thanks
                    Last edited by Stanfillirenfro; 07-26-2022, 02:39 PM.

                    Comment


                      #11
                      Hello Stanfillirenfro,

                      An enum can be assigned a value like that however if you miss any assignments in the list of items that can result in unexpected incrementing of values for later enums. You can see an example of how enums operate with assigning some values in the following link:
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Many thanks Jesse!
                        It is becoming clearer.

                        Many thanks again.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by rdtdale, Today, 01:02 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post rdtdale
                        by rdtdale
                         
                        Started by alifarahani, Today, 09:40 AM
                        3 responses
                        15 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by RookieTrader, Today, 09:37 AM
                        4 responses
                        18 views
                        0 likes
                        Last Post RookieTrader  
                        Started by PaulMohn, Today, 12:36 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post PaulMohn  
                        Started by love2code2trade, 04-17-2024, 01:45 PM
                        4 responses
                        41 views
                        0 likes
                        Last Post love2code2trade  
                        Working...
                        X