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 Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    633 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    364 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    105 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    567 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    568 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X