Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Methods within a strategy

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

    Methods within a strategy

    I have created methods within a strategy that are working just fine. They have been created to simplify the code where the method contains 3 conditions and one action.

    I would like to create other methods that contain only 3 conditions as a set and no actions. Set1() Then I want to use the sets in a combined condition like:
    If (Set1() || Set2() && Set3())
    //then do something

    What is the best way to ackomplish this task? Bottom line, how do I condense 3 conditions into OneWord?

    thanks
    Last edited by kenb2004; 12-30-2010, 11:47 AM.

    #2
    Hello kenb2004,

    It sounds like you're interested in creating a method that returns a bool value.

    Here is an example of this:

    private bool set1()
    {
    if (Close[0] > Close[1])
    return true;

    else
    return false;
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      So...in my example how would you combine the sets?
      If (Set1() == true || Set2() == true && Set3() == true)
      //do something

      Comment


        #4
        Right - that works. The return type of the method is implied as bool so you can also write:

        if (Set1() || Set2() && Set3())

        or for false conditions.

        if (!Set1() || !Set2() && !Set3())
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Super...I give that a try..thanks

          Comment


            #6
            If I declare these bool Sets() in UserDefinedMethods will
            if (Set1() || Set2() && Set3())
            //do something
            work in another strategy without declaring them in that strategy?
            I'm not sure if "declaring" is the right terminology.
            Last edited by kenb2004; 12-30-2010, 12:54 PM.

            Comment


              #7
              Yes, they'll work in another strategy if placed in UserDefinedMethods but must be declared public. See here for an example of this.

              Alternatively you can call from another strategy if declared within the scope of an individual strategy.

              myStrateyName().Set1()
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                In the example you sent me to ....
                If (IsMoringSession(Time[0]) == true)
                this could also be written as
                If (IsMoringSession(Time[0]) because the "bool return is implied "true""?
                Is that right?

                Comment


                  #9
                  Yes, that format works here as well. As long as the method return type is bool you can use the abbreviated format.
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks a lot

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by SalmaTrader, 07-07-2026, 10:26 PM
                    0 responses
                    47 views
                    0 likes
                    Last Post SalmaTrader  
                    Started by CarlTrading, 07-05-2026, 01:16 PM
                    0 responses
                    22 views
                    0 likes
                    Last Post CarlTrading  
                    Started by CaptainJack, 06-17-2026, 10:32 AM
                    0 responses
                    15 views
                    0 likes
                    Last Post CaptainJack  
                    Started by kinfxhk, 06-17-2026, 04:15 AM
                    0 responses
                    21 views
                    0 likes
                    Last Post kinfxhk
                    by kinfxhk
                     
                    Started by kinfxhk, 06-17-2026, 04:06 AM
                    0 responses
                    23 views
                    0 likes
                    Last Post kinfxhk
                    by kinfxhk
                     
                    Working...
                    X